I. Usage of Modbus RTU Commands

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
| Pin | Description |
| REQ | Rising edge trigger |
| PORT | Hardware identifier of communication port |
| BAUD | Baud rate selection: 3600, 6000, 12000, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200 |
| PARITY | Parity check selection: 0-None; 1-Odd parity; 2-Even parity |
| FLOW_CTRL | Flow control selection: 0-(Default) No flow control |
| RTS_ON_DLY | RTS delay selection: 0- (Default) |
III. Detailed description
Modbus RTU master station programming
1. Modbus RTU master station command Modbus Comm_Load parameter
| RESP_TO | Response timeout: Default=1000 ms. The time (in milliseconds) allowed by Modbus_Master for a slave station to respond. |
| MB_DB | Reference 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. |
| DONE | If the previous request is completed without errors, the DONE bit will become TRUE and remain so for one cycle. |
| ERROR | If 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. |
| STATUS | Port 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
| Pin | Description |
| EN | Enable terminal |
| REQ | TRUE=request to send data to Modbus Slave. It is recommended to use rising edge triggering |
| MB_ADDR | Modbus 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 |
| MODE | Mode selection: Specify the request type (read or write). |
| DATA ADDR | Starting address in the slave: Specify the starting address of the data to be accessed in the Modbus slave. |
| DATA_LEN | Data length: Specify the number of bits or words to be accessed in this request. |
| DATA PTR | Data pointer: Point to the M area or data block address where data writing or reading is to be performed. |
| DONE | Done bit: After the previous request has been completed without error, the DONE bit will remain TRUE for one scan cycle . |
| BUSY | FALSE - Modbus Master has no active command: TRUE - Modbus Master command is in execution. |
| ERROR | If 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. |
| STATUS | Port 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_MODE | MB_DATA ADDR | MB_DATA_LEN | Modbus RTU function code | operation and data |
| 0 | 1-9999 | 1-2000 | 01 | read output bits 1-2000 bits per request |
| 0 | 10001-19999 | 1-2000 | 02 | read input bits 1-2000 bits per request |
| 0 | .40001-49999 (equivalent to 400001-409999) .400001-465535 | 1 - 125 | 03 | read hold register 1-125 words per request |
| 0 | 30001-39999 | 1 - 125 | 04 | Read input words 1-125 words per request |
| 1 | 10001 - 19999 | 1 | 05 | Write output bits 1 bit per request |
| 1 | .40001-49999 (equivalent to 400001-409999) .400001-465535 | 1 | 06 | Write to hold register 1 word per request |
| 1 | 10001 - 19999 | 2 - 1968 | 15 | Write multiple output bits Each request involves 2-1968 bits |
| 1 | .40001-49999 (equivalent to 400001-409999 .400001-465535 | 2-123 | 16 | Writing to multiple hold registers Each request involves 2-123 words |
| 2 | 10001 - 19999 | 1 - 1968 | 15 | Writing to output bits Each request involves 1-1968 bits |
| 2 | .40001-49999 (equivalent to 400001-409999 .400001-465535 | 1 -123 | 16 | Writing to save registers Each request involves 1-123 words |
| 11 | 11 | For details, see below | ||
| 80 | 1 | 08 | For details, see below | |
| 81 | 1 | 08 | For details, see below | |
| 104 | 0-65535 | 1-125 | 04 | Read 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
| Pin | Description |
| MB ADDR | Standard addressing of Modbus slave: Standard addressing range (1 to 247), extended addressing range (0 to 65535) |
| MB_HOLD_REG | Data pointer, pointing to the address of the Modbus hold register, which can be either the M memory area or the DB data area |
| NDR | Available 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. |
| DR | Read 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. |
| ERROR | If 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. |
| STATUS | Error Code |
2. Modbus RTU Slave Data Area Definition
| Address Area | Definition | Description |
| Output Bit | Starting from Q0.0 | Q0.0 is address 1, Q0.1 is address 2, Q0.7 is address 8, Q1.0 is address 9 |
| Input bit | I0.0 starts with | I0.0 as address 10001, I0.1 as address 10002, I0.7 as address 10008, I1.0 as address 10009... |
| Input register | IW0 starts with | IW0 as address 30001, IW2 as address 30002, IW4 as address 30003... |
| Hold register | is defined by MB_HOLD_REG | The 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 |
Leave a Reply