高精度数字温度传感芯片 MTS01 IIC CRC校验程序(x8 + x5 + x4 + 1)
敏源传感高精度数字温度传感芯片MTS01 IIC 通信时CRC校验程序详见以下:
/*
*Name: CRC-8 x8+x5+x4+1
* Poly: 0x31
* Init: 0xFF
* Refin: False
* Refout: False * Xorout: 0x00 */
#define POLYNOMIAL 0x131 //100110001
uint8_t MY_I2C_CRC8(uint8_t data[], uint8_t length)
{
uint8_t bit; // bit mask
uint8_t crc = 0xFF; // calculated checksum
uint8_t byteCtr; // byte counter
// calculates 8-Bit checksum with given polynomial
for(byteCtr = 0; byteCtr < length; byteCtr++)
{
crc ^= (data[byteCtr]);
for(bit = 8; bit > 0; --bit)
{
if(crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
else crc = (crc << 1);
}
}
return crc;
}