Skip to content

Modbus RTU CRC Errors on Serial Bus

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about Modbus RTU CRC Errors on Serial Bus. We cover key concepts, practical examples, and best practices.

The Problem

Modbus RTU communication has frequent CRC errors, corrupting data.

Quick Fix

Wrong

modbus_new_rtu('/dev/ttyUSB0', 9600, 'N', 8, 1);  # Too slow for long messages
CRC errors causing retransmissions and data corruption.
#include <modbus/modbus.h>

modbus_t *setup_modbus_rtu(const char *device) {
  modbus_t *ctx = modbus_new_rtu(device, 115200, 'N', 8, 1);
  if (ctx == NULL) return NULL;
  
  // Set serial mode (RS-485)
  modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485);
  
  // Enable RTS for direction control
  modbus_rtu_set_rts(ctx, MODBUS_RTU_RTS_DOWN);
  modbus_rtu_set_custom_rts(ctx, my_rts_function);
  
  // Set inter-frame delay (us) — 3.5 character times
  // At 115200 baud: ~350 us
  struct timeval t = {0, 350};
  modbus_rtu_set_inter_byte_timeout(ctx, &t);
  
  // Set response timeout
  modbus_set_timeout(ctx, 1, 500000);  // 1.5 seconds
  
  return ctx;
}

// Check CRC on received data
// libmodbus verifies CRC automatically
No CRC errors — reliable Modbus RTU communication.

Prevention

CRC errors are caused by: baud rate mismatch, wrong parity, bad wiring, missing termination resistors, electrical noise, or incorrect RTS timing for RS-485. Common fixes: increase baud rate (shorter message = less noise exposure), use 120 Ohm termination at both ends, shielded twisted-pair cable, ferrite beads on long runs.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What causes CRC errors?

Line noise, incorrect baud/parity/data bits, reflections on unterminated lines, ground loops, faulty transceivers. CRC itself is correct — it detects corruption.

What is the inter-character timeout?

1.5 character times (minimum) to detect end-of-frame. Modbus RTU: no explicit frame delimiter — silence indicates frame end.

Does libmodbus handle CRC automatically?

Yes. libmodbus calculates CRC on transmit and verifies on receive. You do not need to manually compute CRC.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro