06 — READING REGISTERS (FC3)

16-bit registers travel big-endian. The eternal gotcha.

Estimated 7 minutes.

FC3 reads 16-bit registers.

Function code 3 reads holding registers. Each register is 16 bits = 2 bytes, so a 10-register read returns 20 bytes of data behind the byte count.

The request.

Function + start address + quantity. The quantity tops out at 125 (250 bytes fits in the 252-byte data ceiling).

The response — byte count, then registers.

The slave answers with the function code, a byte count = qty × 2, and then the register data. Walk the bytes in pairs, high byte then low byte, and reassemble each register.

The response.

Reading 3 registers → 6 data bytes. Pairs are (HI, LO).

Each register is big-endian.

Within a single register: HIGH byte first, LOW byte second. The value 0x1234 goes on the wire as byte 0 = 0x12, byte 1 = 0x34. This is the opposite of x86 memory order and trips up almost everyone.

Big-endian, byte by byte.

Value 0x1234 → byte 0 = 0x12 (high), byte 1 = 0x34 (low).

Big-endian builder.

Type two hex bytes; the panel shows the assembled 16-bit value. Goal: produce 0xCAFE.

Multi-register values are an extra layer of trouble.

A 32-bit float across two registers can be sent four different ways (HI-LO HI-LO, HI-LO LO-HI, LO-HI HI-LO, LO-HI LO-HI). Modbus has no opinion. Vendors do, and they disagree.

You read 0xCAFE — which byte is high?

A register holds 0xCAFE. Which byte goes first on the wire?

  • 0xCA
  • 0xFE

Sanity check with 0x1234.

When a 32-bit value crosses two registers and the vendor docs are silent, send a known value like 0x12345678 from a tool you trust and inspect the bytes on the receiving side. The pattern tells you which of the 4 orderings the device uses.

You can decode an FC3 response.

  • FC3 reads up to 125 registers per request.
  • Response data = qty × 2 bytes.
  • Each register is big-endian: HIGH byte first.
  • Multi-register values have 4 possible orderings — check the vendor doc.

Lesson 06 complete.

  • You can decode any FC3 response into 16-bit values.
  • You can spot big-endian byte order on the wire.
  • You know how to figure out multi-register endianness when docs are silent.