How Do You Implement MODBUS Communication With S7-200
How Do You Implement MODBUS Communication With S7-200
S7-200?
support.industry.siemens.com/cs/document/27832511/how-do-you-implement-modbus-communication-with-s7-
200-
Instructions:
Taking the following example you can setup a simple MODBUS master-slave
communication between two S7-200 CPUs.
The example concerns the MODBUS function code 6 (Write to slave-holding register) and
can be considered as a basis for step-by-step changing of the parameters for the other
function codes supported: 1, 2, 3, 4, 5, 15 and 16.
Requirement:
To operate the MODBUS protocol you must first procure and install first the STEP 7
Micro/WIN command library, then STEP 7 Micro/WIN (Entry ID 17470979).
The MODBUS-Master protocol is supported only from STEP 7 Micro/WIN V4.0 Service
Pack 5 onwards.
1. Hardware setup
2. Parameter matching
3. Memory addressing for the libraries
4. Holding register value transfer
1. Hardware setup
The example is set up for a MODBUS communication between the Ports 0 of two S7-200
CPUs (preferably each with 2 communication interfaces). On the master side it would
also be possible to select Port 1 with the corresponding library block selection
"MBUS_CTRL_P1" and "MBUS_MSG_P1". Port 1 is connected in each case with a PC or
PG with the Micro/WIN software. Communication between the CPUs via Port 0 is made
via a PROFIBUS cable (serial connection of Pins 3, 3, 7 and 8 -> see Fig. 01). In addition,
you must make sure that the encoder ground (M) is connected.
Fig. 01
2. Parameter matching
For MODBUS communication, on the master side you need library
blocks "MBUS_CTRL" and "MBUS_MSG", and "MBUS_INIT" and
"MBUS_SLAVE" on the slave side.
In Micro/WIN you create a new project for the master and the slave with the networks and
parameters shown in Fig. 02.
Here you must make sure that the "Baud" and "Parity" parameters are identical and that
the "Slave" address of the "MBUS_MSG" block matches the "Addr" parameter of the
1/5
"MBUS_INIT" block (see Fig. 02).
The baud rate setting for the Port 0 interface in the "System data block" view in
Micro/WIN is irrelevant for the MODBUS protocol ("Mode" = "1").
Fig. 02
The following tables describe the meanings and selection options of
the library block parameters.
MASTER
MBUS_CTRL
EN Release
Table 01
1)
See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS master
operation MBUS_MSG"
MBUS_MSG
EN Release
First Activation
2/5
Addr MOBDUS initial address 0 .. 128 = digital outputs Q0.0 ..
Q15.7
10001 .. 10128 = digital inputs
I0.0 .. Q15.7
30001 .. 30092 = analog inputs
AIW0 .. AIW62
240001 .. 49999 = holding register
Table 02
1) See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS master
operation MBUS_MSG"
SLAVE
MBUS_INIT
EN Release
3/5
Done 'Finished' message
3)
Error Error code
Table 03
2)
The maximum addresses that can be really used depends on the CPU type used and
its maximum values.
3) See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS slave
protocol"
MBUS_SLAVE
EN Release
Table 04
3) See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS slave
protocol"
Fig. 03
4. Holding register value transfer
After loading the projects into the appropriate CPU you can write to
the selected master variable memory area by activating the table
status and monitor on the slave side.
When the master input I0.0 is activated, the content of variable word VW2 is sent to the
slave CPU and written here to the variable word VW2.
4/5
area.
The "HoldStart" pointer specifies the initial address of the variable memory equivalent to
the holding register start address 40001.
You can calculate the slave variable memory target pointer as follows:
In addition, you must make sure that the maximum number of holding register word
entries "MaxHold" also covers this area:
Fig. 04
More information on the STEP 7 Micro/WIN MOBDUS library is
available in the S7-200 system manual ( Entry ID 1109582) and in
the STEP 7 Micro/WIN Help.
5/5