2025-09-30 1:31 AM
uint8_t ubCrcVal(uint32_t ulCrcVal) {
uint8_t crc = 0x00;
uint8_t i;
uint8_t b;
for (i = 0; i < 4; i++)
{
crc ^= (uint8_t) ((ulCrcVal >> (i * 8)));
for (b = 0; b < 8; b++)
{
if (crc & 0x80)
{
crc = (uint8_t) ((crc << 1) ^ 0x97);
}
else
{
crc <<= 1;
}
}
}
return crc;
}
int main() {
uint32_t cmd=0xE1800000; // cmd for sensor id
printf("CrcValue=0x%02X\n", ubCrcVal(cmd));
return 0;
}
AIS2120 accelerometer. I'm also using this sensor now and have some questions I'd like to consult with you.Is this the correct way to calculate the CRC check code? I hope to receive your reply. Thank you very much!