Guides › What Is Modbus? RTU and TCP Frames, Function Codes, Registers
What Is Modbus? RTU and TCP Frames, Function Codes, Registers
Modbus is a communication protocol that lets industrial devices such as PLCs, drives, power meters, temperature controllers and sensors exchange data. Modicon (now Schneider Electric) created it in 1979 for its PLCs. Because the specification is open and the protocol is simple, it is still the most widely used industrial protocol. The Modbus Organization maintains the current specification.
Master and slave
Modbus is a request/response protocol. The side that asks is the master (client); the side that answers is the slave (server). A slave never sends data on its own; it only replies to requests. A typical setup is a PLC or HMI polling several temperature controllers one after another.
- Serial slave addresses: 1 to 247 (0 is broadcast, with no reply)
- One master per bus; the master waits for a reply before sending the next request.
Modbus variants
| Variant | Medium | Encoding | Error check | Notes |
|---|---|---|---|---|
| Modbus RTU | RS-485 / RS-232 | Binary bytes | CRC-16 | Most common, efficient |
| Modbus ASCII | RS-485 / RS-232 | Hex characters (starts with a colon, ends with CR LF) | LRC | Human-readable but twice as long; rarely used |
| Modbus TCP | Ethernet (TCP port 502) | Binary + MBAP header | None (TCP handles it) | Growing in new installations |
Data model: coils and registers
| Table | Size | Access | Traditional notation | Example |
|---|---|---|---|---|
| Coil | 1 bit | Read/write | 0xxxx (00001+) | Relay output, run/stop command |
| Discrete Input | 1 bit | Read only | 1xxxx (10001+) | Limit switch, alarm contact |
| Input Register | 16 bits | Read only | 3xxxx (30001+) | Measurements (temperature, current) |
| Holding Register | 16 bits | Read/write | 4xxxx (40001+) | Setpoints, parameters |
Watch the address offset: register "40001" in a manual is sent as 0x0000 in the frame. Protocol addresses start at 0. Mixing up 0-based and 1-based numbering, and reading every value one register off, is the most common field problem.
Modbus RTU frame
| Slave address | Function code | Data | CRC |
|---|---|---|---|
| 1 byte | 1 byte | 0 to 252 bytes | 2 bytes (low byte first) |
RTU has no start or end characters. Frames are separated by a silent interval of at least 3.5 character times: about 4 ms at 9600 bps (one 11-bit character is about 1.15 ms). Above 19200 bps the interval is fixed at 1.75 ms. A gap of more than 1.5 character times inside a frame makes the receiver discard it.
Request and response example (function 03)
Read 10 holding registers starting at 40001 from slave 1:
Request: 01 03 00 00 00 0A C5 CD
| | [start] [count=10] [CRC 0xCDC5, low byte first]
| function 03
slave address 1
Response: 01 03 14 [20 data bytes] [2 CRC bytes]
(byte count 0x14 = 10 registers x 2 bytes)
Write the value 3 to register 40002 (protocol address 1) of slave 1 with function 06: 01 06 00 01 00 03 98 0B. On success the device echoes the same frame back.
Common function codes
| Code | Name | Description |
|---|---|---|
| 01 (0x01) | Read Coils | Up to 2000 coils |
| 02 (0x02) | Read Discrete Inputs | Up to 2000 inputs |
| 03 (0x03) | Read Holding Registers | Up to 125 registers; the most used function |
| 04 (0x04) | Read Input Registers | Up to 125 registers |
| 05 (0x05) | Write Single Coil | ON = FF 00, OFF = 00 00 |
| 06 (0x06) | Write Single Register | One register |
| 15 (0x0F) | Write Multiple Coils | Several coils |
| 16 (0x10) | Write Multiple Registers | Up to 123 registers |
| 23 (0x17) | Read/Write Multiple Registers | Write and read in one transaction |
| 43/14 (0x2B/0x0E) | Read Device Identification | Vendor name, product code |
Exception responses
If a slave cannot process a request, it returns the function code plus 0x80 and an exception code. Example: a failed function 03 request returns 01 83 02 ....
| Code | Name | Typical cause |
|---|---|---|
| 01 | Illegal Function | Function code not supported by the device |
| 02 | Illegal Data Address | Address does not exist, 0/1 offset mix-up, count runs past the end |
| 03 | Illegal Data Value | Value out of range, bad count field |
| 04 | Server Device Failure | Internal device error |
| 05 | Acknowledge | Long-running command accepted |
| 06 | Server Device Busy | Device busy; retry later |
| 0A | Gateway Path Unavailable | Gateway misconfigured |
| 0B | Gateway Target Failed to Respond | Device behind the gateway is not answering |
No reply at all (a timeout) is not an exception. Check wiring, baud rate, parity, slave address and CRC byte order first.
Modbus TCP frame (MBAP header)
| Transaction ID | Protocol ID | Length | Unit ID | Function + data |
|---|---|---|---|---|
| 2 bytes | 2 bytes (always 0) | 2 bytes (bytes that follow) | 1 byte | Same as RTU |
The RTU example above becomes 00 01 00 00 00 06 01 03 00 00 00 0A over TCP. The MBAP header replaces the CRC, and the Unit ID addresses a serial device behind a TCP-to-RTU gateway.
32-bit values and byte order
Registers are 16 bits, so 32-bit integers and IEEE 754 floats span two registers. Each register is big-endian, but the order of the two registers varies by vendor. The float 25.5 is 41 CC 00 00; depending on the device it arrives as 41CC 0000 (ABCD) or 0000 41CC (CDAB, word-swapped). If a value looks absurdly large or small, try swapping the words.
Integer registers often carry scaled values. A temperature register reading 0x00FA = 250 with a scale of 0.1 from the manual means 25.0 °C.
RS-485 wiring basics
- Two-wire half-duplex differential pair (A/B or D+/D−), ideally with a common signal ground.
- Up to about 1200 m and 32 standard unit loads (more with 1/8-load transceivers).
- 120 Ω termination at both ends of the bus; daisy-chain the devices (avoid star wiring).
- All devices must share the same settings: baud rate, 8 data bits, parity (the spec default is even; with no parity use 2 stop bits), stop bits.
- Vendors label A/B inconsistently. If nothing answers, try swapping the two wires.
Troubleshooting checklist
- Baud rate, parity, stop bits and slave address match
- A/B polarity, termination, ground
- CRC value and byte order (check with the CRC calculator)
- Register offset (0-based vs 1-based) and function code (03 vs 04)
- Polling: never send the next request before the reply arrives
See the CRC guide for how the checksum works and the 4-20mA guide for analog signals.
Try it now: CRC Calculator (verify Modbus CRC) (runs in your browser, no data is sent anywhere)