New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Modbus register addressing: offsets, function codes and 32-bit floats

Why register 1 is sent as address 0, which function codes read and write each table, and how to find a float’s word order from one known reading.

Modbus register addressing has two numbering schemes. The specification’s data model numbers the registers of each table from 1, while the request on the wire carries an address from 0. Register number X is sent as address X-1, so holding register 1 is address 0, and a register map may use either scheme.

Most of my Modbus work is meters and controllers at pump stations and grid sites. When a read returns an error or nonsense, I check two things first: the off-by-one and the word order.

Modbus register address vs register number: what is the difference?

The register number is what the manual shows; the address is what goes into the request. The Modbus Application Protocol Specification V1.1b3 numbers the elements of each data block from 1 to n, addresses them from 0 to 65535 in the request, and says data numbered X is addressed as X-1.

The specification’s own example reads registers 108 to 110 with a starting address of 0x006B, which is 107. Some manuals also write numbers such as 40001. The specification defines no such numbers: a request carries a function code, which names the table, and an address from 0 to 65535. Take their meaning from the manual’s own notes.

TableObjectAccessReadWrite
Coils1 bitRead-write0105, 15
Discrete inputs1 bitRead-only02none
Input registers16-bit wordRead-only04none
Holding registers16-bit wordRead-write0306, 16

Can you write to an input register?

No. The specification defines input registers as read-only 16-bit words; writes go to holding registers, with function 06 for one register or 16 for a block.

Ask for an address the device does not have and it answers with exception code 02, Illegal Data Address, under the request’s function code plus 0x80: 0x83, or 131, for a holding register read. The specification’s example is a device with 100 registers, addresses 0 to 99: a read of 4 registers from address 96 works, a read of 5 fails, because address 100 does not exist.

How do you read a 32-bit float from two Modbus registers?

Read two consecutive registers and join their four bytes into an IEEE 754 single-precision float. The specification defines only 16-bit registers, sent big-endian with the most significant byte first, so it does not say which of the two registers holds the high half of a 32-bit value. Each manufacturer decides.

Label the float’s bytes A to D, most significant first, and the four possible orders are ABCD, CDAB, BADC and DCBA.

How do you find a device’s word order and byte swap?

Use one reading you already know instead of trying orders at random:

  1. Pick a value you can see elsewhere, such as the voltage on the meter’s own display: 230.5 V.
  2. Read the two registers raw, in hex.
  3. Join them in the order received and decode the float.
  4. If that is nonsense, swap the two registers and decode again; if it is still wrong, swap the bytes inside each register, with and without the register swap.

230.5 as a float is 0x43668000. A device that sends the low word first returns 0x8000, then 0x4366. Joined as received, that decodes to about -2.4 × 10^-41; swapped, it is 230.5. I note the order once per device model, next to the register map, because every meter of that model will need it. A gateway then sends the decoded value on, over the protocols compared in MQTT vs HTTP for IoT devices, as in energy meter reading across sites.

Frequently asked questions

How many registers can one Modbus request read?

Read Holding Registers (03) and Read Input Registers (04) take 1 to 125 registers per request, and Write Multiple Registers (16) writes 1 to 123. For a longer register map, split the reads into blocks and make sure no block runs past the last address the device has.

Can the same value appear in more than one Modbus table?

Yes. The specification says it is acceptable, and very common, for the four tables to overlay one another on the target device. On such a device the same value can answer to function 03 and 04, so go by the register map.

Why do two devices put the same quantity at different addresses?

Because the specification leaves it to them. It defines the four tables and their addressing, but says the mapping between the Modbus data model and the device’s own application is entirely vendor and device specific. The device’s register map is the only reliable source.

Share

See your field data live this week

Start a trial in your region with your first devices, or book a demo and bring your own use case.