Almost every "Illegal Data Address" exception traces back to this: the number in the documentation is not the number on the wire.
Modbus has two parallel numbering systems, and they have coexisted for forty years because both are useful. Confusing them is the single most common beginner error in the protocol.
Protocol (PDU) addresses are what actually travel in the frame. They are zero-based and range from 0 to 65535.
Convention (documentation) addresses are what device manuals print. They are one-based and carry a prefix digit that identifies the register table.
| Table | Convention range | Prefix | Example |
|---|---|---|---|
| Coils (read/write bits) | 00001–09999 | 0 | 00001 = first coil |
| Discrete inputs (read-only bits) | 10001–19999 | 1 | 10001 = first discrete input |
| Input registers (read-only 16-bit) | 30001–39999 | 3 | 30001 = first input register |
| Holding registers (read/write 16-bit) | 40001–49999 | 4 | 40001 = first holding register |
The prefix is metadata, not arithmetic. 40001 is not a large number you send to the device — it says "holding register, first one".
Strip the prefix digit, then subtract one:
40001 -> drop '4' -> 001 -> minus 1 -> 0
40011 -> drop '4' -> 011 -> minus 1 -> 10
40108 -> drop '4' -> 108 -> minus 1 -> 107
30001 -> drop '3' -> 001 -> minus 1 -> 0
00001 -> drop '0' -> 001 -> minus 1 -> 0
10001 -> drop '1' -> 001 -> minus 1 -> 0
So a datasheet entry that reads "Holding Register 40011: Setpoint" means PDU address 10, function code 03 to read or 06 to write.
Send 40011 instead and you will get exception 0x02 — assuming the device even has that many registers, which it usually does not.
Three reasons, all legitimate:
4xxxx genuinely was a memory area label. Vendors kept printing it because field technicians recognise it.400001–465536. Same idea: drop the leading 4, subtract one, and you land in 0–65535. Do not confuse 400001 with the five-digit 40001 — they are different registers.Suppose you need the value at "40011" and you get 0x02.
Step 1: read address 0, quantity 1 -> success? table & function code are right.
Step 2: read address 10, quantity 1 -> success? your conversion is right.
Step 3: read address 11, quantity 1 -> success? the datasheet is 0-based, use 10 going forward.
Step 4: read address 40011 -> normally fails; confirms you were off by 40001.
Step 1 is the one people skip. It separates "wrong address" from "wrong function code or wrong table" in a single request. If reading address 0 fails, the problem is not your offset — the device may not implement function code 03 at all, or you are talking to the wrong slave ID.
The address prefix and the function code are two statements of the same fact. Mismatching them produces 0x02 even when the address arithmetic is perfect:
| You want | Function code | Address prefix |
|---|---|---|
| Read coils | 01 | 0xxxx |
| Read discrete inputs | 02 | 1xxxx |
| Read holding registers | 03 | 4xxxx |
| Read input registers | 04 | 3xxxx |
| Write single coil | 05 | 0xxxx |
| Write single register | 06 | 4xxxx |
| Write multiple coils | 15 (0x0F) | 0xxxx |
| Write multiple registers | 16 (0x10) | 4xxxx |
Reading a 3xxxx input register with function 03 is a common slip: 03 reads holding registers only. Input registers need 04, and they are read-only — attempting to write them returns 0x01 (Illegal Function), not 0x02.
datasheet address → PDU address → function code in the project notes. Every future debug session gets faster.int32 occupies two consecutive registers. If the datasheet says 40011 is a float, you need addresses 10 and 11, and you must confirm word order (big-endian versus word-swapped) separately. Wrong word order gives a perfectly valid number that is simply nonsense.You can test the whole conversion chain without hardware: the ModbusLab TCP slave exposes known register values on port 502, and the message lab shows you the exact address bytes your frame is carrying.