
Four kinds of data
A Modbus server keeps its data in four tables, coils, discrete inputs, input registers and holding registers. Two hold single bits and two hold 16-bit values, and which of them a request can write depends on the table, not on the server.
Four tables
A function code picks the table and an address picks the place in it. The tables differ in how wide an item is and whether a request may write it.
| Table | Item | Read | Write |
|---|---|---|---|
| Coils | 1 bit | 01 | 05, 15 |
| Discrete inputs | 1 bit, read only | 02 | none |
| Input registers | 16 bits, read only | 04 | none |
| Holding registers | 16 bits | 03 | 06, 16 |
A coil is something to switch, such as a relay. A discrete input is a bit the outside world sets, such as a switch on a wire. An input register is a value the server reports, often a measurement. A holding register is a value you read and set, such as a setting.
Function codes are decimal here: 15 is 0F and 16 is 10 in a frame.
Nothing writes a read only table
No function writes an input register or a discrete input, so a request cannot reach them.
A register is 16 bits, high byte first
Modbus sends data big-endian. The value 1000 is 0x03E8 and goes out as 03 E8. The check value is the one exception, low byte first.
Anything bigger is a convention
The protocol knows single bits and 16-bit words, and not what any value means. A 32-bit number takes two registers, a decimal is often a scaled integer or a float in two registers, and which register comes first is the device maker's choice. Devices differ, and the manual is the only source.
The tables may overlay
Nothing says the four tables are separate memory. A coil and a bit of a register may be the same bit. The specification calls that acceptable and very common, and the manual says whether a device does it.
Common mistakes
- Writing to an input register. It is read only and no function reaches it. Look for the holding register that holds the setting.
- Assuming a 32-bit value is built the same on every device. Test with a known value, and swap the two registers if the number is wrong by a huge factor.
- Treating the tables as separate memory. On some devices writing a coil changes a register.
Edit this page — content/fundamentals/rs485-modbus/four-kinds-of-data.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.