Protocol Integrity

Embedded CRC-8, CRC-16 & CRC-32 Calculator

Calculate SMBus PEC, Sensirion I2C CRC-8, Modbus RTU CRC-16, IEEE 802.3 and STM32 hardware CRC-32 checksums from hex or ASCII payloads with portable C code.

STM32F1/F4/F7/H7 CRC->DR peripheral default (MSB-first, no final XOR)
Test vectors:
Selected CRC0x0376E6E7Decimal 58124007
Polynomial0x04C11DB7Init 0xFFFFFFFF / XorOut 0x00000000
ReflectionMSB-firstCheck("123456789") = 0x0376E6E7
AlgorithmPolynomialInitRefIn / RefOutResult
CRC-8 / SMBus (PEC)0x070x00false / false0xF4
CRC-8 / Sensirion (SHT3x / SHT4x / SCD4x)0x310xFFfalse / false0xF7
CRC-16 / CCITT-FALSE0x10210xFFFFfalse / false0x29B1
CRC-16 / Modbus RTU0x80050xFFFFtrue / true0x4B37
CRC-32 / IEEE 802.3 (Ethernet / ZIP)0x04C11DB70xFFFFFFFFtrue / true0xCBF43926
CRC-32 / MPEG-2 (STM32 hardware CRC default)0x04C11DB70xFFFFFFFFfalse / false0x0376E6E7
Portable C implementation
/* CRC-32 / MPEG-2 (STM32 hardware CRC default) (MSB-first) */
uint32_t crc_compute(const uint8_t *data, size_t len) {
    uint32_t crc = 0xFFFFFFFF;
    for (size_t i = 0; i < len; i++) {
        crc ^= ((uint32_t)data[i] << 24);
        for (int b = 0; b < 8; b++) {
            crc = (crc & 0x80000000UL) ? ((crc << 1) ^ 0x04C11DB7) : (crc << 1);
        }
    }
    return crc ^ 0x00000000;
}

Why CRC mismatches break firmware bootloaders

Two CRC algorithms can share the exact same polynomial and still produce completely different words. Bit reflection, byte-lane endianness on 32-bit STM32 registers and final XOR masks account for nearly every checksum mismatch between host build scripts and target C firmware.

Frequently asked questions

QuestionAnswer
Why does the STM32 hardware CRC peripheral disagree with Python zlib.crc32()?STM32 hardware CRC uses polynomial 0x04C11DB7 with init 0xFFFFFFFF, MSB-first bit order (no reflection) and no final XOR. Standard IEEE 802.3 zlib.crc32 reflects input and output bits and XORs the final result with 0xFFFFFFFF.
What byte order does Modbus RTU use for its 16-bit CRC?Modbus RTU computes reflected CRC-16 with polynomial 0x8005 (0xA001 reflected) and transmits the low byte first on the wire. For payload 01 03 00 00 00 02, the CRC is 0x0BC4 and wire bytes are C4 0B.
How do Sensirion SHT31 and SHT40 verify I2C sensor frames?Every 16-bit temperature or humidity word is followed by one CRC-8 byte using polynomial 0x31, initial value 0xFF and no reflection. For test bytes 0xBE 0xEF, the datasheet expects 0x92.