Modbus RTU register mapping table instructions for Siemens S7-1200 PLC

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

Modbus RTU register mapping table instructions for Siemens S7-1200 PLC

I. Usage of Modbus RTU Commands

Modbus RTU register mapping table instructions for Siemens S7-1200 PLCFigure

II. Modbus RTU Master Programming

  • Master programming requires callingModbus Comm_Load and Modbus_MasterCommand:
  • The Modbus_Comm_Load command configures the communication module through the Modbus RTU protocol;
  • The Modbus Master command can communicate as a Modbus master through the port configured by the Modbus Comm Load command.

Modbus RTU Master Command Modbus Comm Load Parameters

PinDescription
REQRising edge trigger
PORTHardware identifier of communication port
BAUDBaud rate selection: 3600, 6000, 12000, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200
PARITYParity check selection: 0-None; 1-Odd parity; 2-Even parity
FLOW_CTRLFlow control selection: 0-(Default) No flow control
RTS_ON_DLYRTS delay selection: 0- (Default)

III. Detailed description

Modbus RTU master station programming

1. Modbus RTU master station command Modbus Comm_Load parameter

RESP_TOResponse timeout: Default=1000 ms. The time (in milliseconds) allowed by Modbus_Master for a slave station to respond.
MB_DBReference to the background data block of Modbus_Master or Modbus_Slave instructions. The MB_DB parameter must be linked to the static variable MB_DB parameter in the Modbus_Master or Modbus_Slave instructions.
DONEIf the previous request is completed without errors, the DONE bit will become TRUE and remain so for one cycle.
ERRORIf the previous request is completed with errors, the ERROR bit will become TRUE and remain so for one cycle. The error code in the STATUS parameter is only valid during the cycle when ERROR=TRUE.
STATUSPort configuration error code. Please refer to the online help of TIAPortal software or the S7-1200 system manual.

2.Modbus RTU Master instructions Modbus Master parameters

PinDescription
ENEnable terminal
REQTRUE=request to send data to Modbus Slave. It is recommended to use rising edge triggering
MB_ADDRModbus RTU Slave address. Default address range: 0 to 247; extended address range: up to 65535. The value 0 is reserved for broadcasting messages to all Modbus Slaves
MODEMode selection: Specify the request type (read or write).
DATA ADDRStarting address in the slave: Specify the starting address of the data to be accessed in the Modbus slave.
DATA_LENData length: Specify the number of bits or words to be accessed in this request.
DATA PTRData pointer: Point to the M area or data block address where data writing or reading is to be performed.
DONEDone bit: After the previous request has been completed without error, the DONE bit will remain TRUE for one scan cycle
.
BUSYFALSE - Modbus Master has no active command: TRUE - Modbus Master command is in execution.
ERRORIf the previous request completed with an error, the ERROR bit will become TRUE and remain TRUE for one cycle. The error code in the STATUS parameter is only valid during the cycle when ERROR=TRUE.
STATUSPort configuration error code, please refer to the TIA Portal software online help or the S7-1200 system manual.

3. Relationship between MB MODE, MB DATA ADDR, MB DATA LEN, Modbus RTU function code, etc.

MB_MODEMB_DATA ADDRMB_DATA_LENModbus RTU function codeoperation and data
01-99991-200001read output bits
1-2000 bits per request
010001-199991-200002read input bits
1-2000 bits per request
0.40001-49999 (equivalent to 400001-409999)
.400001-465535
1 - 12503read hold register
1-125 words per request
030001-399991 - 12504Read input words
1-125 words per request
110001 - 19999105Write output bits
1 bit per request
1.40001-49999 (equivalent to 400001-409999)
.400001-465535
106Write to hold register
1 word per request
110001 - 199992 - 196815Write multiple output bits
Each request involves 2-1968 bits
1.40001-49999 (equivalent to 400001-409999
.400001-465535
2-12316Writing to multiple hold registers
Each request involves 2-123 words
210001 - 199991 - 196815Writing to output bits
Each request involves 1-1968 bits
2.40001-49999 (equivalent to 400001-409999
.400001-465535
1 -12316Writing to save registers
Each request involves 1-123 words
1111For details, see below
80108For details, see below
81108For details, see below
1040-655351-12504Read input word
1-125 words per request

11 (Operation and Data): Read server status word and event counter:

1.The status word reflects the processing status (0-unprocessed, 0xFFFFF-in process);

2.When a Modbus request is successfully executed, the event counter will be incremented. If an error occurs when executing a Modbus function, the server will send a message but will not increment the event counter.
80 (Operation and Data): Check server status through diagnostic code 0x0000 (return loop test - server sends back request

1 word per call)
81 (Operation and Data) :Reset the event counter of the server through diagnostic code 0x000A:
Call 1 word at a time

Modbus RTU slave programming

PinDescription
MB ADDRStandard addressing of Modbus slave: Standard addressing range (1 to 247), extended addressing range (0 to 65535)
MB_HOLD_REGData pointer, pointing to the address of the Modbus hold register, which can be either the M memory area or the DB data area
NDRAvailable new data:
>FALSE: No new data.
>TRUE: Indicates that new data has been written by the Modbus master. If the previous request is completed without error, the NDR bit will become TRUE and remain TRUE for one cycle.
DRRead Data:
> FALSE: No new data.
> TRUE: Indicates that the command has stored the data received by the Modbus master in the target area. If the previous request was completed without errors, the DR bit will become TRUE and remain so for one cycle.
ERRORIf the previous request was completed with errors, the ERROR bit will become TRUE and remain so for one cycle. If execution is terminated due to an error, the error code in the STATUS parameter is only valid during the cycle when ERROR=TRUE.
STATUSError Code

2. Modbus RTU Slave Data Area Definition

Address AreaDefinitionDescription
Output BitStarting from Q0.0Q0.0 is address 1, Q0.1 is address 2, Q0.7 is address 8, Q1.0 is address 9
Input bitI0.0 starts withI0.0 as address 10001, I0.1 as address 10002, I0.7 as address 10008, I1.0 as address 10009...
Input registerIW0 starts withIW0 as address 30001, IW2 as address 30002, IW4 as address 30003...
Hold registeris defined by MB_HOLD_REGThe first word pointed by the pointer is 40001, and the second word is 40002.
1. For example, if MB_HOLD_REG is P#M100.0 WORD8, then MW100 is 40001, MW102 is 40002, MW104 is 40003...MW114 is 40008.
2. For example: If MB_HOLD_REG is used to optimize the INT array [0...7] in DB, and the array name is "XXX" AA, then "XXX".AA[0] is 40001, "XXX".AA[1] is 40002, "XXX".AA[2] is 40003, and "XXX".AA[7] is 40008
Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.