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 code1 Byte0x06
Register Address2 Bytes0x0000 to 0xFFFF
Register Value2 Bytes0x0000 to 0xFFFF
Table 1 - Command structure

Response

The normal response is an echo of the request, returned after the register contents have been written.

Function code1 Byte0x06
Register Address2 Bytes0x0000 to 0xFFFF
Register Value2 Bytes0x0000 to 0xFFFF
Table 2 - Response structure

Error

Error code1 Byte0x86
Exception code1 Byte01 or 02 or 03 or 04
Table 3 - Error structure. Scroll below for details.

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

write single holding register
Figure 1 - Write Single Holding Register

Contents retrieved from

  • http://modbus.org/
  • http://www.simplymodbus.ca/

More information