Modbus Function Code 6
Write Single Holding Register on Modbus
This function code is used to write a single holding register in a remote device. The Request PDU specifies the address of the register to be written. Registers are addressed starting at zero. Therefore register numbered 1 is addressed as 0.
Request
Function code | 1 Byte | 0x06 |
Register Address | 2 Bytes | 0x0000 to 0xFFFF |
Register Value | 2 Bytes | 0x0000 to 0xFFFF |
Response
The normal response is an echo of the request, returned after the register contents have been written.
Function code | 1 Byte | 0x06 |
Register Address | 2 Bytes | 0x0000 to 0xFFFF |
Register Value | 2 Bytes | 0x0000 to 0xFFFF |
Error
Error code | 1 Byte | 0x86 |
Exception code | 1 Byte | 01 or 02 or 03 or 04 |
Example
Request
This command is writing the contents of analog output holding register # 40005 to the slave device with address 11. Each holding register can store 16 bits.
0B 06 0004 ABCD 7604 |
- 0B: The Slave Address (0B hex = address 11)
- 06: The Function Code 6 (Write Single Holding Register)
- 0004: The Data Address of the register (0004 hex = 4, + 40001 offset = register #40005).
- ABCD: The value to write.
- 7604: The CRC (Cyclic Redundancy Check) for error checking.
Response
The normal response is an echo of the query, returned after the register contents have been written.
0B 06 0004 ABCD 7604 |
- 0B: The Slave Address (0B hex = address 11)
- 06: The Function Code 6 (Write Single Holding Register)
- 0004: The Data Address of the register (0004 hex = 4, + 40001 offset = register #40005).
- ABCD: The value written.
- 7604: The CRC (Cyclic Redundancy Check) for error checking.
Workflow Diagram for Modbus FC 6
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