Search code examples
crccrc16

CRC checksum calculation algorithm


Can anyone with good knowledge of CRC calculation verify that this code

https://github.com/psvanstrom/esphome-p1reader/blob/main/p1reader.h#L120

is actually calculating crc according to this description?

CRC is a CRC16 value calculated over the preceding characters in the data message (from “/” to “!” using the polynomial: x16+x15+x2 +1). CRC16 uses no XOR in, no XOR out and is computed with least significant bit first. The value is represented as 4 hexadecimal characters (MSB first).


Solution

  • There's nothing in the linked code about where it starts and ends, and how the result is eventually represented, but yes, that code implements that specification.