15.3 Functional Description
15.3.1 16-bit CRC Algorithm
The CRC unit generates a 16-bit CRC result equivalent to the following algorithm:
1. XOR the input with the most-significant bits of the current CRC result. If this is the first iteration of the CRC unit, the current CRC
result will be the set initial value (0x0000 or 0xFFFF).
2. If the MSB of the CRC result is set, shift the CRC result and XOR the result with the polynomial.
3. If the MSB of the CRC result is not set, shift the CRC result.
4. Repeat steps 2 and 3 for all 8 bits.
The algorithm is also described in the following example.
unsigned short UpdateCRC (unsigned short CRC_acc, unsigned char CRC_input)
{
unsigned char i; // loop counter
#define POLY 0x1021
// Create the CRC "dividend" for polynomial arithmetic (binary arithmetic
// with no carries)
CRC_acc = CRC_acc ^ (CRC_input << 8);
// "Divide" the poly into the dividend using CRC XOR subtraction
// CRC_acc holds the "remainder" of each divide
//
// Only complete this division for 8 bits since input is 1 byte
for (i = 0; i < 8; i++)
{
// Check if the MSB is set (if MSB is 1, then the POLY can "divide"
// into the "dividend")
if ((CRC_acc & 0x8000) == 0x8000)
{
// if so, shift the CRC value, and XOR "subtract" the poly
CRC_acc = CRC_acc << 1;
CRC_acc ^= POLY;
}
else
{
// if not, just shift the CRC value
CRC_acc = CRC_acc << 1;
}
}
// Return the final remainder (CRC value)
return CRC_acc;
}
The following table lists several input values and the associated outputs using the 16-bit CRC algorithm:
Table 15.1. Example 16-bit CRC Outputs
Input
Output
0x63
0xBD35
0x8C
0xB1F4
0x7D
0x4ECA
0xAA, 0xBB, 0xCC
0x6CF6
0x00, 0x00, 0xAA, 0xBB, 0xCC
0xB166
EFM8UB3 Reference Manual
Cyclic Redundancy Check (CRC0)
silabs.com
| Building a more connected world.
Rev. 0.2 | 183