cancel
Showing results for 
Search instead for 
Did you mean: 

AIS2120 CRC and workflow

Yz2
Visitor
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!wechat_2025-09-30_123322_374.png

@Andrew Neil 

0 REPLIES 0