Modbus CRC-16 and LRC calculatorModbus CRC-16 与 LRC 计算器

CRC-16 for RTU, LRC for ASCII — or paste a complete frame to check it.

RTU 算 CRC-16,ASCII 算 LRC;也可以粘完整帧来校验。

Bytes字节

Result结果

Frame to send完整待发帧

—

Calculation trace计算过程

#ByteCRC after this byteXOR input

Start value is 0xFFFF. Each byte is XORed into the low byte, then eight right shifts are applied; whenever the bit shifted out is 1 the polynomial 0xA001 is XORed back in. The final register is appended low byte first.初值 0xFFFF。每个字节先异或到低字节,再做 8 次右移;移出的位为 1 时异或多项式 0xA001。最终寄存器低字节在前追加。

CRC-16/MODBUS in one paragraph一段话讲清 CRC-16/MODBUS

Modbus uses the CRC-16 with polynomial 0x8005 in reflected form (0xA001), initial value 0xFFFF, no final XOR and no output reflection. It is computed over every byte of the frame before the CRC itself, including the unit ID. The 16-bit result is appended low byte first, so a computed 0x84C0 is sent as C0 84. The standard check value is the ASCII string 123456789, which must produce 0x4B37.

It is not the same as CRC-16/IBM (ARC), CRC-16/CCITT or CRC-16/XMODEM. A frame checksummed with the wrong variant will fail every time even though the values look plausible.

Modbus 使用多项式 0x8005 的反射形式(0xA001),初值 0xFFFF,结果不取反、不反射。计算范围是 CRC 之前的全部字节,包含从站地址。16 位结果低字节在前追加,例如算出 0x84C0 就发送 C0 84。标准校验串是 ASCII 123456789,结果必须是 0x4B37。

它和 CRC-16/IBM(ARC)、CRC-16/CCITT、CRC-16/XMODEM 都不一样。用错变体时数值看着合理,但每一帧都会校验失败。

Three mistakes that account for most CRC failures90% 的 CRC 错误来自这三种情况