https://github.com/futekast/crc16_modbus
Reusable C implementation of CRC-16/MODBUS with documented bitwise and table-based calculation methods.
https://github.com/futekast/crc16_modbus
c checksum crc crc16 crc16-modbus embedded error-detection firmware modbus
Last synced: about 2 months ago
JSON representation
Reusable C implementation of CRC-16/MODBUS with documented bitwise and table-based calculation methods.
- Host: GitHub
- URL: https://github.com/futekast/crc16_modbus
- Owner: futekast
- License: mit
- Created: 2026-05-01T02:18:21.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-01T02:29:17.000Z (about 2 months ago)
- Last Synced: 2026-05-01T04:14:38.053Z (about 2 months ago)
- Topics: c, checksum, crc, crc16, crc16-modbus, embedded, error-detection, firmware, modbus
- Language: C
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CRC16_MODBUS
Reusable C implementation of CRC-16/MODBUS.
## Files
- `include/crc16_modbus.h`
- `src/crc16_modbus.c`
- `examples/main.c`
## CRC Parameters
| Parameter | Value |
|---|---:|
| Name | CRC-16/MODBUS |
| Polynomial | 0x8005 |
| Reflected Polynomial | 0xA001 |
| Initial Value | 0xFFFF |
| Input Reflected | Yes |
| Output Reflected | Yes |
| Final XOR | 0x0000 |
## Validation
ASCII Check: `"123456789"` -> `0x4B37`
HEX Check: `0x12 0x34 0x56 0x78 0x09` -> `0x2590`
Reverse ASCII Check: `"987654321"` -> `0xC9D3`
Reverse HEX Check: `0x09 0x78 0x56 0x34 0x12` -> `0x7C96`
Both bitwise and table-based functions are validated against the same expected results.
## Byte-Order Note
CRC-16/MODBUS is calculated over the byte order provided to the function.
If a protocol displays bytes in one order but defines CRC calculation over the reverse order, the input buffer must be arranged in the protocol-defined CRC order before calling the CRC function.
Example:
Displayed HEX input:
```text
0x12 0x34 0x56 0x78 0x09