Modbus communication function codes (1, 2, 4, 5, and 15) can read and write bits and words
directly in the input process image and output process image of the CPU. For these function
codes, the MB_HOLD_REG parameter must be defined as a data type larger than a byte.
The following table shows the example mapping of Modbus addresses to the process image
in the CPU.
Table 13- 82 Mapping of Modbus addresses to the process image
Codes
Function
01
Read bits
02
Read bits
04
Read words Input
05
Write bit
15
Write bits
Modbus communication function codes (3, 6, 16) use a Modbus holding register which can
be an M memory address range or a data block. The type of holding register is specified by
the MB_HOLD_REG parameter on the Modbus_Slave instruction.
Note
MB_HOLD_REG data block type
A Modbus holding register data block must allow both direct (absolute) and symbolic
addressing. When you create the data block the "Standard" access attribute must be
selected.
The following table shows examples of Modbus address to holding register mapping that is
used for Modbus function codes 03 (read words), 06 (write word), and 16 (write words). The
actual upper limit of DB addresses is determined by the maximum work memory limit and M
memory limit, for each CPU model.
Table 13- 83 Mapping of Modbus addresses to CPU memory
Modbus master
address
MW100
40001
MW100
40002
MW102
40003
MW104
40004
MW106
40005
MW108
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
Modbus functions
Data area
Address range
Output
1
Input
10001
30001
Output
1
Output
1
DB10.DBw0
DB10.DBW0
DB10.DBW2
DB10.DBW4
DB10.DBW6
DB10.DBW8
Communication processor and Modbus TCP
Data area
to
8192
Output Process Image
to
18192
Input Process Image
to
30512
Input Process Image
to
8192
Output Process Image
to
8192
Output Process Image
MB_HOLD_REG parameter examples
MW120
DB10.DBW50
MW120
DB10.DBW50
MW122
DB10.DBW52
MW124
DB10.DBW54
MW126
DB10.DBW56
MW128
DB10.DBW58
13.5 Modbus communication
S7-1200
CPU address
Q0.0 to Q1023.7
I0.0 to I1023.7
IW0 to IW1022
Q0.0 to Q1023.7
Q0.0 to Q1023.7
"Recipe".ingredient
"Recipe".ingredient[1]
"Recipe".ingredient[2]
"Recipe".ingredient[3]
"Recipe".ingredient[4]
"Recipe".ingredient[5]
1207