s7 200 Smart Modbus Rtu Communication
s7 200 Smart Modbus Rtu Communication
Communication with
Modbus RTU Protocol
for S7-200 SMART
https://w3.siemens.co.in/automation/in/en/automation-
systems/industrial-automation/s7-200-smart-plc/pages/default.aspx Siemens
Industry
Online
Support
Legal information
Legal information
Use of application examples
Application examples illustrate the solution of automation tasks through an interaction of several
components in the form of text, graphics and/or software modules. The application examples are
a free service by Siemens AG and/or a subsidiary of Siemens AG ("Siemens"). They are
non-binding and make no claim to completeness or functionality regarding configuration and
equipment. The application examples merely offer help with typical tasks; they do not constitute
customer-specific solutions. You yourself are responsible for the proper and safe operation of the
products in accordance with applicable regulations and must also check the function of the
respective application example and customize it for your system.
Siemens grants you the non-exclusive, non-sub licensable and non-transferable right to have the
application examples used by technically trained personnel. Any change to the application
examples is your responsibility. Sharing the application examples with third parties or copying the
application examples or excerpts thereof is permitted only in combination with your own products.
The application examples are not required to undergo the customary tests and quality inspections
of a chargeable product; they may have functional and performance defects as well as errors. It is
your responsibility to use them in such a manner that any malfunctions that may occur do not
result in property damage or injury to persons.
Disclaimer of liability
Siemens shall not assume any liability, for any legal reason whatsoever, including, without
Siemens AG Copyright year All rights reserved
limitation, liability for the usability, availability, completeness and freedom from defects of the
application examples as well as for related information, configuration and performance data and
any damage caused thereby. This shall not apply in cases of mandatory liability, for example
under the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss of
life, bodily injury or damage to health, non-compliance with a guarantee, fraudulent
non-disclosure of a defect, or culpable breach of material contractual obligations. Claims for
damages arising from a breach of material contractual obligations shall however be limited to the
foreseeable damage typical of the type of agreement, unless liability arises from intent or gross
negligence or is based on loss of life, bodily injury or damage to health. The foregoing provisions
do not imply any change in the burden of proof to your detriment. You shall indemnify Siemens
against existing or future claims of third parties in this connection except where Siemens is
mandatorily liable.
By using the application examples you acknowledge that Siemens cannot be held liable for any
damage beyond the liability provisions described.
Other information
Siemens reserves the right to make changes to the application examples at any time without
notice. In case of discrepancies between the suggestions in the application examples and other
Siemens publications such as catalogs, the content of the other documentation shall have
precedence.
Security information
Siemens provides products and solutions with Industrial Security functions that support the secure
operation of plants, systems, machines and networks.
In order to protect plants, systems, machines and networks against cyber threats, it is necessary
to implement – and continuously maintain – a holistic, state-of-the-art industrial security concept.
Siemens’ products and solutions constitute one element of such a concept.
Customers are responsible for preventing unauthorized access to their plants, systems, machines
and networks. Such systems, machines and components should only be connected to an
enterprise network or the Internet if and to the extent such a connection is necessary and only
when appropriate security measures (e.g. firewalls and/or network segmentation) are in place.
For additional information on industrial security measures that may be implemented, please visit
https://www.siemens.com/industrialsecurity.
Siemens’ products and solutions undergo continuous development to make them more secure.
Siemens strongly recommends that product updates are applied as soon as they are available
and that the latest product versions are used. Use of product versions that are no longer
supported, and failure to apply the latest updates may increase customer’s exposure to cyber
threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feed
at: https://www.siemens.com/industrialsecurity.
Siemens AG Copyright year All rights reserved
Table of contents
Warranty and liability ................................................................................................... 2
1 Introduction ........................................................................................................ 5
1.1 Overview............................................................................................... 5
2 Engineering ........................................................................................................ 7
5 Appendix .......................................................................................................... 31
1 Introduction
1.1 Overview
Modbus is a public communication protocol, and its simplest serial communication part
only specifies the basic data transmission format on the serial line. In the OSI seven-layer
protocol model, only one or two layers are used.
Modbus has two serial transfer modes, ASCII and RTU. They define different ways in which
data is packed and decoded. Devices that support the Modbus protocol generally support the
RTU format.
Both parties to the communication must support one of the above modes.Modbus is a
master/slave communication mode for a single master. There can only be one master station on
the Modbus network. The master station has no address on the Modbus network. The slave
address range is 0 - 247, where 0 is the broadcast address and the slave's actual address
range is 1 - 247.
For detailed protocols and specifications, please visit the Modbus organization's website:
http://www.modbus.org
Table 1-1
SB CM01 9 6SE7-288-5CM01-0AA0
Table 1-2
2 Engineering
2.1 Hardware setup
Siemens AG Copyright year All rights reserved
Direct Connection:
When an S7-200 SMART CPU communicates with a programming device, HMI or
another S7-200 SMART CPU, a direct connection is achieved. Direct connection does not
require the use of a switch, and the two devices can be directly connected using a network
cable, as shown in Figure 2. Direct connection of the communication device.
Siemens AG Copyright year All rights reserved
Indirect Connection:
When more than two communication devices are communicating, a switch is required to
implement the network connection. You can connect multiple CPUs and HMI devices using the
rail-mounted Siemens CSM1277 4-port switch, as shown in Figure 3. Network connections for
multiple communication devices.
Table 1. Pin Assignments for the Integrated RS485 Port of the S7-200 SMART CPU
Pin
Connector signal Pin definition
label
1 shield Chassis ground
2 24V back Logical common
3 RS-485 signal B RS-485 signal B
4 Send request RTS (TTL)
The programming port connector passes all signals (including the power pins) from the
S7-200 SMART CPU through to the programming port, which is especially useful for connecting
devices that draw power from the S7-200 SMART CPU (such as a TD 400C).
Both connectors have two sets of terminal screws to allow you to attach the incoming
and outgoing network cables. Both connectors also have switches to bias and terminate the
network selectively. The following shows typical biasing and termination for the cable
connectors.
1. Pin number
2. Network connector
3. Cable shield
Table 2. Pin Assignment Table for S7-200 SMART SB CM01 Signal Board Port (Port 1)
Connector Pin label signal Pin definition
1 Ground Chassis ground
2 Tx/B RS232-Tx/RS485-B
3 send request RTS (TTL)
4 M ground Logical common
5 Rx/A RS232-Rx/RS485-A
You can use the CM01 signal board to easily connect multiple devices to a network.
The signal board passes all signals (including the power pins) from the S7-200 SMART CPU
through to the programming port, which is especially useful for connecting devices that draw
power from the S7-200 SMART CPU (such as a TD 400C).
1. Terminal name
2. Terminal block
3. Cable shield
3 Engineering
3.1 Description of interface
The Modbus communication protocol is implemented in the free port mode of the S7-
200 SMART CPU communication port, and can be transmitted through a slow communication
device. This facilitates the formation of a simple communication network between the S7-200
SMART.
Siemens officially launched the Modbus RTU Master Base Protocol Library (Siemens Standard
Library Instructions) in STEP 7-Micro/WIN SMART.
Siemens AG Copyright year All rights reserved
Note :
1. The function of the Modbus RTU master station library is realized by calling the pre-
programmed program function block in the user program. The library is valid for
the CPU integrated RS 485 communication port and CM 01 signal board. The library will set the
communication port to work in free port mode.
2. The Modbus RTU master station instruction library uses some user interrupt functions which
are locked. It is not allowed to disable interrupts in the user program when programming other
programs.
Use SM0.0(ALWAYS_ON) to call MBUS_CTRL to complete the initialization of the master and
start its function control:
Figure 3. Calling Modbus RTU master initialization and control subroutine with
SM0.0(ALWAYS_ON)
2. Call the Modbus RTU master read/write subroutine MBUS_MSG to send a Modbus request.
Figure 4. Calling the Modbus RTU master read and write subroutine
4. When programming, use SM0.1 to call the subroutine MBUS_INIT for initialization, use
Siemens AG Copyright year All rights reserved
Maximum
g. Max AQ expansion modules can be connected, so the
I/Q bit:
maximum number of I/O points is 188 at present)
/188)
Maximum The time the master waits for a response from the
holding slave, in milliseconds. A typical setting is 1000
i. MaxHold
register milliseconds (1 second), and the allowed range is 1 -
area: 32767.
Keep
j. HoldStart
register area Specified by “&VBx“ (indirect addressing mode)
start
address:
5. Library Allocation
Allocating Library Instruction Data Areas in the V Data Area of the CPU. The Modbus
Slave instruction library requires a 781 byte global V memory area. Calling the STEP 7 -
Micro/WIN SMART Instruction Library requires the allocation of the library instruction data area
(Library Memory). The library instruction data area is the variable storage space used by the
subroutine and interrupt program of the corresponding library.If the library instruction data area
is not allocated during programming, many identical errors are generated at compile time.
Note:
By default, start with VB0, but make sure that the memory uses the address range and
other The addresses used by the program cannot overlap. Press the "Suggested Address"
button to also assign it automatically. The holding register area specified by the subroutine
parameters HoldStart and MaxHold is allocated in the V data storage area of the S7-200
SMART CPU. This data area cannot overlap with the library instruction data area.
Otherwise, an error will occur during operation. Can't communicate properly. Note that the
holding register area in Modbus is addressed by "word",ie MaxHold specifies the number of
VWs instead of VBs.
In the example of Figure 6, the Modbus holding register area is specified starting from
VB1100 (HoldStart = VB1100), and the holding register is 1000 words (MaxHold = 1000), since
the holding register is in words (two bytes), actually This communication buffer occupies 2000
bytes of VB1100~VB3100. Therefore, the allocation library instruction should at least avoid the
VB1100~VB3100 interval when retaining the data area.
The Modbus RTU slave address corresponds to the address of the S7-200 SMART.
Modbus addresses always appear in the form of 00001, 30004. The correspondence between
the data storage area inside the S7-200 SMART CPU and the four types of addresses of
Modbus 0, 1, 3, and 4 are as follows:
Table 1. Modbus Address Correspondence Table
Modbus
S7-200 SMART data area
address
00001 ~ 00256 Q0.0 ~ Q31.7
10001 ~ 10256 I0.0 ~ I31.7
30001 ~ 30056 AIW0 ~ AIW110
4yyyy ~ 4zzzzz Vx+2(yyyy-1) or Vx+2(zzzzz-1)
Where V is the buffer start address in the S7-200 SMART CPU, which is HoldStart.
If the V memory area address in the S7-200 SMART CPU is known, the formula for calculating
Siemens AG Copyright year All rights reserved
Modbus function code supported by the Modbus RTU slave instruction library
The Modbus RTU slave instruction library supports specific Modbus functions. Access to the
master using this library must follow the requirements of this library.
Write multiple coils (discrete output points). Function 15 Writes the values of
several discrete output points to the output image register (Q area) of the S7-
200 SMART CPU. The address of the output point must start with a byte
15 boundary (such as Q0.0 or Q2.0), and the number of output points must be an
integer multiple of 8. This is a limitation of this Modbus RTU slave instruction
library. Some points are not mandatory and the user program can override the
value written by the Modbus communication request.
Several multiple holding registers. Function 16 writes multiple values to the
16 holding registers of the V memory area of the S7-200 SMART CPU. Up to 120
words of data can be written in one request.
Siemens AG Copyright year All rights reserved
3.3 Operation
Step 1: Initialize and monitor the Modbus Master by calling MBUS_CTRL on every scan. The
Modbus Master is set 9.6KBps and no parity. The Slave Device is allowed 1000 milliseconds (1
Second) to respond.
Siemens AG Copyright year All rights reserved
Step 2: On the First Scan, reset the enable flags (M2.0 to M3.0) used for more than one
MBUS_MSG instruction.
Siemens AG Copyright year All rights reserved
Step 3: Call the MBUS_MSG instruction when the first enable flag (M2.0) is ON. The First
parameter must be set for only the first scan that the instruction is enabled. This instruction
writes (RW = 1) 50 holding registers to slave 1. The write data is taken from VB1100-VB1198
(50 words) in the CPU and written to address 40001 - 40100 in the Modbus slave.
Siemens AG Copyright year All rights reserved
Step 6: When the first MBUS_MSG instruction is complete (Done goes from 0 to 1), clear the
enable for the first MBUS_MSG and set the enable for the second MBUS_MSG instruction. If
Error (MB1) is not zero, then set Q0.1 to show the error.
Siemens AG Copyright year All rights reserved
Step 7: Call the MBUS_MSG instruction when the enable flag (M2.1) is ON. The First
parameter must be set for only the first scan that the instruction is enabled. This instruction
reads (RW = 0) 50 holding registers to slave 1. The read data is taken in VB1200-VB1298 (50
words) in the CPU and written to address 40001 - 40100 in the Modbus slave.
Step 10: When the first MBUS_MSG instruction is complete (Done goes from 0 to 1), clear the
enable for the first MBUS_MSG and set the enable for the second MBUS_MSG instruction. If
Error (MB1) is not zero, then set Q0.1 to show the error.
The low numbered error codes (1 through 12) are errors that are detected by the
MBUS_MSG instruction. These error codes generally indicate a problem with the input
parameters of the MBUS_MSG instruction, or a problem receiving the response from the slave.
Parity and CRC errors indicate that there was a response but that the data was not received
correctly. This is usually caused by an electrical problem such as a bad connection or electrical
noise.
MBUS_CTRL
Description
Error Code
0 No error
1 Invalid parity type
2 Invalid baud rate
3 Invalid timeout
4 Invalid mode
Siemens AG Copyright year All rights reserved
MBUS_MSG
Description
Error Code
0 No error
Parity error in response: This is only possible if even or odd parity is used. The
transmission was disturbed and possibly incorrect data was received. This
1
error is usually caused by an electrical problem such as incorrect wiring or
electrical noise affecting the communication.
2 Not used
Receive timeout: There was no response from the slave within the Timeout
time. Some possible causes are bad electrical connections to the slave device,
3
master and slave are set to a different baud rate / parity setting, and incorrect
slave address.
Error in request parameter: One or more of the input parameters (Slave, RW,
4 Address, or Count) is set to an illegal value. Check the documentation for
allowed values for the input parameters.
Modbus master not enabled: Call MBUS_CTRL on every scan prior to calling
5
MBUS_MSG.
Modbus is busy with another request: Only one MBUS_MSG instruction can
6
be active at a time.
Error in response: The response received does not correspond to the request.
7 This indicates some problem in the slave device or that the wrong slave device
answered the request.
CRC error in response: The transmission was disturbed and possibly incorrect
8 data was received. This error is usually caused by an electrical problem such
as incorrect wiring or electrical noise affecting the communication.
11 Invalid port number
MBUS_MSG
Description
Error Code
12 Signal board port 1 missing or not configured
Slave does not support the requested function at this address: See the
101 required Modbus slave function support table in the "Using the Modbus master
Instructions" help topic.
Slave does not support the data address: The requested address range of
102
Address plus Count is outside the allowed address range of the slave.
Slave does not support the data type: The Address type is not supported by
103
the slave device.
104 Slave device failure
Slave accepted the message but the response is delayed: This is an error for
105
MBUS_MSG and the user program should resend the request at a later time.
Slave is busy and rejected the message: You can try the same request again
106
to get a response.
107 Slave rejected the message for an unknown reason.
108 Slave memory parity error: There is an error in the slave device.
If the slave delay parameter is set too long, the master station number 3 error
will be caused.
The slave station loses power or does not run, the network failure will cause the
main station number 3 error.
Allocate memory for library instructions in the V data area of the CPU (Library
Memory). The Modbus Master instruction library requires a 286-byte global V
memory area. Calling the STEP 7 - Micro/WIN SMART Instruction Library
requires the allocation of the library instruction data area (Library Memory). The
library instruction data area is the variable storage space used by the
subroutine and interrupt program of the corresponding library. If the library
instruction data area is not allocated during programming, many identical errors
are generated at compile time.
MBUS_SLAVE
Description
Error Code
0 No error
1 Memory range error
2 Invalid baud rate or parity
3 Illegal slave address
4 Illegal value for Modbus parameter
5 Holding registers overlap Modbus Slave symbols
6 Receive parity error
7 Receive CRC error
8 Illegal function request/function not supported
9 Illegal memory address in request
10 Slave function not enabled
11 Invalid port number
12 Signal board port 1 missing or not configured
4 Additional information
Additional notes on the Modbus RTU Master Protocol library
Modbus address
Usually the Modbus addresses are five-to-six digit numbers that indicate the data type
as well as the address value. Modbus RTU master instructions map the address to the correct
functions to send to the slave device. (The address corresponds to the Addr input parameter of
the MBUS_MSG/MB_MSG2 instruction.) The Modbus address definitions are as follows:
00001 - 09999: Digital output (coil)
read Function 1
00001 - 09999
digital output Function 5: Write single output point
write
Function 15: Write multiple output points
10001 - 19999 read Function 2
digital input write -
30001 - 39999 read Function 4
input register write -
40001 – 49999 holding read Function 3
registers Function 6: Write Single Register Unit
400001 - 465535 write
Function 16: Write Multiple Register Unit
The CPU reads and writes the bit data (addresses 0xxxx and 1xxxx) areas as packed
bytes; that is, each byte consists of 8 bits of data. The least significant bit of the first data byte is
the addressed bit number (the parameter Address). If you intend to write only a single bit then
you must set the bit in the least significant bit (Vx.0) of the byte pointed to by DataPtr. As shown
below:
5 Appendix
5.1 Service and support
Industry Online Support
Siemens Industry Online Support offers round the clock access to our entire
service and support know-how and portfolio.
The Industry Online Support is the central address for information about our
products, solutions and services.
Technical Support
The Technical Support of Siemens Industry provides you fast and competent
support regarding all technical queries with numerous tailor-made offers
Siemens AG Copyright year All rights reserved
– ranging from basic support to individual support contracts. Please send queries
to Technical Support via Web form:
www.siemens.com/industry/supportrequest
We support you with our globally available training courses for industry with
practical experience, innovative learning methods and a concept that’s tailored to
the customer’s specific needs.
For more information on our offered trainings and courses, as well as their
locations and dates, refer to our web page:
www.siemens.com/sitrain
Service offer
You will receive optimum support wherever you are with the "Siemens Industry
Online Support" app. The app is available for Apple iOS, Android and Windows
Phone:
support.industry.siemens.com/cs/ww/en/sc/2067
5.2 Support
Siemens Ltd
DI FA AS
Thane Belapur Road
Thane 400601, India
Application Center
SUP FA
Email: [email protected]
Table 5-1
No. Topic
https://support.industry.siemens.com
https://support.industry.siemens.com/cs/ww/en/view/Entry ID
\3\