In the field, Modbus RTU feels like two separate subjects: the cable and terminal side, and what the bytes actually mean. Most of the time the problem appears where the two meet. The line is sound but the register address is off by one, or the register is right but a 32-bit value is read in the wrong order. This guide puts the whole chain, from the line to the register map, in one place.
We have separate articles on line design and general fault finding: RS-485 line design and Modbus RTU troubleshooting. We do not repeat their topics here (topology, termination, bias, 8E1/8N2, the basic poll calculation). On top of them we add the electrical side of the physical layer, the frame and CRC, data encoding, timing optimization and debugging by reading the bytes. Numeric limits come from the two specifications published by Modbus.org and from TIA-485-A. Confirm the values that are binding for your project against the standard text and the device documentation.
Contents
- RS-485 physical layer: driver, direction control, protection
- Addressing: slave address and register address
- RTU frame structure and CRC
- Function codes
- Data types and byte order
- Example register map
- Poll timing and duration calculation
- Exception codes
- Systematic debugging
- Commissioning checklist
- Frequently asked questions
1. RS-485 physical layer: driver, direction control, protection
Topology and termination decisions are covered in the line design article. Here we look at how the line works electrically and where it meets the software.
1.1 Differential signal and common mode
RS-485 is differential. The receiver looks at the voltage difference between the two wires. According to TIA-485-A the receiver threshold is about ±200 mV, and the permitted common-mode range is about −7 V to +12 V. The driver output must also deliver a defined minimum differential voltage across a load defined in the standard (54 ohm). Confirm these numbers against the standard text and the transceiver datasheet.
What this means in the field: if the potential difference between the grounds of two devices exceeds the common-mode range, the receiver reads wrongly or the transceiver is damaged, however good the twisted pair is. Between different panels, different transformer groups and different buildings, using an isolated transceiver or an external isolator is therefore a separate decision point. For the logic of shield and common connections, see the shield grounding note.
1.2 Half duplex and direction control
Two-wire RS-485 is half duplex: only one side drives at a time. The master enables its driver while sending a request, then disables it and starts listening. The slave sends its response the same way. Direction control is done either in hardware (a converter with automatic direction sensing) or in software (the DE/RE pin). When it is done in software, the most common mistake is this:
- The driver is switched off before the last byte has fully left the line. “Transmit buffer empty” and “the last byte has been completely sent on the serial line” are not the same event. A truncated last byte shows up as a CRC error.
- The driver is switched off later than necessary. The first byte of the slave’s response is lost and the frame arrives incomplete.
The symptom is the same in both cases: a line that works on the bench but breaks in the panel or at a certain baud rate. The fix is to tie the switch-off to the “transmission complete” flag. Which flag reports this depends on the driver and the processor; check its documentation.
There is also the echo case. If the receiver is not disabled while its own driver is on, the master reads back its own request. The master software may take it for a response. Either suppress the echo in hardware or discard as many bytes as were sent in software.
1.3 Fail-safe receiver and bias
When the line is idle, the differential voltage is close to zero. The receiver output may be undefined in this state and noise can create false start bits. Bias defines this state from a single point; fail-safe receivers provide a built-in behavior for the idle line. A transceiver whose datasheet says “fail-safe” may reduce the need for bias but may not remove it. For bias values and count, see the line design note.
1.4 Surge protection
On long outdoor lines or near inductive loads, the line is exposed to transient overvoltage. TVS diodes, gas discharge tubes or a combination of them are used at the transceiver inputs. Points to watch when selecting: the capacitance of the protection element slows the signal at high baud rates, and the protection must work within the transceiver’s common-mode range. Which protection is suitable depends on the project. For in-panel layout and grounding decisions, you can look at the control panel design standards guide.
2. Addressing: slave address and register address
Modbus has two different “addresses”, and they are often confused.
2.1 Slave address
The first byte of every frame is the address of the target slave. The valid range is 1-247, and 0 is for broadcast. Broadcast makes sense only for write requests, and slaves do not respond. After a broadcast, the master must wait so the slaves can finish processing; this time is given in the device documentation or the specification, so confirm it.
In the field the address is set in one of three ways: the device menu, a DIP switch, or a register written over Modbus. Set the address of a new device on the bench or on its own before plugging it into the live line. The factory default is the same on many devices; if a second device joins with the same address, both slaves respond at once and the line is corrupted.
If there is a gateway from Modbus TCP to RTU, the unit ID on the TCP side becomes the RTU slave address. Check this mapping in the gateway’s documentation.
2.2 Register address: 0-based and 1-based notation
In the frame the data address is 16 bits, that is, from 0 to 65535, and the first register is number 0. In device documentation, however, you usually see the “4xxxx” notation:
| Notation | Meaning | Typical function |
|---|---|---|
| 0xxxx | Coil (read/write bit) | 01, 05, 15 |
| 1xxxx | Discrete input (read-only bit) | 02 |
| 3xxxx | Input register (read-only 16 bit) | 04 |
| 4xxxx | Holding register (read/write 16 bit) | 03, 06, 16 |
This prefix notation is a habit that grew out of the field; there is no prefix in the frame. In the frame, the function code determines the data type. The notation 40001 usually corresponds to protocol address 0, so you subtract. Some manufacturers use a 6-digit notation (400001), and some already write the protocol address. Look for the phrase “protocol address” or “PDU address” in the documentation, and if it is unclear, test with a register you know.
3. RTU frame structure and CRC
3.1 The frame
An RTU frame consists of four fields:
| Field | Size | Description |
|---|---|---|
| Slave address | 1 byte | 0-247 |
| Function code | 1 byte | The most significant bit becomes 1 in an error response |
| Data | n bytes | Varies with the function |
| CRC | 2 bytes | Low byte is sent first |
The upper limit of the data field comes from the PDU limit in the Modbus application protocol. The PDU (function code + data) is at most 253 bytes; with the slave address and CRC added, an RTU frame is at most 256 bytes. This limit determines how many registers you can read in one request (section 4).
The start and end of a frame are marked by silence: there must be a gap of at least 3.5 character times between frames, and a gap of at most 1.5 character times between characters within a frame. The numeric details are in the troubleshooting note.
3.2 CRC-16 calculation
The CRC is calculated over all bytes from the address byte to the last byte of the data. The algorithm can be summarized as follows:
- Initialize a 16-bit register to 0xFFFF.
- For each byte, XOR the low byte of the register with the byte.
- Repeat eight times: if the least significant bit is 1, shift the register right by one bit and XOR it with 0xA001; if it is 0, just shift.
- After all bytes, the register is the CRC. Write the low byte to the frame first, then the high byte.
This is the variant most sources call “CRC-16/MODBUS” (polynomial 0x8005, reflected form 0xA001). A ready-made library that uses a different CRC-16 variant corrupts the results silently.
Check your routine in these two ways:
- Known example. A request with address 1, function 03, start 0, quantity 1 must be:
01 03 00 00 00 01 84 0A. The last two bytes are the CRC (low byte 0x84 first, then 0x0A). If your routine gives a different result, check the byte order and the algorithm. - Self-check. If you calculate the CRC over the whole frame including the CRC bytes, the result is 0x0000 provided the low byte was written first. This is the shortest way to verify on the receiving side.
3.3 Reading the example request
The frame 01 03 00 00 00 01 84 0A is read as follows:
| Byte | Meaning |
|---|---|
| 01 | Slave address 1 |
| 03 | Read holding registers |
| 00 00 | Start address 0 (two bytes, high byte first) |
| 00 01 | Quantity 1 |
| 84 0A | CRC (low, high) |
The structure of the expected response: address, 03, byte count (02), two data bytes, CRC. A total of 7 bytes.
4. Function codes
These are the ones that matter in the field. The upper limits derive from the 253-byte PDU, and a device may set a lower limit. Check the device documentation.
| Code | Name | Upper limit (from the specification) | Note |
|---|---|---|---|
| 01 (0x01) | Read coils | 2000 bits | Bits are packed within bytes starting from the low bit |
| 02 (0x02) | Read discrete inputs | 2000 bits | Read-only |
| 03 (0x03) | Read holding registers | 125 registers | Most commonly used |
| 04 (0x04) | Read input registers | 125 registers | Typical for measured values |
| 05 (0x05) | Write single coil | 1 | 0xFF00 for on, 0x0000 for off |
| 06 (0x06) | Write single register | 1 | The response is identical to the request |
| 15 (0x0F) | Write multiple coils | 1968 bits | |
| 16 (0x10) | Write multiple registers | 123 registers | Prefer this code for 32-bit values |
| 23 (0x17) | Read/write | Read 125, write 121 | Not every device supports it |
| 43/14 | Read device identification | Device dependent | To read manufacturer, model, version |
| 08 (0x08) | Diagnostics | Depends on sub-function | Counters and loopback test (section 9) |
You will not use most of these codes. In practice 03, 04, 06 and 16 do most of the work. Reading measurements and status is done with 03 or 04, writing parameters with 06 or 16, and relay and output commands with 05.
4.1 Points to watch with write codes
- Do not write 32-bit values with 06. Two separate 06 requests are processed at two separate times; in between, the device may use the intermediate value. For a two-register value, 16 writes it in a single request.
- With 05 only 0xFF00 and 0x0000 are valid. Any other value produces an exception response.
- A write response is not a confirmation. The device may have accepted the value and limited or rounded it. After writing critical parameters, read them back and compare.
- Writing to non-volatile memory. Some devices write parameter registers to EEPROM, and the number of writes is limited. Do not keep writing the same parameter in a loop. Read the limit from the device documentation.
4.2 Request and response byte counts
You need these numbers for the duration calculation:
| Function | Request (bytes) | Response (bytes) |
|---|---|---|
| 03 / 04, N registers | 8 | 5 + 2N |
| 01 / 02, N bits | 8 | 5 + ⌈N/8⌉ |
| 06 | 8 | 8 |
| 16, N registers | 9 + 2N | 8 |
5. Data types and byte order
5.1 Order in the frame
In Modbus, register and address fields are sent big-endian: high byte first, then low byte. The CRC is the only exception; its low byte goes first. This rule is clear for 16-bit fields.
5.2 32-bit and 64-bit values
The specification defines the 16-bit register; it does not define how a 32-bit value is spread across two registers. This is a manufacturer decision and the most commonly misread topic in the field. The same value can arrive in four forms. Example value: 0x12345678.
| Name | First register | Second register |
|---|---|---|
| ABCD (big-endian, most common order) | 0x1234 | 0x5678 |
| CDAB (word swapped) | 0x5678 | 0x1234 |
| BADC (byte swapped) | 0x3412 | 0x7856 |
| DCBA (fully reversed) | 0x7856 | 0x3412 |
Naming varies from source to source. Decide by looking at the bytes that arrive, not at the table.
5.3 Floating point and verification
The IEEE 754 single-precision value 25.5 is 0x41CC0000. If the device documentation says “float, two registers”, test it like this:
- Produce a known value or find a fixed readable parameter. For example a temperature that shows 25.5 on the display.
- Read the raw two registers.
- Find which of the four orders gives 25.5.
- Write the order you chose into the configuration and record it per device model. Different products from the same manufacturer may use a different order.
For devices that use scaled integers instead of float (for example the value 235 with a 0.1 scale meaning 23.5), the sign and scale are given in the documentation.
5.4 Signed numbers and bits
- A 16-bit signed number is carried in two’s complement; the value −1 arrives as 0xFFFF. If the reader interprets it as unsigned, it sees 65535.
- Bit fields (status, alarm) carry meaning bit by bit within a single register. Take which bit is which alarm from the device documentation; bit numbering (0-based, least significant bit) may vary by manufacturer.
- ASCII text (such as a device name) fits two characters per register. Confirm from the documentation which character is in the high byte.
6. Example register map
The map below is an example; it does not belong to a real device. The address column is the protocol (0-based) address. The labels are kept generic.
| Protocol address | Notation | Label (example) | Type | Scale / unit | Access |
|---|---|---|---|---|---|
| 0 | 30001 | example_temperature |
int16 | 0.1 °C | Read-only (FC 04) |
| 1 | 30002 | example_humidity |
uint16 | 0.1 % | Read-only (FC 04) |
| 2-3 | 30003-30004 | example_energy_total |
float32 (CDAB, example) | kWh | Read-only (FC 04) |
| 10 | 40011 | example_setpoint |
int16 | 0.1 °C | Read/write (FC 03/06) |
| 11 | 40012 | example_mode |
uint16 | 0 = off, 1 = manual, 2 = auto | Read/write |
| 12 | 40013 | example_alarm_bits |
uint16 (bit field) | bit 0: high temperature; bit 1: sensor fault | Read-only (FC 03) |
| 20 | 00021 | example_output_1 |
coil | 0 = off, 1 = on | Read/write (FC 01/05) |
| 100 | 40101 | example_slave_address |
uint16 | 1-247 | Restart required after writing |
6.1 When preparing the map for your own project
- Keep the notation column and the protocol address separate; writing only one of them leads to an off-by-one error.
- Add type, scale, unit, access and byte order to every row. If a row has no “order”, that row will have to be researched again later.
- Do not send requests to ranges the device cannot read. Many devices return an “illegal address” exception at an undefined address (section 8). When you read consecutive blocks and hit a gap, the whole request is dropped.
- Place frequently changing and rarely changing values in separate groups; the poll strategy is built on them (section 7).
- Store the map together with version information. The same model may have a different register layout depending on the firmware version.
7. Poll timing and duration calculation
The basic formula is in the line design note. Here we deepen it in two directions: calculating starting from the character time, and ways to shorten the poll.
7.1 Character time
An RTU character is 11 bits (1 start, 8 data, 1 parity, 1 stop; with 8N2 the total is also 11). The character time is 11 / baud seconds.
| Baud | Character time | 3.5 characters |
|---|---|---|
| 9600 | about 1.15 ms | about 4.0 ms |
| 19200 | about 0.57 ms | about 2.0 ms |
Above 19200 the specification recommends fixed values (750 µs for 1.5 characters, 1.75 ms for 3.5 characters). Check in your master software’s documentation how it applies them.
7.2 Three example calculations
These are example calculations. Recalculate with your own baud rate and your device’s measured response time. For the slave processing time, 10 ms was assumed in the examples; the real value depends on the device.
Example A: reading two registers (one float32), 19200 baud. The request is 8 bytes, the response 5 + 4 = 9 bytes; a total of 17 bytes, that is 187 bits. Line time 187 / 19200 ≈ 9.7 ms. Two 3.5-character silences ≈ 4.0 ms. With a 10 ms slave time, one query takes about 24 ms. At 9600 baud the same calculation gives about 19.5 + 8.0 + 10 ≈ 37.5 ms.
Example B: writing two registers (FC 16). The request is 9 + 4 = 13 bytes, the response 8 bytes; a total of 21 bytes, that is 231 bits. At 19200 the line time is about 12.0 ms.
Example C: 125 registers, one block or one by one? In a single block the request is 8 bytes and the response 5 + 250 = 255 bytes; a total of 263 bytes, that is 2893 bits. At 19200 the line time is about 150.7 ms. Adding 4.0 ms of silence and 10 ms of slave time gives about 165 ms. If you read the same 125 registers one by one, each request is 8 + 7 = 15 bytes, that is 165 bits, the line time is 8.6 ms; with silence and slave time it comes to about 22.6 ms. 125 requests take about 2.8 seconds. The difference is about 17 times.
7.3 Ways to shorten the poll
- Read consecutive registers in one request. There is a fixed overhead per request (address, function, CRC, silences, slave time). Each additional register adds only 2 bytes, that is 22 bits.
- Read and discard small gaps. If the fixed overhead per request is counted in bytes only (13 bytes ≈ 143 bits, plus 7 characters of silence ≈ 77 bits; total ≈ 220 bits), it corresponds to a gap of about 10 registers. As slave time is added, this number grows. If the gap contains an undefined address you get an exception; check the map.
- Set up fast and slow groups. Alarms and status can be read every cycle; energy counters and parameters every few cycles.
- Raise the baud rate, but only after verifying the line. When the baud rate doubles, the line time halves; the slave time does not fall at the same rate (above 19200 the silences also stay fixed). Going from 9600 to 19200 does not halve the cycle time.
- Temporarily remove a non-responding device from the cycle. Every failed query that waits for the timeout lengthens the cycle for the other devices. After a few attempts, mark the device “offline” and retry less often.
7.4 Response timeout
The timeout should be at least the sum of the line time, the slave’s worst-case processing time and a safety margin. Too short a setting produces false timeouts; too long a setting slows the cycle when a device drops out. To measure the slave time, look at the gap between the last byte of the request and the first byte of the response on the analyzer. Measure it separately for different jobs (writing a parameter, a read that requires computation).
8. Exception codes
If the slave receives the request, the CRC is correct but it cannot carry out the request, it gives an exception response. The function code of the response is the request’s code with the most significant bit set to 1, for example 0x83 for 03. An exception code byte and the CRC follow. The response is typically 5 bytes: address | 83 | code | CRC (2).
An important distinction: if you receive an exception, the line is sound. The slave heard you, understood you and answered. The problem is on the address or value side. If no response comes at all, you look at the line, the settings or the CRC.
| Code | Name | Typical cause | What to do |
|---|---|---|---|
| 01 | Illegal function | The device does not support this code | Check the supported codes in the documentation; try 04 instead of 03 |
| 02 | Illegal data address | The address or address + quantity is outside the device’s defined range | Off-by-one, quantity too large, gap in the map |
| 03 | Illegal data value | The value is outside the allowed range or the quantity is invalid | Check the range and the quantity limit |
| 04 | Slave device failure | Internal error while the device processes the request | Check the device status, retry |
| 05 | Acknowledge | A long operation was accepted but not finished | Query the status after a while |
| 06 | Slave device busy | The device is busy with another job | Wait and retry |
| 08 | Memory parity error | Memory error during extended file access | Consult the device manufacturer |
| 10 (0x0A) | Gateway path unavailable | The gateway cannot open a path to the target | Gateway configuration |
| 11 (0x0B) | Gateway target device failed to respond | The device behind the gateway does not answer | The line and device behind it |
Confirm the list of exception codes against the Modbus application protocol specification. Manufacturers may also use codes outside the specification.
In practice the two you meet most often are 02 and 03. 02 usually points to an address offset or a gap inside a block; 03 to an out-of-range write or too large a quantity.
9. Systematic debugging
The general symptom table and the physical check sequence are given in the troubleshooting note. Here we present a method based on reading frames byte by byte. Listen passively to the line with an analyzer or a USB-RS485 converter and save the raw bytes.
9.1 What do you see, and what does it mean?
| What you see | Likely meaning | Next step |
|---|---|---|
| Request present, no response at all | The slave does not hear or rejects the CRC; wrong address; faulty line | Settings, A/B, address |
| Request present, response present, CRC wrong | Noise, parity mismatch, truncated last byte | Parity setting, direction control, termination |
| Extra 0x00 or 0xFF at the start of the response | Transient level while the driver turns on, direction control delay | Direction control timing |
| Response identical to the request (even for 03) | Echo: the receiver listens to its own driver | Suppress the echo in hardware or software |
| Response comes from another address | Same address on two devices or wrong target | Address list |
| Two responses overlap | Two slaves with the same address | Connect the devices one by one |
| Response function code starts with 0x80 | Exception | Section 8 |
| Frame split in the middle (gap) | Master or converter timing | USB converter and operating system delay |
| Response correct but value meaningless | Byte order, type, scale or off-by-one | Sections 5 and 2 |
9.2 Method
- Reduce to a single device. Work with a short cable and termination between the master and a single slave. If it works, the problem is in the line or in the other devices; if it does not, it is in the device settings.
- Then split the line in two. On a line that does not work, remove devices half at a time and find which half carries the problem. When there are many devices, this is much faster than trying them one by one.
- Read a known value. Create a register with a known correct value for each device (device identification or a fixed parameter). If the line works but the values are wrong, the known value immediately reveals an off-by-one and the byte order.
- Keep error counters. On the master side, record separate timeout and CRC counters for each slave together with time. Errors that rise on all devices at the same time point to a common cause (master, converter, line). Errors that rise on a single device point to that device’s settings or connection.
- Use the diagnostic code if the device supports it. The sub-functions of function 08 include a loopback test and slave-side counters for messages, CRC errors and no-response. Confirm from the documentation which ones your device supports. The CRC error counter the slave sees itself tells you by whom the line is being corrupted.
- Make one change at a time. Change one thing at a time and note the result.
9.3 Common root causes
- Parity “none” is selected in the device menu but the number of stop bits is wrong.
- The converter’s direction control is late at a high baud rate.
- Two different master programs (a maintenance laptop and the SCADA side) query the same line at the same time.
- A block read ran into an undefined address.
- The device restarts after a write, so the next few queries go unanswered.
- Many devices were gathered on a single line without calculating the poll time.
10. Commissioning checklist
This list complements the checklists in the line design and troubleshooting notes. For how to carry it into the factory acceptance test, see the FAT checklist note.
- The address and settings (baud, parity, stop bits) of each slave were written in the device table and ticked off one by one.
- New devices were addressed on the bench before being plugged into the live line.
- The register map was written with the protocol address (0-based) and the notation kept separate, including type, scale, unit and byte order.
- The CRC routine was tested with the known example (
01 03 00 00 00 01 84 0A). - Address offset and 32-bit order were verified for each device with a known register.
- Consecutive reads were grouped into blocks; no undefined address remains inside a block.
- Registers that are written were read back and verified; the write frequency was limited for those written to non-volatile memory.
- Direction control was verified with an analyzer at the target baud rate; there is no echo and the last byte is not truncated.
- Timeout, retry count and offline device behavior were configured.
- The poll time was measured with the full number of devices under load and compared with the calculation.
- With the line idle, the idle level and the differential voltage with the driver on were measured.
- Error counters were monitored with motors and drives running (the worst noise case).
- The timeout and CRC counters of each device were recorded; an acceptance limit was set.
- The analyzer recording was added to the commissioning report.
Frequently asked questions
Why is the CRC sent low byte first in Modbus RTU?
That is how the specification defines it: the CRC field is written in the frame with the low byte first. It is the only exception to the big-endian order in the register and address fields. If you leave this out of routines you write by hand, all frames are rejected.
Is address 40001 0 or 1 in the protocol?
Usually 0, but it is not guaranteed. The notation is a habit that grew out of the field and manufacturers apply it differently. Test with a known value.
Why do two programs read a 32-bit value differently?
Because the specification does not define the order in which two registers are combined. The manufacturer may choose different orders such as ABCD or CDAB. Find the right one with a known value read from the device.
How many registers can I read in one request?
According to the specification, 125 registers for functions 03 and 04, and 123 when writing with function 16. This comes from the 253-byte PDU limit. Some devices set a lower limit; check the device documentation.
The line works but sometimes no response comes. Is it an exception?
No. An exception is a response; it means the slave heard you. No response at all points to the line, the settings, the address or the CRC. With an analyzer, look at how the request appears on the line and whether the response arrives.
Can I read with broadcast?
No. Broadcast (address 0) is for writing only and slaves do not respond. Reading requires a separate query to each device.
How much does raising the baud rate reduce the poll time?
The line time decreases in inverse proportion to the baud rate; the slave processing time stays the same. So the gain is usually less than proportional. Optimizing block reads and poll groups first is often more effective than raising the baud rate.
To roughly see the time of a single read and of scanning all devices once, you can use the Modbus RTU poll and scan time calculator; the result is a lower-bound estimate.
If you would like support with Modbus RTU, from line design to commissioning, take a look at our Industrial automation page.