Modbus Function Code 06 (Write Single Register): Protocol Specification & Hex Analysis
In industrial automation, programmable logic controllers (PLCs), variable frequency drives (VFDs), PID controllers, and SCADA telemetry systems rely continuously on holding registers to store operational setpoints, configuration thresholds, and control parameters. Modbus Function Code 06 (0x06 / Write Single Register) is the fundamental command defined in the Modbus Application Protocol Specification V1.1b3 to update a single 16-bit word in a remote slave device.
Whether you are testing PLC register writes over serial RS-485 Modbus RTU or debugging high-speed industrial Ethernet packets over Modbus TCP port 502, understanding the request/response byte layouts, zero-based wire addressing, and exception handling of Function Code 06 is essential for robust industrial software design.
The Modbus Register Model: Where Does FC06 Fit?
Modbus memory architecture organizes data into four distinct, standardized tables. Function Code 06 operates exclusively on the read/write 16-bit Holding Registers:
| Table Type | Object Type | Access | PLC Address Range | Read Function Code | Write Function Code |
|---|---|---|---|---|---|
| Discrete Outputs (Coils) | 1-bit discrete | Read / Write | 00001 – 09999 | FC01 (Read Coils) | FC05, FC15 |
| Discrete Inputs | 1-bit discrete | Read-Only | 10001 – 19999 | FC02 (Read Discrete Inputs) | None (Read-Only) |
| Input Registers | 16-bit word | Read-Only | 30001 – 39999 | FC04 (Read Input Registers) | None (Read-Only) |
| Holding Registers | 16-bit word | Read / Write | 40001 – 49999 | FC03 (Read Holding Registers) | FC06 (Write Single), FC16 (Write Multiple) |
Protocol Data Unit (PDU) Specification
The Modbus Protocol Data Unit (PDU) is independent of the underlying communication layer (serial RTU, ASCII, or Ethernet TCP). The PDU defines the core command and payload structure.
1. Function Code 06 Request PDU
The master requests the slave to store a 16-bit value into a designated holding register:
- Function Code: 1 byte (
0x06) - Register Address: 2 bytes (
0x0000to0xFFFF, 16-bit zero-based wire offset) - Register Value: 2 bytes (
0x0000to0xFFFF, the 16-bit integer to write)
Total Request PDU Size: 5 bytes.
2. Function Code 06 Normal Response PDU
Upon successful write execution, the slave device returns an exact echo of the request PDU:
- Function Code: 1 byte (
0x06) - Register Address: 2 bytes (the address that was written)
- Register Value: 2 bytes (the value that was stored)
Total Response PDU Size: 5 bytes.
Why Does the Normal Response Echo the Request?
Unlike read function codes (FC01, FC02, FC03, FC04) which return a byte count followed by data, write functions (FC05 and FC06) return an exact echo. This provides immediate, zero-overhead verification to the master that the target address and written word were parsed and committed without bit-level distortion.
PLC Addressing vs. Zero-Based Wire Addressing
One of the most frequent sources of communication errors in industrial commissioning is the offset between 1-based PLC documentation addresses and 0-based protocol wire addresses:
- Documentation Addressing (1-based): Modicon PLC documentation assigns the prefix
4to holding registers, numbering them from40001to49999(or400001to465536in extended 6-digit notation). - Wire Addressing (0-based): In the transmitted binary PDU, register addresses start at
0x0000. Register40001corresponds to wire address0x0000. Register40010corresponds to0x0009. Register40108corresponds to0x006B(107 decimal).
Hex Frame Breakdown: Modbus RTU vs. Modbus TCP
Scenario: Writing Value 1,234 (0x04D2) to Holding Register 40001
In this scenario, a supervisory client writes the integer value 1234 (hex 0x04D2) into Holding Register 40001 (wire address 0x0000) on Slave ID 1.
Modbus RTU Serial Frame Analysis
// Modbus RTU Request Frame (8 Bytes)
[01] [06] [00] [00] [04] [D2] [6A] [68]
| | | | | | | |
| | +-----+ +-----+ +-----+
| | Register Register CRC-16
| | Address Value (Low/High)
| | (0x0000) (0x04D2) (0x686A)
| +-- Function Code (0x06)
+-------- Slave Address (0x01)
// Modbus RTU Normal Response Frame (8 Bytes — Exact Echo)
[01] [06] [00] [00] [04] [D2] [6A] [68]
Modbus TCP Ethernet Frame Analysis
In Modbus TCP, the frame is encapsulated with a 7-byte Modbus Application Protocol (MBAP) header instead of a CRC:
// Modbus TCP Request Frame (12 Bytes)
[00 01] [00 00] [00 06] [01] [06] [00 00] [04 D2]
| | | | | | |
| | | | | | +-- Register Value (0x04D2 = 1234)
| | | | | +---------- Register Address (0x0000 = 40001)
| | | | +---------------- Function Code (0x06)
| | | +--------------------- Unit ID / Slave ID (0x01)
| | +---------------------------- Length Field (0x0006 = 6 remaining bytes)
| +------------------------------------ Protocol ID (0x0000 = Modbus)
+-------------------------------------------- Transaction ID (0x0001)
// Modbus TCP Normal Response Frame (12 Bytes — Exact Echo of PDU)
[00 01] [00 00] [00 06] [01] [06] [00 00] [04 D2]
Modbus Exception Codes with Function Code 06
If the slave device cannot successfully complete the write command, it sets the highest-order bit of the function code (0x06 | 0x80 = 0x86) and returns an exception response containing an error code:
| Exception Code | Name | Root Cause in FC06 | Troubleshooting & Fix |
|---|---|---|---|
| 01 (0x01) | Illegal Function | The slave device firmware does not implement Function Code 06, or writes to holding registers are disabled. | Verify if the device only accepts Function Code 16 (Write Multiple Registers). Many modern PLCs require FC16 even when writing a single register. |
| 02 (0x02) | Illegal Data Address | The requested register address does not exist in the slave device's allocated memory map. | Check device documentation for 1-based vs 0-based offset. Verify that the register address is within the valid holding register range. |
| 03 (0x03) | Illegal Data Value | The 16-bit value written is outside the permissible configuration limits for this specific register. | Verify parameter boundaries (e.g., trying to write 120Hz to a VFD with a maximum frequency setting of 60Hz). |
| 04 (0x04) | Slave Device Failure | An unrecoverable internal hardware error occurred while the slave attempted to store the value into non-volatile EEPROM/Flash. | Inspect slave power supply, EEPROM write cycle health, and device diagnostics. |
Writing Registers with Python (pymodbus)
Automating register writes is straightforward using Python and the pymodbus library. The following script connects to a Modbus TCP server (or ModbusSimulator) and writes a single holding register:
from pymodbus.client import ModbusTcpClient
def write_single_setpoint():
# Connect to Modbus TCP Server on Port 502
client = ModbusTcpClient('127.0.0.1', port=502)
client.connect()
target_address = 0 # Holding Register 40001 (0-based wire offset)
setpoint_value = 1234 # 16-bit integer value
print(f"Writing value {setpoint_value} to register offset {target_address}...")
# Execute Function Code 06 (Write Single Register)
result = client.write_register(address=target_address, value=setpoint_value, slave=1)
if result.isError():
print(f"[-] Write failed with Modbus Exception: {result}")
else:
print(f"[+] Write successful! Slave echoed: register={target_address}, value={setpoint_value}")
client.close()
if __name__ == "__main__":
write_single_setpoint()
Simulating Function Code 06 in ModbusSimulator
Testing write commands against live production machinery carries real risks: an incorrect register offset could change a motor speed limit, open a chemical valve, or trip an emergency interlock. ModbusSimulator allows engineers to test FC06 logic completely in software:
- Interactive Register Grid: View 4xxxx holding registers in real time. When an external SCADA or Python client executes FC06, the grid updates dynamically with visual value change indicators.
- Data Type Formatting: Switch seamlessly between Signed INT16, Unsigned UINT16, Hexadecimal, Binary, and Scaled Engineering Units.
- Protocol Sniffer & Hex Inspector: Inspect full RTU CRC and TCP MBAP request and response frames with millisecond timestamps.
- Simulate Custom Exceptions: Configure read-only register zones or value range constraints to test how your supervisory control client handles Exception Codes 02 and 03.
Test Your Modbus Systems Today
Download ModbusSimulator to simulate virtual Modbus RTU and TCP slaves, script register and coil values, and debug PLC networks without hardware.
Download ModbusSimulator Free →Frequently Asked Questions (FAQs)
What is Modbus Function Code 06?
Modbus Function Code 06 (0x06 / Write Single Register) is the standard command used by a master/client to write a 16-bit word value (0x0000 to 0xFFFF) into a single holding register (4xxxx) on a remote slave/server.
What is the normal response to a Function Code 06 request?
The normal response from the slave is an exact byte-for-byte echo of the request PDU: the function code (0x06), the 2-byte register address, and the 2-byte register value written.
What is the difference between address 40001 and wire address 0x0000?
Address 40001 is the 1-based human documentation address. The physical communication frame transmits a zero-based offset, so 40001 is transmitted on the wire as 0x0000.
What is the difference between Function Code 06 and Function Code 16 (0x10)?
Function Code 06 writes exactly one single 16-bit register. Function Code 16 (Write Multiple Registers) writes a contiguous block of between 1 and 123 registers in a single request frame.
How does Function Code 06 handle signed integers and negative numbers?
Modbus transmits all register values as 16-bit words using two's complement binary format. For example, -10 is transmitted as 0xFFF6. Interpretation as signed or unsigned is determined by the client application.
Can Function Code 06 write to Input Registers?
No. Input Registers (3xxxx) are read-only analog inputs. FC06 can only write to Holding Registers (4xxxx).
What causes Modbus Exception Code 03 with Function Code 06?
Exception Code 03 (Illegal Data Value) indicates that the 16-bit value written is outside the acceptable operational bounds defined by the slave firmware for that specific parameter.