Modbus Function Code 16
Write Multiple Holding Registers on Modbus
This function code is used to write a block of contiguous registers (1 to 123 registers) in a remote device. The requested written values are specified in the request data field. Data is packed as two bytes per register.
Request
Function code | 1 Byte | 0x10 |
Starting Address | 2 Bytes | 0x0000 to 0xFFFF |
Quantity of Registers | 2 Bytes | 0x0001 to 0x007B |
Byte Count | 1 Byte | 2 x N* |
Registers Value | N* x 2 Bytes | value |
Table 1 - Command structure
Response
The normal response returns the function code, starting address, and quantity of registers written.
Function code | 1 Byte | 0x10 |
Starting Address | 2 Bytes | 0x0000 to 0xFFFF |
Quantity of Registers | 2 Bytes | 1 to 123 (0x7B) |
Error
Error code | 1 Byte | 0x90 |
Exception code | 1 Byte | 01 or 02 or 03 or 04 |
Example
Request
This command is writing the contents of two analog output holding registers # 40019 & 40020 to the slave device with address 11. Each holding register can store 16 bits.
0B 10 0012 0002 04 0B0A C102 A0D5 |
- 0B: The Slave Address (0B hex = address 11)
- 10: The Function Code 16 (Write Multiple Holding Registers, 16 = 10 hex)
- 0012: The Data Address of the first register (0012 hex = 18, +40001 offset = register #40019).
- 0002: The number of registers to write.
- 04: The number of data bytes to follow (2 registers x 2 bytes each = 4 bytes).
- 0B0A: The value to write to register 40019
- C102: The value to write to register 40020
- A0D5: The CRC (Cyclic Redundancy Check) for error checking.
Response
0B 10 0012 0002 E167 |
- 0B: The Slave Address (0B hex = address 11)
- 10: The Function Code 16 (Write Multiple Holding Registers, 10 hex - 16)
- 0012: The Data Address of the first register (# 40019 - 40001 = 18 (0012 hex) ).
- 0002: The number of registers written.
- E167: The CRC (Cyclic Redundancy Check) for error checking.
Workflow Diagram for Modbus FC 16
Contents retrieved from
- http://modbus.org/
- http://www.simplymodbus.ca/
More information
- Modbus Function Codes
- Mobdbus function code 1 - read coils
- Mobdbus function code 2 - read discrete inputs
- Mobdbus function code 3 - read multiple holding registers
- Mobdbus function code 4 - read input registers
- Mobdbus function code 5 - write single coil
- Mobdbus function code 6 - write single holding register
- Mobdbus function code 15 - write multiple coils
- Mobdbus function code 16 - write multiple holding registers
- Modbus References
- Modbus protocol basics