Modbus RTU and TCP: registers, functions and common errors

Modbus data areas, framing, addressing, serial timing and security without confusing physical and protocol limits.
Modbus RTU and TCP: registers, functions and common errors

AI-generated illustration — example setting.

Request–response communication

Modbus was developed by Modicon in 1979 and is widely used with controllers, meters and drives. A client issues a request and a server responds. Serial Modbus normally has one master; the base protocol has no general unsolicited-event mechanism. A device may expose its own event log through registers.

Data and functions

Coils and discrete inputs are one-bit areas. Holding and input registers contain 16-bit values; bytes within a register are sent most significant first. The base protocol does not define every instrument's register map. Device documentation, or an additional model such as SunSpec, supplies the meaning.

Functions 01/02 read up to 2000 bits; 03/04 read up to 125 registers. Functions 05/06 write one coil/register. Function 15 writes up to 1968 coils and 16 up to 123 registers. A device may implement lower limits. Identification and diagnostic functions exist, but are not a universal discovery service.

RTU, ASCII and TCP framing

A Modbus PDU contains a function code and data, with a maximum PDU length of 253 bytes. RTU adds a serial address and CRC-16. ASCII uses hexadecimal characters, delimiters and LRC. TCP adds the seven-byte MBAP header: Transaction ID, Protocol ID, Length and Unit ID; it does not append the RTU CRC.

Serial addresses 1–247 identify servers; address 0 is broadcast with no response. These serial rules must not be applied indiscriminately to all TCP Unit IDs. TCP normally uses port 502; Unit ID is particularly important for gateways.

Serial timing and the physical line

At lower rates, RTU frames are separated by at least 3.5 character times and an internal gap exceeding 1.5 character times invalidates the frame. Above 19,200 bit/s the guide recommends fixed 1.75 ms and 750 μs intervals. Serial parameters must match; the guide uses even parity by default, or two stop bits without parity.

RS-485 traditionally supports 32 unit loads, not a universal limit of 32 devices. Reduced-load transceivers may allow more. Cable length, termination, stubs and loading are distinct from Modbus's 247 individual serial addresses.

Addresses, number formats and errors

A documented reference such as 40001 commonly means holding-register offset 0 in the PDU. Check whether the tool expects a reference number or zero-based offset. A 32-bit value occupies two registers; their word order is defined by the device map, not the base protocol. Check signedness, scale and nonstandard byte rearrangements.

An exception sets the function's high bit and returns a code, for example 01 illegal function, 02 illegal address, 03 illegal value, 04 server failure, 06 busy or 0A/0B gateway errors. No reply may instead indicate an address, serial, wiring or timeout problem.

Security and system integration

Classic RTU/TCP has no built-in cryptographic authentication or encryption. Devices and gateways can still restrict writable functions or addresses. Modbus Security adds TLS and X.509 credentials on port 802 when both peers support it. Segmentation, access restrictions and appropriate secure tunnels remain useful.

Modbus is effective for documented field-device exchange. BACnet or other protocols can be better suited to richer building functions. Device timestamps and logs may be available through registers, but they are not a universal base Modbus event model.

Sources and further reading

Rate this article

Choose from 1 to 5 stars