This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
Hello
I'm using the following function to calculate the CRC value returned from a BQ2022A. However, I'm not sure what the BQ2022A uses as an initial CRC value. I'm unable to find it in the datasheet. Can anyone help, please?
Thanks
Ron
#define CRC8_POLY 0x31 // x^8 + x^5 + x^4 + 1
#define CRC8_INIT 0xFF // Initial CRC value
uint8_t calc_crc8(const uint8_t *data, size_t length)
{
uint8_t crc = CRC8_INIT;
for (size_t i = 0; i < length; i++)
{
crc ^= data[i];
for (uint8_t j = 0; j < 8; j++)
{
if (crc & 0x80)
{
crc = (crc << 1) ^ CRC8_POLY;
}
else
{
crc <<= 1;
}
}
}
return crc;
}