In the previous chapter we built Ms. Wang's greenhouse network: the gateway is the master and the three devices are slaves. The question now is: where exactly inside the device is slave 1's "temperature 25.6°C" stored? Where is slave 2's "fan switch"? How does the gateway read them out?
Imagine that every Modbus device contains a row of labelled lockers: some lockers have a single slot that fits exactly one "on/off" note (1 bit); some have two slots and can hold a bigger number (16 bits); some are marked "read-only, don't touch", and some can be read and written freely. Modbus specifies that all devices use the same set of locker specifications—this is its data model.
When working with Modbus devices, 90% of the job is looking up "which address holds which data" in the device manual. Read the wrong locker (type) or the wrong position (address) and at best you get garbage values, at worst you corrupt the device configuration. Once you know these four lockers, every function code is just "which door to open".
| Type | English | Access | Bit width | Typical use | Greenhouse example |
|---|---|---|---|---|---|
| Coil | Coil | Read / Write | 1 bit | Switches, relays, indicator lamps | Exhaust fan switch, pump switch |
| Discrete input | Discrete Input | Read-only | 1 bit | Limit switches, door contacts, buttons | Door/window open-closed state |
| Holding register | Holding Register | Read / Write | 16 bits | Setpoints, analog outputs, configuration | Humidity target, temperature limits |
| Input register | Input Register | Read-only | 16 bits | Measured values, instrument readings | Temperature, humidity, light readings |
Memory aid: coils and holding registers "can be changed"; discrete inputs and input registers "can only be viewed". The 1-bit types represent switches, the 16-bit types represent numbers.
Device manuals often show 5-digit numbers such as 40001 or 30001. These are reference numbers, and the leading digit tells you the type:
0xxxx — coils (e.g. 00001)1xxxx — discrete inputs (e.g. 10001)3xxxx — input registers (e.g. 30001)4xxxx — holding registers (e.g. 40001)But the address actually sent onto the wire counts from 0: reference number 40001 corresponds to link address 0x0000, and 40002 corresponds to 0x0001. The conversion formula is: link address = reference number − 40001 (for holding registers), e.g. 40001 → 0, 40005 → 4 (0x0004).
A 16-bit value occupies 2 bytes. Modbus specifies that the high byte comes first—this is big-endian. In plain terms: announce the "tens" first, then the "ones". For example, 100 is stored as 00 64 (high byte 0x00, low byte 0x64), not 64 00.
The gateway wants to read "temperature" from slave 1 (stored in a holding register; to match what the Lab supports, we use FC 03):
Request—read 1 holding register @0x0000:
01
03
00 00
00 01
84 0A
| Byte | Value | Meaning |
|---|---|---|
| 0 | 01 | Slave 1 |
| 1 | 03 | Function code: Read Holding Registers |
| 2–3 | 00 00 | Starting address |
| 4–5 | 00 01 | Quantity |
| 6–7 | 84 0A | CRC-16 |
Response—the slave returns 2 data bytes 00 64 (100 in decimal):
01
03
02
00 64
B9 AF
| Byte | Value | Meaning |
|---|---|---|
| 0 | 01 | Slave 1 |
| 1 | 03 | Function code echoed |
| 2 | 02 | Byte count = 2 |
| 3–4 | 00 64 | Data (raw integer 100) |
| 5–6 | B9 AF | CRC-16 |
If the device manual says "temperature = raw value × 0.1 °C", then 00 64 = 100 → 100 × 0.1 = 10.0 °C. Note: Modbus only transports raw integers; the decimal point is defined by the device manual, not by the protocol.
What if the temperature has a fractional part and a sign? Industry commonly uses a "scaling factor" (such as ×10 or ×100) to turn decimals into integers; when a larger range or a true floating-point number is needed, two adjacent 16-bit registers are combined into a 32-bit value (high word first). A string is a run of registers, one character per byte. None of these combination rules are defined by Modbus—they are all defined by the device manual. That is exactly why the "register map" exists.
| Slave | Type | Reference number | Link address | Meaning | Conversion |
|---|---|---|---|---|---|
| Slave 1 sensor | Input register | 30001 | 0x0000 | Temperature | ×0.1 °C |
| Slave 1 sensor | Input register | 30002 | 0x0001 | Humidity | ×0.1 % |
| Slave 2 exhaust fan | Coil | 00001 | 0x0000 | Fan switch | 0=off 1=on |
| Slave 2 exhaust fan | Holding register | 40001 | 0x0000 | Speed setpoint | 0–100 % |
| Slave 3 water pump | Coil | 00001 | 0x0000 | Pump switch | 0=off 1=on |
Ms. Wang's gateway polls according to this map: read 30001 for temperature, read 00001 for fan state, write 40001 to set the speed.
A variable frequency drive (VFD) for a motor in a factory also has a register map: holding register 0x0000 = target speed (RPM), input register 0x0000 = present frequency (0.01 Hz). When the host software "reads 40001" and gets 1500, it knows the motor is running toward 1500 RPM—the same routine as the greenhouse's "read 30001 → 10.0 °C": look up the map first, then convert.
A classic beginner mistake: the manual says "40001 is temperature", so they enter address 40001 in the software. The result is either an "illegal data address" exception or reading a completely unrelated register. Remember: 40001 is a reference number; the link address is 0x0000—in software you normally enter 0 or 0x0000.
0x0000, quantity 1;01 03 00 00 00 01 84 0A;2 and watch the request become 01 03 00 00 00 02 C4 0B—read one more register and both the quantity and the CRC change.In this chapter you met Modbus's four "lockers": two 1-bit switches (coils and discrete inputs) and two 16-bit numbers (holding registers and input registers). You also learned how to convert a reference number into a link address, and about big-endian ordering.
Next, we learn how to "open the lockers"—using function codes to tell a slave: read the temperature, turn on the fan, write the setpoint.