CRC Calculation Programming Guide
CRC Calculation Programming Guide
This document will mainly introduce one programming approach to calculate the CRC value based on
the CRC polynomial, 𝑋 8 + 𝑋 5 + 𝑋 4 + 1, that used in TPS929120-Q1 FlexLED protocol. The related
theory knowledge of CRC will not be explained in this document.
Input
Data bit
4. Programming
#include <msp430.h>
#include <FlexLED.h>
#include <msp430.h>
#include <FlexLED.h>
#define polynomialINV 0x8C //as UART transmit from LSB to MSB, invert the polynomial
0x31 (0011 0001) to 0x8C (1000 1100)
#define LSB 0x01
for(k=0;k<256;k++)
{
remainder=k;
for(j=8;j>0;j--)
{
if(remainder & LSB)
{
remainder = (remainder>>1) ^ polynomialINV; //right shift 1 bit and
do the XOR operation with 0x8C
}
else
{
remainder = remainder>>1;
}
}
crcArray[k]=remainder;
}
}
//we have to reverse the final remainder to get the CRC value, for example, if
final remainder = 0010 1100, we need to reverse it to 0011 0100
remainder = ((remainder & 0x80)>>7) + ((remainder & 0x40) >>5) + ((remainder &
0x20) >>3) + ((remainder & 0x10)>>1) + ((remainder & 0x08)<<1) + ((remainder & 0x04)
<<3) + ((remainder & 0x02) <<5) + ((remainder & 0x01)<<7);
return remainder;
}