Assemble and verify CRC-16/MODBUS RTU frames over RS-485
Modbus RTU packs binary frames tightly on half-duplex RS-485 links with no start/stop delimiter characters. Instead, devices detect frame boundaries using silent idle intervals of at least 3.5 character times (t3.5) and verify integrity with a 16-bit cyclic redundancy check.
A frequent firmware bug is byte-swapping the CRC: while Modbus register addresses and 16-bit register data travel big-endian (high byte first), the trailing CRC-16/MODBUS checksum is always transmitted little-endian (low byte first, high byte second) using reflected polynomial 0xA001.
Formulas
CRC-16/MODBUS: init = 0xFFFF, reflected poly = 0xA001, LSB-first shiftWire order: [SlaveID, FuncCode, ...Data..., CRC & 0xFF, CRC >> 8]Character time = 11 bits ÷ baud rate; t3.5 = 3.5 × T_char (or 1,750 µs above 19,200 bps)
Worked example
Reading 10 holding registers starting at address 0x0000 from Slave ID 1 produces PDU bytes 01 03 00 00 00 0A. Its CRC-16 is 0xCDC5, transmitted on the wire as C5 CD to form 01 03 00 00 00 0A C5 CD.