Entry type: FAQ, Entry ID: 18516182, Entry date: 04/18/2012
(0)
Rate

How do you program communication blocks FB12 "BSEND" and FB13 "BRCV" for data exchange in the S7 program of an S7-300 CPU?

  • Entry
  • Associated product(s)

Instructions
Communication blocks FB12 "BSEND" and FB13 "BRCV" have to be called in the program in order to transfer data between two S7-300 stations by way of an S7 connection configured in NetPro. The S7 connection has to be configured on both sides, because the S7 communication by way of FB12 "USEND" and FB13 "URCV" is based on the client-client principle.

Features of the communication blocks FB12 "BSEND" and FB13 "BRCV"

  • The FB12 and FB13 function blocks are asynchronous communication functions.
  • In this example, the blocks are called in the OB1 cycle (see also Entry ID: 2795485).
  • The FB12 and FB13 function blocks run for several OB1 cycles.
  • The FB12 function block is activated by the "REQ" input parameter.
  • The FB13 function block is activated by the "EN_R" input parameter.
  • The end of the job is indicated by "DONE", "NDR" or "ERROR".
  • BSEND and BRCV can communicate simultaneously through one connection.
  • The latest version of the FB12 "BSEND" and FB13 "BRCV" communication blocks for data exchange by way of a CP343-1 or CP342-5 is available in the SIMATIC_NET_CP library under "CP 300 > Blocks".
  • The latest version of the FB12 "BSEND" and FB13 "BRCV" communication blocks with the "CPU_300" family for data exchange by way of the integrated PROFINET interface of a S7-300 CPU, IM151-8 PN/DP CPU or IM154-8 CPU is available in the Standard Library under "Communication Blocks > Blocks".

Description of the sample program
The S7 program contains the call of the communication blocks FB12 "BSEND" and FB13 "BRCV" from the Standard Library. The FB12 "BSEND" function block is for sending data and the FB13 "BRCV" function block is for receiving data.
The sample program shows the functions of the FB12 "BSEND" and FB15 "BRCV" communication blocks using an S7 connection.

First create the hardware configuration for your S7-300 station.

Note
Configure the Marker byte 10 as clock marker. The send request is triggered by this clock marker. Save and compile the hardware configuration of your S7-300 station and load it into the CPU.
The timer resource T10 is used in this sample program.

Configure an S7 connection for the CPU in NetPro. You can configure a specified S7 connection if the communication partners are configured together in a STEP 7 project. If the communication partner is not configured in the same STEP 7 project as the S7-300 station, then an unspecified S7 connection is configured. Make sure you assign the IP address or PROFIBUS address correctly when you configure the S7 connection. You also need to make sure you assign the rack/slot and connection resource correctly. These are for clearly identifying the S7 connection between the communication partners.

You find the value that must be specified for the "ID" input parameter of communication blocks FB12 "BSEND" and FB13 "BRCV" in the Properties dialog of the S7 connection -> tab "General".

 
Fig. 01

The STEP 7 program consists of blocks OB100, OB1, FB105, DB105, DB200, DB201, FB12 and FB13.

OB100
The OB100 is a restart OB and is run when the CPU is restarted (warm start). In this OB, the first communication trigger is enabled with marker 0.3 "START-UP".

OB1
OB1 is called cyclically. FB105 is called in this OB (instance data block: DB105) with M0.3 "START-UP" as parameter (INIT_COM). After FB105 has been run the M0.3 "START-UP" is reset.


Fig. 02

FB105
FB105 is called in the OB1 cycle. The FB12 "BSEND" and FB13 "BRCV" communication block calls are in FB105.

At the "ID" input parameter of the communication blocks you must specify the connection number of the S7 connection configured in NetPro. The value for the "ID" input parameter must be taken from the Properties dialog of the S7 connection configured in NetPro (see Fig. 01).
You can change the connection number separately in FB105. Change the connection number in network 2 of FB105 in accordance with your configuration. The connection number is stored in a static tag and so in the instance data block DB105.
The connection number "1" is defined in this example.


Fig. 03

FB12 is activated by the input parameter "REQ" when the M10.6 clock marker has a positive edge and no job is running. The "REQ" input parameter is reset only when the send job is completed either successfully or with an error.
This locking of the function call is important, because the function is asynchronous and can last several cycles. Continual activation of the function block without waiting for the end of the active job can cause a communication overload.

With the "R_ID" input parameter you define the coherence of a send job and a receive job. The "R_ID" on the FB12 "BSEND" of the sender must match that on the FB13 "BRCV" of the recipient.

At the "SD_1" input parameter of FB12 you specify the address and length of the data area that contains the data to be sent (send buffer), for instance: P#DB201.DBX0.0 BYTE 8000.
You enter the length of the data to be sent in bytes at the "LEN" input parameter. You define the length of the data to be sent in Network 1 of FB105. This is stored in a static tag and so in the instance data block DB105.
In this example the length of the data to be sent is 8000 bytes.

The output parameters "DONE", "ERROR" and "STATUS" are required for the job evaluation and are only valid in the same cycle.


Fig. 04

If the send job is completed with an error, then the value of the output parameter "STATUS" of FB12 is saved for error analysis.


Fig. 05

FB13 is activated by the "EN_R" input parameter. The value of the "EN_R" input parameter is always "1" because the marker M0.1 is set to the value "1" in the startup OB100. In this way the S7-300 station is always ready to receive.

With the "R_ID" input parameter you define the coherence of a send job and a receive job. The "R_ID" for FB12 on the Send side and FB13 on the Receive side must match.

At the "RD_1" input parameter you specify the address and length of the data area where the received data is stored (receive buffer), for instance P#DB200.DBX0.0 BYTE 8000.

The "LEN" output parameter indicates the length of the data received in bytes. The output parameters "NDR", "ERROR" and "STATUS" are required for the job evaluation and are only valid in the same cycle.


Fig. 06

If the receive job is completed with an error, then the value of the "STATUS" output parameter of FB13 is saved for error analysis.


Fig. 07

Additional information

  • The manual "System and Standard Functions for S7-300/400 Volume 1/2", Chapter 22 "S7 Communication" provides information, for example, about the volume of data you can transfer using the FB12 "BSEND" and FB13 "BRCV" communication blocks. This manual is available for downloading in Entry ID 44240604.
  • How to configure a specified and an unspecified S7 connection is described in Entry ID: 17628518.

The STEP 7 project as download
The STEP 7 project contains a sample program for calling the FB12 and the FB13 communication blocks. It was created with STEP 7 V5.5.

Sample_S7-300_BSEND_BRCV.zip ( 47 KB )

Note
Copy the latest version of the communication blocks FB12 and FB13 from the SIMATIC_NET_CP library or from the Standard Library into your user program and then call it in your user program.

Error details
Detailed error description
Help us to improve Online Support.
The page requested cannot be displayed. Please contact the webmaster.
Contact to webmaster