
www.sensirion.com
Version 1.3
–
September 2022
19/24
3.11
Checksum Calculation
The 8-bit CRC checksum transmitted after each data word is generated by a CRC algorithm. Its properties are displayed in
. The CRC covers the contents of the two previously transmitted data bytes. To calculate the checksum only these two
previously transmitted data bytes are used. Note that command words are not followed by CRC.
Property
Value
Example code (C/C++)
Name
CRC-8
#define CRC8_POLYNOMIAL 0x31
#define CRC8_INIT 0xFF
uint8_t
sensirion_common_generate_crc
(
const uint8_t
*
data
,
uint16_t
count
) {
uint16_t
current_byte
;
uint8_t
crc
=
CRC8_INIT
;
uint8_t
crc_bit
;
/* calculates 8-Bit checksum with given polynomial */
for
(
current_byte
=
0
;
current_byte
<
count
; ++
current_byte
) {
crc
^= (
data
[
current_byte
]);
for
(
crc_bit
=
8
;
crc_bit
>
0
; --
crc_bit
) {
if
(
crc
&
0x80
)
crc
=
(
crc
<<
1
) ^
CRC8_POLYNOMIAL
;
else
crc
= (
crc
<<
1
);
}
}
return
crc
;
}
Width
8 bit
Protected Data
read and/or write data
Polynomial
0x31 (x8 + x5 + x4 + 1)
Initialization
0xFF
Reflect input
False
Reflect output
False
Final XOR
0x00
Examples
CRC (0xBEEF) = 0x92
Table 32
I
2
C CRC properties.