0% found this document useful (0 votes)
19 views5 pages

How Do You Implement MODBUS Communication With S7-200

s7200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

How Do You Implement MODBUS Communication With S7-200

s7200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

How do you implement MODBUS communication with

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

Parameter Meaning Selection options

EN Release

Mode Protocol specification 0=PPI, 1=MODBUS

Baud Transmission rate in kbps 1200, 2400, 4800, 9600, 19200,


38400, 57600, 115200

Parity Parity 0=none, 1=odd, 2=even

Timeout Maximum time in ms for the


slave's response

Done 'Finished' message


1)
Error Error code

Table 01
1)
See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS master
operation MBUS_MSG"

MBUS_MSG

Parameter Meaning Selection options

EN Release

First Activation

Slave Slave address

RW "Read" or "Write" 0=read, 1=write

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

Count Number of bits (0xxxx, 1xxxx) /


words (3xxxx, 4xxxx)

DataPtr Pointer to start of variable memory

Done 'Finished' message


1)
Error Error code

Table 02
1) See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS master

operation MBUS_MSG"

SLAVE

MBUS_INIT

Parameter Meaning Selection options

EN Release

Mode Protocol specification 0=PPI, 1=MODBUS

Addr Slave address

Baud Transmission rate in kbps 1200, 2400, 4800, 9600, 19200,


38400, 57600, 115200

Parity Parity 0=none, 1=odd, 2=even

Delay Signal stretching in ms


2)
MaxIQ Number of available digital inputs
and outputs
2)
MaxAI Number of available analog input
words
2)
MaxHold Max. number of holding register
word entries

HoldStart Pointer to the start of the holding


register (40001)

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

Parameter Meaning Selection options

EN Release

Done 'Finished' message


3)
Error Error code

Table 04
3) See STEP 7 Micro/WIN Help: "Error codes for the execution of the MODBUS slave

protocol"

3. Memory addressing for the libraries


After completion of the projects you must define the memory for the library in the
Micro/WIN program block container. When reserving memory for the libraries, make sure
that the area selected in each case does not overlap the variable memory area for the
data (for the master: "DataPtr" + "Count" and for the slave: "HoldStart" + "MaxHold").

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.

This holding register value transfer is shown in Fig. 04.


The pointer "DataPtr" represents the start of the variable memory to be read.
The "Count" parameter specifies the number of words to be written to the address "Addr"
= "4xxxx" (holding register).
The variable memory area selected will be written to the holding register start address
"Addr" = "40002" ("RW" = "1").
The holding register works word for word as a placeholder to the slave variable memory

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:

2 * (Addr - 40001) + HoldStart = 2 * (40002 - 40001) + &VB0 = &VB2

In addition, you must make sure that the maximum number of holding register word
entries "MaxHold" also covers this area:

MaxHold >= Addr - 40001 + Count = 40002 - 40001 + 1 = 2

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

You might also like