3.17 CRC - Cyclic Redundancy Check
This device is equipped with a 16-bit CRC-CCITT algorithm to ensure the integrity of loaded configurations and provides a way to confirm that the user stored configuration was loaded. By monitoring the CRC register, the host application can understand whether the loaded configuration is intended for their application.
Note: The CRC value will be calculated during the saving, loading, and
loading processes of the user's configuration.
Sample Program
// Function to calculate the CRC-16 of a data array
uint16_t crc16_ccitt(const uint8_t *value, uint16_t length)
{
// Initial value
uint16_t crc = 0xFFFFu;
for (uint16_t i = 0u; i < length; i++)
{
// XOR byte into most sig. byte of crc
crc ^= (uint16_t)(((uint16_t)value[i]) << 8u);
// Loop over each bit
for (uint8_t j = 0u; j < 8u; j++)
{
// If the uppermost bit is 1...
if ((crc & 0x8000u) != 0u)
{
// ...shift left and XOR with the polynomial
crc = ((crc << ((uint16_t)1u)) ^ CRC16_POLY);
}
else
{
// Just shift left
crc = (crc << 1u);
}
}
}
return crc; // Final CRC value
}
The following values have been used to compute the CRC.
Initial Value | 0xFFFF |
CRC16_POLY | 0x1021 |