0% found this document useful (0 votes)
123 views21 pages

Modbus - Master (Communicate Using SIPLUS I O or The

The document describes the Modbus_Master instruction in Siemens S7-1200 programmable logic controllers (PLCs). The Modbus_Master instruction communicates as a Modbus master using a port configured by Modbus_Comm_Load. It takes parameters like REQ, MB_ADDR, MODE, DATA_ADDR, DATA_LEN, and provides outputs like DONE, BUSY, ERROR, and STATUS. The instruction must follow rules like being called from a program cycle OB and not interrupting other Modbus_Master instructions.

Uploaded by

Dil Nawaz
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)
123 views21 pages

Modbus - Master (Communicate Using SIPLUS I O or The

The document describes the Modbus_Master instruction in Siemens S7-1200 programmable logic controllers (PLCs). The Modbus_Master instruction communicates as a Modbus master using a port configured by Modbus_Comm_Load. It takes parameters like REQ, MB_ADDR, MODE, DATA_ADDR, DATA_LEN, and provides outputs like DONE, BUSY, ERROR, and STATUS. The instruction must follow rules like being called from a program cycle OB and not interrupting other Modbus_Master instructions.

Uploaded by

Dil Nawaz
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/ 21

Modbus_Master (Communicate using

SIPLUS I/O or the PtP port as Modbus RTU


master) i… - ID: 109741593 - Industry
Support Siemens
https://support.industry.siemens.com/cs/mdm/109741593?
c=90540451979&lc=en-PK

Content
Search
Index

S7-1200 Programmable controller


Preface
Product overview
New features
STEP 7 programming software
Installation
PLC concepts
Device configuration
Programming concepts
Basic instructions
Extended instructions
Technology instructions
Communication
Web server
Communication processor and Modbus TCP
Using the serial communication interfaces
Biasing and terminating an RS485 network connector
Point-to-point (PtP) communication
Universal serial interface (USS) communication
Modbus communication
Overview of Modbus RTU and Modbus TCP
communication
Modbus TCP
Modbus RTU
Overview
Selecting the version of the Modbus RTU
instructions
Maximum number of supported Modbus slaves
Modbus RTU instructions
Modbus_Comm_Load (Configure SIPLUS I/O or
port on the PtP module for Modbus RTU)
instruction
Modbus_Master (Communicate using SIPLUS I/O
or the PtP port as Modbus RTU master)
instruction
Modbus_Slave (Communicate using SIPLUS I/O
or the PtP port as Modbus RTU slave)
instruction
Modbus RTU examples
Legacy PtP communication (CM/CB 1241 only)
Legacy USS communication (CM/CB 1241 only)
Legacy Modbus TCP communication
Legacy Modbus RTU communication (CM/CB 1241
only)
Industrial Remote Communication (IRC)
TeleService communication (SMTP email)
Online and diagnostic tools
Technical specifications
Calculating a power budget
Ordering Information
Device exchange and spare parts compatibility

A
Ä
B
C
D
E
F
G
H
I
J
K
L
M
N
O
Ö
P
Q
R
S
T
U
Ü
V
W
X
Y
Z
0-9
Rate

Entry type: Manual, Entry ID: 109741593, Entry


date: 09/16/2016

SIMATIC S7 S7-1200 Programmable


controller
Document: S7-1200 Programmable controller (V4.2, 09/2016, English)

Type of topic: Fact

Modbus_Master (Communicate using SIPLUS I/O or the PtP


port as Modbus RTU master) instruction

Table: Modbus_Master instruction

LAD / FBD

SCL

Description
"Modbus_Master_DB"( REQ:=_bool_in_,
MB_ADDR:=_uint_in_, MODE:=_usint_in_,
DATA_ADDR:=_udint_in_, DATA_LEN:=_uint_in_,
DONE=>_bool_out_, BUSY=>_bool_out_,
ERROR=>_bool_out_, STATUS=>_word_out_,
DATA_PTR:=_variant_inout_);

The Modbus_Master instruction communicates as a Modbus


master using a port that was configured by a previous
execution of the Modbus_Comm_Load instruction. An
instance data block is assigned automatically when you place
the Modbus_Master instruction in your program. This
Modbus_Master instance data block is used when you specify
the MB_DB parameter for the Modbus_Comm_Load
instruction.

Table: Data types for the parameters


Parameter and type Data type Description
0=No request
REQ IN Bool
1= Request to transmit data to Modbus slave

Modbus RTU station address:

V1.0: Standard addressing range (1 to 247)


USInt Extended addressing range (1 to 65535)
MB_ADDR IN
V2.0: The value of 0 is reserved for broadcasting a
UInt message to all Modbus slaves. Modbus function
codes 05, 06, 15 and 16 are the only function
codes supported for broadcast.

Mode Selection: Specifies the type of request


MODE IN USInt (read, write, or diagnostic). See the Modbus
functions table below for details.

Starting Address in the slave: Specifies the


starting address of the data to be accessed in the
DATA_ADDR IN UDInt
Modbus slave. See the Modbus functions table
below for valid addresses.

Data Length: Specifies the number of bits or


DATA_LEN IN UInt words to be accessed in this request. See the
Modbus functions table below for valid lengths.

DATA_PTR IN Variant Data Pointer: Points to the M or DB address


(non-optimized DB type) for the data being
written or read.

The DONE bit is TRUE for one scan, after the last
DONE OUT Bool
request was completed with no error.

0 – No Modbus_Master operation in progress


BUSY OUT Bool
1 – Modbus_Master operation in progress

The ERROR bit is TRUE for one scan, after the


last request was terminated with an error. The
ERROR OUT Bool error code value at the STATUS parameter is
valid only during the single scan where ERROR =
TRUE.

STATUS OUT Word Execution condition code

Modbus_Master communication rules

MB_COMM_LOAD must be executed to configure a port


before a Modbus_Master instruction can communicate
with that port.
If a port is to be used to initiate Modbus master requests,
that port should not be used by MB_SLAVE. One or more
instances of Modbus_Master execution can be used with
that port, but all Modbus_Master execution must use the
same Modbus_Master instance DB for that port.
The Modbus instructions do not use communication
interrupt events to control the communication process.
Your program must poll the Modbus_Master instruction for
transmit and receive complete conditions.
It is recommended that you call all Modbus_Master
execution for a given port from a program cycle OB.
Modbus_Master instructions may execute in only one of
the program cycle or cyclic/time delay execution levels.
They must not execute in both execution priority levels.
Pre-emption of a Modbus_Master instruction by another
Modbus_Master instruction in a higher priority execution
priority level will result in improper operation.
Modbus_Master instructions must not execute in the
startup, diagnostic or time error execution priority levels.
Once a Modbus_Master instruction initiates a transmission,
this instance must be continually executed with the EN
input enabled until a DONE=1 state or ERROR=1 state is
returned. A particular Modbus_Master instance is
considered active until one of these two events occurs.
While the original instance is active, any call to any other
instance with the REQ input enabled will result in an error.
If the continuous execution of the original instance stops,
the request state remains active for a period of time
specified by the static variable "Blocked_Proc_Timeout".
Once this period of time expires, the next Modbus_Master
instruction called with an enabled REQ input will become
the active instance. This prevents a single Modbus_Master
instance from monopolizing or locking access to a port. If
the original active instance is not enabled within the
period of time specified by the static variable
"Blocked_Proc_Timeout", then the next execution by this
instance (with REQ not set) will clear the active state. If
(REQ is set), then this execution initiates a new
Modbus_Master request as if no other instance was active.
REQ parameter

0 = No request; 1 = Request to transmit data to Modbus Slave

You may control this input either through the use of a level or
edge triggered contact. Whenever this input is enabled, a
state machine is started to ensure that no other
Modbus_Master using the same instance DB is allowed to
issue a request, until the current request is completed. All
other input states are captured and held internally for the
current request, until the response is received or an error
detected.

If the same instance of Modbus_Master is executed again


with REQ input = 1 before the completion of the current
request, then no subsequent transmissions are made.
However, when the request is completed, a new request is
issued whenever a Modbus_Master is executed again with
REQ input = 1.

DATA_ADDR and MODE parameters select the Modbus


function type

DATA_ADDR (starting Modbus address in the slave): Specifies


the starting address of the data to be accessed in the Modbus
slave.

The Modbus_Master instruction uses a MODE input rather


than a Function Code input. The combination of MODE and
Modbus address determine the Function Code that is used in
the actual Modbus message. The following table shows the
correspondence between parameter MODE, Modbus function
code, and Modbus address range.

Table: Modbus functions


Modbus Data Modbus
MODE Operation and data
function length address
1 to
2000 Read output bits:
0 01 1 to 1 to 9999
1 to (1992 or 2000) bits per request
1992 1

1 to
2000 Read input bits: 10001 to
0 02 1 to 1 to (1992 or 2000) bits per request 19999
1992 1

40001 to
1 to 125 Read Holding registers: 49999 or
0 03 1 to 124 1 to (124 or 125) words per request 400001 to
1
465535

1 to 125 Read input words: 30001 to


0 04 1 to 124 1 to (124 or 125) words per request 39999
1

1 to 125
Read input words: 00000 to
104 04 1 to 124
1 to (124 or 125) words per request 65535
1

Write one output bit:


1 05 1 1 to 9999
One bit per request

40001 to
Write one holding register: 49999 or
1 06 1
1 word per request 400001 to
465535

2 to
1968 Write multiple output bits:
1 15 2 to 1 to 9999
2 to (1960 or 1968) bits per request
1960 1

40001 to
2 to 123 Write multiple holding registers: 49999 or
1 16 2 to 122 2 to (122 or 123) words per request 400001 to
1
465535
1 to
1968 Write one or more output bits:
2 15 2 to 1 to 9999
1 to (1960 or 1968) bits per request
1960 1

40001 to
1 to 123 Write one or more holding registers: 49999 or
2 16 1 to 122 1 to (122 or 123) words per request 400001 to
1
465535

Read the slave communication status


word and event counter. The status
word indicates busy (0 – not busy,
0xFFFF - busy). The event counter is
incremented for each successful
11 11 0 completion of a message.

Both the DATA_ADDR and DATA_LEN


operands of the Modbus_Master
instruction are ignored for this
function.

Check slave status using data


diagnostic code 0x0000 (Loopback test
80 08 1 – slave echoes the request)

1 word per request

Reset slave event counter using data


81 08 1 diagnostic code 0x000A

1 word per request

3 to
10,
12 to
Reserved
79,
82 to
255

DATA_PTR parameter

The DATA_PTR parameter points to the DB or M address that


is written to or read from. If you use a data block, then you
must create a global data block that provides data storage for
reads and writes to Modbus slaves.
Note

The DATA_PTR data block type must allow direct addressing

The data block must allow both direct (absolute) and symbolic addressing. When
you create the data block the "Standard" access attribute must be selected.

Data block structures for the DATA_PTR parameter

These data types are valid for word reads of Modbus


addresses 30001 to 39999, 40001 to 49999, and 400001 to
465536 and also for word writes to Modbus addresses
40001 to 49999 and 400001 to 465536.
- Standard array of WORD, UINT, or INT data types
- Named WORD, UINT, or INT structure where each
element has a unique name and 16 bit data type.
- Named complex structure where each element has a
unique name and a 16 or 32 bit data type.
For bit reads and writes of Modbus addresses 00001 to
09999 and bit reads of 10001 to 19999.
- Standard array of Boolean data types.
- Named Boolean structure of uniquely named Boolean
variables.
Although not required, it is recommended that each
Modbus_Master instruction have its own separate memory
area. The reason for this recommendation is that there is a
greater possibility of data corruption if multiple
Modbus_Master instructions are reading and writing to the
same memory area.
There is no requirement that the DATA_PTR data areas be
in the same global data block. You can create one data
block with multiple areas for Modbus reads, one data block
for Modbus writes, or one data block for each slave station.

Modbus_Master instruction data block (DB) tags

The following table shows the public static tags stored in the
Modbus_Master instance DB that you can use in your
program:

Table: Modbus_Master instance DB static tags


Tag Data type Default Description
Duration (in seconds) for which to
wait for a blocked Modbus_Master
instance before this instance is
removed as ACTIVE. This can occur,
for example, if a Modbus_Master
Blocked_Proc_Timeout Real 0.5 request is issued and the program
then stops to call the Modbus_Master
function before it has completely
finished the request. The time value
must be greater than 0 and less than
55 seconds, or an error occurs.

Configures single or double-byte slave


station addressing:

FALSE = One-byte address; 0 to 247


Extended_Addressing Bool FALSE
TRUE = Two-byte address
(corresponds to extended
addressing); 0 to 65535

The MB_DB parameter of the


Modbus_Comm_Load instruction must
MD_DB MB_BASE -
be connected to the MB_DB parameter
of the Modbus_Master instruction.
Your program can write values to the Blocked_Proc_Timeout
and Extended_Addressing variables to control the
Modbus_Master operations. See the MB_SLAVE topic
description of HR_Start_Offset and Extended_Addressing for
an example of how to use these variables in the program
editor and details about Modbus extended addressing.

Condition codes

Table: Modbus_Master execution condition codes


(communication and configuration errors) 1
STATUS (W#16#) Description
0000 No error

Slave timeout. The specified slave did not respond in the


specified time. Please check the baud rate, parity, and wiring of
80C8
the slave device. This error is only reported after any configured
retries have been attempted.

The Modbus_Master instruction has timed out for one of the


following reasons:

The instruction is waiting for a response from the module


that is being used for communications.
The Blocked_Proc_Timeout value is set too small.

This error is reported if a PROFIBUS or PROFINET distributed


80C9
I/O device returns from one of the following:

An interruption to power or communication


A communication module pull/plug event

In these instances, the hardware configuration from the PLC is


reloaded, and Modbus_Comm_Load must be executed again to
properly configure the communication module.

The receiver issued a flow control request to suspend an active


transmission and never re-enabled the transmission during the
80D1 specified wait time.

This error is also generated during hardware flow control when


the receiver does not assert CTS within the specified wait time.
The transmit request was aborted because no DSR signal is
80D2
received from the DCE.

80E0 The message was terminated because the receive buffer is full.

80E1 The message was terminated as a result of a parity error.

80E2 The message was terminated as a result of a framing error.

80E3 The message was terminated as a result of an overrun error.

The message was terminated as a result of the specified length


80E4
exceeding the total buffer size.

Invalid port ID value or error with Modbus_Comm_Load


8180
instruction

8186 Invalid Modbus station address

8188 Invalid Mode specified for broadcast request

8189 Invalid Data Address value

818A Invalid Data Length value

Invalid pointer to the local data source/destination: Size not


818B
correct

Invalid pointer for DATA_PTR or invalid Blocked_Proc_Timeout.


The data area must be one of the following:

818C Classic DB
Array of elemental data types in a symbolic or retentive DB
M memory

8200 Port is busy processing a transmit request.

Negative acknowledgement when reading module. Check the


input at the PORT parameter. This can be caused by the loss of a
8280
PROFIBUS or PROFINET distributed I/O module, either by a
station power or communication loss or a module pull.

Negative acknowledgement when writing to module. Check the


input at the PORT parameter. This can be caused by the loss of a
8281
PROFIBUS or PROFINET distributed I/O module, either by a
station power or communication loss or a module pull.

Table: Modbus_Master execution condition codes (Modbus


protocol errors) 1
Response code
STATUS (W#16#) Modbus protocol errors
from slave
8380 - CRC error

8381 01 Function code not supported

8382 03 Data length error

Data address error or address outside the valid


8383 02
range of the DATA_PTR area

Greater than
8384 Data value error
03

Data diagnostic code value not supported


8385 03
(function code 08)

Function code in the response does not match


8386 -
the code in the request.

8387 - Wrong slave responded

The slave response to a write request is


incorrect. The write request returned by the
8388 -
slave does not match what the master actually
sent.

Note

Setting the maximum record length for Profibus communication

When using a CM1243-5 Profibus Master module to control an ET 200SP or


ET 200MP Profibus device that uses an RS232, RS422, or RS485 point-to-point
module, you need to explicitly set the "max_record_len" data block tag to 240 as
defined below:

Set "max_record_len" in the Send_P2P section of the instance DB (for example,


"Modbus_Master_DB".Send_P2P.max_record_len) to 240 after running
Modbus_Comm_Load.

Explicitly assigning max_record_len is only necessary with Profibus


communication; Profinet communication already uses a valid max_record_len
value.
Also available in the following languages:

German
Spanish
French
Chinese
Italian
English

Feedback for the article with the entry ID 109741593


Personalization saves you typing! If you have already been
registered, you can login directly. If you are not registered
yet, you can inform and register yourself without obligation
here (our service is free of charge).

Log in
Register

Name

Phone number

Email

DetailPages.Subject

Comment
Number of characters: 0 (max. 500)
Send copy of comment to sender. (login required)
Cancel
Send
Note: The feedback always relates to the current entry. Your
message will be forwarded to our technical editors working
in the Online Support. In a few days, you will receive a
response if your feedback requires one.
Requests and feedback
What do you want to do?

You want to discuss in our forum and exchange


experiences with other users
Go to the Forum
You have a technical question / problem: Ask the Technical
Support
Create support request
Note: Depending on the effort involved, support may be
subject to a charge. In this case, please have a Siemens
Industry Service Card ready.
You want to create CAx data for one or more products
Go to the CAx download manager
You would like to send us feedback on this Entry
Provide feedback
Note: The feedback always relates to the current entry.
Your message will be forwarded to our technical editors
working in the Online Support. In a few days, you will
receive a response if your feedback requires one.
PDF

Support to the statistics


With this function the IDs found are listed according to
number (format .txt).

Generate list
Copy URL

Copy URL
Display page in new design
mySupport Cockpit

Add to mySupport favorites


Add to mySupport documentation
Favorites
My requests
CAx downloads
My Products / Clipboard

Topic pages for this entry


Documentation for SIMATIC Industrial PCs
IO-Link – An Overview of the Most Important Documents
and Links
TIA Portal - An Overview of the Most Important Documents
and Links - Communication

You might also like