Short answer: if a Modbus RTU device does not answer or you get CRC errors, check in this order: slave address, baud rate and parity, A/B wiring and termination, the gap between frames, and how your code assembles the response bytes.
1. Slave address
The address in your request must match the device. A wrong address gives silence, not an error.
2. Serial settings
Baud rate, data bits, parity and stop bits must match exactly. A common default is 9600 baud, but confirm it in the manual. Wrong settings usually produce garbage and CRC errors.
3. RS485 wiring
- A and B swapped is a very common cause of no response. Try swapping them.
- Use a common ground reference where the manual requires it.
- Long runs need termination at both ends of the bus only.
4. Silent interval between frames
Modbus RTU frames are separated by a silent time of at least 3.5 character times. For baud rates above 19200 the specification suggests a fixed 1.75 ms. If your bridge or code sends the next request too early, or splits one frame with a pause, the device may ignore it.
5. Framing in your app
Responses can arrive in pieces, especially over Bluetooth or a serial bridge. For a function 3 read of n registers, the full reply is 5 + 2n bytes. Wait until you have all of them, then check the CRC.
fun expectedLength(count: Int) = 5 + 2 * count // addr, func, bytes, data, crc(2)
val buffer = ByteArrayOutputStream()
fun onBytes(chunk: ByteArray, count: Int): ByteArray? {
buffer.write(chunk)
return if (buffer.size() >= expectedLength(count)) buffer.toByteArray() else null
}
An exception reply is only 5 bytes, so also accept a response whose second byte has the high bit set.
6. Timeouts and retries
Use a timeout longer than the device’s response time, send one request at a time, and retry a limited number of times before reporting an error.
Checklist
- Right slave address.
- Baud rate, parity and stop bits match.
- A and B not swapped, termination correct.
- Frames spaced by the silent interval.
- Full response collected before the CRC check.
- One request at a time with a sensible timeout.
FAQ
Why do I get CRC errors only sometimes?
Usually noise, a bad ground or termination, or an incomplete frame being checked too early.
Can two devices share an address?
No. Each device on the bus needs a unique address, or they will answer at the same time.
Related: Modbus RTU Basics for Android Developers and the Bluetooth and IoT hub.
Register maps differ by manufacturer. Always confirm addresses, scaling and word order in your device manual.