Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This document provides you with information on the samples of Profibus communication between a SIMATIC S7 station and a SIMATIC S5 station using the FDL service (Fieldbus Data Link) with free layer 2 access. For a brief overview of this sample, refer to Chapter 2. For detailed information, refer to Chapter 3 and the chapters following. The document covers the following topics:
System structure Introduction to the required blocks and their communication structure Program structures and extracts of code Operator control and monitoring Troubleshooting
MPI interface
as
Function Diagram
The following diagram illustrates how the sample works:
SIMATIC S5 Station
Run startup Prepare data for sending Send data (2 bytes of user data) Receive data and copy it to the send buffer
Data Exchange
6 bytes of data are exchanged cyclically by the stations involved in communication. These consist of 4 bytes of header to specify the partner station and 2 bytes of user data.
S7/S5 Partner
The S7 partner initiates connection establishment and the sending of new data. The S5 partner returns the received data to the S7 end. Return means that received data is sent back to the S7 end after it has been completely received.
Program
S7 End
S5 End
STARTUP
FB125 FB111
OB1
MY_SEND_CALL
FC AG_SEND
RECEIVE REC<-SDA
FC6 FC41
FB120 FB40
An "AG_SEND" FC is called every cycle to send 2 bytes of user data. Parallel to the send job an "AG_RECV" FC is called to fetch received data from the CP. The data is saved once it has been completely received. Once the RECEIVE job has been processed without error, the data to send is incremented by 1 and the send/receive cycle begins again.
A "RECEIVE" FB is triggered in every cycle. When the "RECEIVE" FB signals newly received data, the "SEND" FB is triggered with the newly received data to send the received data back.
There must be an online connection to the CPU. "Monitor variables" must be activated. The values to be modified must be marked as valid.
If the conditions listed above are met, you can determine whether the sample is functioning correctly by observing that the data sent and received from the active (S7) station is changing continuously.
System Structure
This chapter lists the hardware and software required to run the sample.
Note Scope of Application of this Document The content of this document assumes a specific configuration. This documentation can, however, be used for all FDL samples of communication between a SIMATIC S7 PLC and SIMATIC S5 stations.
General Structure
Bus system Communications protocol Active end Passive end Communications processors Services PROFIBUS SDA (Send Data with Acknowledge) SIMATIC S7 SIMATIC S5 CP 342-5,CP 5431 FDL (free layer 2 access)
The sample uses the FDL protocol. Using this protocol and the SDA services, there is a data exchange between a SIMATIC S7 station and a a SIMATIC S5 station. As communications processors, a CP 342-5 is used at the active SIMATIC S7-300 end and a CP 5431 at the passive SIMATIC S5 end.
location 1 2 4
Slot 1 2
Caution The samples relate to specific hardware configurations. These must exist to ensure problem-free operation. If you want to use a different configuration, adaptations will be necessary.
Note Using a different CPU If you want to use a different CPU for the sample, please read the document "Change_CPU".
Note Using a different CP If you want to use a different CP for the sample, please read the document "Change_CP".
Required Software
You require the following software to run the sample:
Microsoft Windows 95, Windows 98 or Windows NT 4.0 as the operating system STEP 7 V5.03 NCM S7 Profibus V5.03 STEP 5 V6.65 COM 5431 V
How the sample works Blocks required for communication and their communication structure
10
Step-by-Step Execution of the User Program at the Active End (SIMATIC S7)
Specify the DESTINATION: The destination of the data to be sent is specified for every send job in the user program with a 4 byte long job header, since the FDL service is used with free layer 2 access. SEND: A data block of 2 bytes is sent to the passive partner in every cycle. RECEIVE: A receive job is triggered in every cycle and, depending on the return value, the received data is written to the receive buffer. The received data contain a 4 byte long job header to specify the sender. Increment data: The value of the data to be sent is incremented by 1 and the send/receive cycle starts again.
Step-by-Step Execution of the User Program at the Passive End (SIMATIC S5)
SEND: A receive job is triggered at the passive end every cycle. When new data are received, these are entered in the common receive/send buffer and the SEND is triggered. RECEIVE: A send job is triggered when new data is received.
11
12
13
14
This chapter introduces you to the structure of the program for both the active and passive ends and important sections of code are shown and explained.
15
Call AG_SEND
Yes
No
Call AG_RECV
Yes
Yes
16
17
Purpose
OB1 is responsible for cyclic execution of the user program. In this sample program, the blocks that implement the send / receive functionality (AG_SEND and AG_RECV) are called.
Call
OB1 is called in every CPU cycle.
Name
OB1
Code
// // example for send/receive with 2 bytes of data // CALL MY_SEND_CALL" // CALL MY_RECEIVE_CALL" //
Description
OB1 calls the blocks named "MY_SEND_CALL" (call AG_SEND) and "MY_RECEIVE_CALL" (call FC AG_RECV) in every cycle.
18
Purpose
Two bytes of data are sent to the configured partner using the Send / Receive service AG_SEND.
Call
Called within OB1.
Name
MY_SEND_CALL (FC40)
Code
// L 4 // job header: PB address of destination station T DB40.DBB 2 L 3 // job header: LSAP of destination station T DB40.DBB 3 L B#16#0 //job header: Service (SDA = 00h) T DB40.DBB4 // CALL "AG_SEND" ACT := TRUE ID := 1 LADDR := W#16#100 SEND := P#DB40.DBX2.0 BYTE 6 LEN := 6 DONE := SEND_DONE" ERROR := SEND_ERROR" STATUS := SEND_STATUS" // AN "SEND_ERROR" BEC // L "SEND_STATUS" T "PARAMETER_ERROR_DB".send_error_status
19
ACT: Edge signal for executing the block. ID: This identifier identifies the S/R connection (obtained with "CPU -> Connections"). LADDR: This parameter provides the address of the local CP (assigned in "HW Config" and can also be read out using "Netpro") SEND: Address of a local data area from which values are sent (send area). LEN: Length of the data area to be sent. DONE: Indicates error-free execution of the job. ERROR: Indicates whether or not an error has occurred. STATUS: Provides detailed information about states or errors during execution of the job.
Description
CALL "AG_SEND": The "Send data" FC is called. Depending on the "SEND_ERROR" bit, the status word is saved or the function is exited using a conditional block end (BEC).
Summary
The job header of the send job is filled to specify the destination station for the data to be sent. The actual user data transferred start in byte 4 of the send area. The send block is triggered in every cycle to send data from the send buffer (DB40). When an error occurs during sending, the returned status value is saved in a data block (DB43).
20
Purpose
Using FC AG_RECV, 2 bytes of data received from the partner are entered in the specified receive area.
Call
Called within OB1.
Name
MY_RECEIVE_CALL (FC41)
Code
// CALL "AG_RECV" ID := 1 // connection ID LADDR := W#16#100 // logic module address SEND := P#DB41.DBX2.0 BYTE 6 // ANY pointer to receive buffer NDR := RECV_NDR" DONE := RECV_DONE" ERROR := RECV_ERROR" STATUS := RECV_STATUS" // current function status LEN := RECV_BUFFERLENGTH" // A "RECV_ERROR" // if function error, jump JC err // L "RECV_BUFFERLENGTH" // save length of receive data T "RECV_DB".receive_bufferlength // A RECV_NDR" // receive new data? FP EDGE_MEMORY" JCN m001 // L DB41.DBB2 // if partner address = 4, go on L 4 ==I JCN m001 // L SEND_DB".send_data[0] // increment send data + 1 T SEND_DB".send_data[0] M001: BE // err: L RECV_STATUS" // save current (error) T PARAMETER_ERROR_DB".receive_error_status
21
ID: This identifier identifies the S/R connection (obtained with "CPU -> Connections"). LADDR: This parameter provides the address of the local CP (assigned in "HW Config" and can also be read out using "Netpro") RECV: Address of a local data area from which the values are transferred. NDR: Indicates error-free execution of the job. ERROR: Indicates whether or not an error has occurred. STATUS: Provides detailed information about states or errors during execution of the job. LEN: Length of the data area to be sent.
Description
CALL "AG_RECV": The FC for data reception is called. The status value is saved depending on the "RECV_ERROR" bit. Otherwise, the received data length is accepted and the data word incremented if the data was received correctly (new send data prepared).
Summary
The receive block is triggered in every cycle to receive data and write it to the receive buffer (DB41). When an error occurs during sending, the returned status value is saved in a data block (DB43). If data is received correctly from the defined partner station (PB addr = 4), the data is incremented.
22
Program/cycle start
Call RECEIVE
Yes
Yes
Copy I/O data
Call SEND
Yes
23
Purpose
OB1 is responsible for cyclic execution of the user program. The following sample program calls the blocks for executing the functions SEND and RECEIVE.
Call
OB1 is called in every CPU cycle.
Name
OB1
Code
:JU FB 41 Name :REC<-SDA : :JU FB 40 Name :SEND>SDA : :BE call receive-function call send function
Description
OB1 calls the block with the name REC<-SDA and SEND>SDA in each CPU cycle.
24
Purpose
OB20-OB22 are intended for programming with the various possible PLC startup types.
Call
The blocks OB20 to OB22 are called depending on the type of startup, for example, warm or cold restart. The calls in the example are identical for all three types of startup.
Name
OB20 / OB21 / OB22
Code
OB 20 :JU FB 111 Name :STARTUP ERR : F 200.0 : :BE synchron for CP 5431 synchron error for CP 5431
Description
OB20 calls the "STARTUP" FB during startup to initialize communication.
25
Purpose
FB111 initializes the communications processor.
Call
FB111 is called during startup by one of the OBs OB20 to OB22.
Name
FB111
Code
: :JU FB 125 Name :SYNCHRON SSNR : BLGR : PAFE : : :A := : :BE F 255.0 PAFE error ? KY 0,0 KY 0,6 FY 255 SSNR - CP5431
=ERR
Description
In "STARTUP" FB 111, the function block FB125 is called to initialize the communications processor.
26
Purpose
Using FB SEND, 2 bytes of data are sent to the configured partner.
Call
Called within OB1.
Name
FB40
Code
Name :SEND>SDA :A F 45.7 :JU FB 120 Name : SEND SSNR : KY A-NR : KY ANZW : FW QTYP : KS DBNR : KY QANF : KF QLAE : KF PAFE : FY 0,0 0,134 56 DB 0,40 +1 +5 54 : :A F :AN F := F : :A F := F : :A F : :AN F :R F : :BE send to remote-station 2 bytes "call-send-bit"
job number (ncm5431) send send send send 57.2 55.0 55.1 57.2 55.0 55.1 54.0 45.7 edge flag "data transfer completed" no pafe by send reset "call-send-bit" buffer buffer buffer length type is db is db40 offset is dw1 (5 words/10 bytes)
anzw "job complete without err" edge flag "data transfer completed"
27
SSNR: Interface number of CP. A-NR: The job number identifies the S/R connection of the CP. ANZW: Display word QTYP: Type of buffer area. DBNR: The DB number for data blocks. QANF: Offset within the buffer area. QLAE: Length of the area to send in WORD. PAFE: Error byte of the block.
Description
FB "SEND" is called. Depending on the "Data_transfer" and "PAFE" bytes, the send bit is reset and the block is closed.
Summary
The send block is triggered in every cycle to transfer data.
28
Purpose
Using FB RECEIVE, 2 bytes of data received from the partner are accepted.
Call
Called within OB1.
Name
FB41
Code
FB41 Name :REC<-SDA :O F 0.0 :ON F 0.0 :JU FB 121 :RECEIVE : KY 0,0 : KY 0,134 : FW 46 : KS DB : KY 0,41 : KF +1 : KF -1 : FY 44 : :A F 47.2 :AN F 45.0 := F 45.1 :A F 47.2 := F 45.0 : :A F 45.1 :AN F 44.0 :S F 45.7 : :C DB 41 :L DW 5 :C DB 40 :T DW 5 : :BE receive data from remote-station call receive data job number (ncm5431) receive buffer type is db dB number is 41 receive buffer offset is dw1 receivel ength is joker anzw "job complete without err" edge flag "data acceptance complete"
edge flag "data acceptance complete" no pafe error set "call send bit" data transfer receive to send
29
SSNR: Interface number of CP. A-NR: This parameter shows the job number for the connection of the local communication CP. ANZW: Display word ZTYP: ID for type of receive buffer. DBNR: Number of the data block. ZANF: Offset of the receive buffer. ZLAE: Length of the data area to send. If "1" is set, the length of the data is obtained when the data is received. PAFE: Process image error in executing the receive block.
Description
FB "RECEIVE" is called. When the "receive end" bit "PAFE" bits have been successfully passed the block is closed and the send job bit is set.
Summary
The receive block is triggered in every cycle to receive data and, after successful reception, to trigger the send job.
30
31
Note If problems occur during operator control and monitoring, please read Chapter 7, Troubleshooting.
Monitoring
You can monitor the functions using the variable table provided with the sample. The following table explains how to use the variable table.
Step 1 2 3 4 5
Description Insert this end of the MPI cable in the MPI port of the S7 CPU in the active station Select "Blocks" in the project window of the SIMATIC Manager under the active station. Double-click "VAT1". In the "Monitoring and Modifying Variables" program, select "PLC" >"Connect to " -> "Configured CPU" To monitor the specified variables, select "Variable" -> "Monitor"
Note The monitor function is active when "Online" is displayed in the status bar in the "Monitoring and Modifying Variables" program and you can see a continuously changing progress bar.
32
33
Note The sample is functioning correctly when the value of the data read and written changes continuously. Don't forget! The variable table must be online and monitoring must be active for the values to be updated.
Operator Control
You can call the functions using the variable table provided with the sample. How to start and activate it was described above.
Note To call up the functions, the variable table must be "Online" and "Monitor" must be active so that the values can be updated (see above).
The following table shows you how to change the value of the data sent to (and then read by) the passive end.
Step 1 2
Description Enter a value between 0 and 32767 in the last column ("Modify Value") of the line "MW 52" "SEND_DATA" in the variable table. Select "Variable" -> "Activate Modify Value"
Correct function: If the value has been successfully modified, the value read should also return a new value.
34
35
Troubleshooting
This chapter is intended to help you if you encounter problems installing and starting up the sample.
36
Step 1 2
Description Is the MPI cable connected to both the PG/PC and the S7 CPU? In the "Set PG/PC Interface" program is the correct interface parameter set assigned to the "Access point of application" "S7ONLINE (STEP 7)"? For example,"MPI-ISA on board (MPI)" if you are using the PG-MPI port. Is the hardware configuration in the project (offline configuration) identical in every way with the actual configuration (online configuration)? Has the CPU been reset?
3 4
Remedies
Correct the problem by working through the steps below if your answer was no to one of the questions above.
Answer to Step 1 was "NO" No connection can be established to the S7 CPU, it is not possible to download to the CPU.
Step 1 2
Description Insert one end of the MPI cable in the MPI port on your PG or PC. Insert the other end of the MPI cable in the MPI port of your S7 CPU.
37
Answer to Step 2 was "NO" No connection can be established to the S7 CPU, it is not possible to download to the CPU.
Step 1 2
Description Start the "Set PG/PC Interface" program: "Start" -> "Simatic" -> "SIMATIC NET" -> "Set PG/PC Interface". Set the module you want to use as the MPI port in "Interface parameter set used". For example, "MPI-ISA on board (MPI)" if you are using the PG-MPI port. Click the "OK" button.
Step 1
Description Adapt the actual hardware configuration to that of the project or read the documentation "Change_CPU" or "Change_CP" if you want to use a different CPU or CP than the one used in the sample.
Description
38
Step 1 2 3
Description Is the Profibus cable connected to both the active and passive stations? Can you see "Online" in the status bar of the variable table? Can you see a continuously changing progress bar in the status bar?
Remedies
Correct the problem by working through the steps below if your answer was no to one of the questions above.
The answer to step 1 was "NO" No connection can be established between the stations and data exchange is not possible.
Step 1 2
Description Connect the end of the PROFIBUS cable to the CP port of the station. Repeat step 1 for the passive station.
39
Your answer to Step 2 was "NO" No connection was established to the S7 CPU and monitoring was not possible.
Step 1
Description In the program "Monitoring and Modifying Variables", select "PLC" -> "Connect To" -> "Configured CPU".
Your answer to step 3 was "NO" The monitoring function is not activated.
Step 1
Description In the "Monitoring and Modifying Variables" program, select "Variable" -> "Monitor".
40
Step 1 2
Description Have you activated "Variable" -> "Modify Value Valid" in the "Monitoring and Modifying Variables" program? Is the value you entered for memory word 52 (MW52) between 0 and 32767?
Remedies
Correct the problem by working through the steps below if your answer was no to one of the questions above.
Step 1
Description Select "Variable" -> "Modify Value Valid" in the "Monitoring and Modifying
Variables" program.
Step 1
Description Enter a value between 0 and 32767 in the last column ("Modify Value") of the line "MW 52" "SEND_DATA" in the variable table.
Note If you do not find the solution to your problem in this chapter, reinstall the sample.
41