Solved
STM32G0 CRC16 mismatch.
Hi,
I am trying to run the CRC calculation with the STM32G031 but the results do not match. The result of the CRC16_CCITT_FALSE should be 0x29B1 according to http://www.sunshine2k.de/coding/javascript/crc/crc_js.html but I get 0x277F.
You can find my implementation below.
unsigned short CRC_16Bit_Polynom(unsigned char *Data, unsigned char Size);
void CRC_Init(void);
int main(void)
{
unsigned char Buffer[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
CRC_16Bit_Polynom(Buffer, 9);
}
void CRC_Init(void)
{
RCC->AHBENR |= RCC_AHBENR_CRCEN;
CRC->CR = 0x00000000;
CRC->CR |= CRC_CR_POLYSIZE_0;
CRC->INIT = 0xFFFF;
CRC->POL = 0x1021;
}
unsigned short CRC_16Bit_Polynom(unsigned char *Data, unsigned char Size)
{
unsigned short Ergebnis = 0;
CRC->CR |= CRC_CR_RESET;
for(unsigned char i = 1; i <= Size; i++)
{
CRC->DR = (unsigned short) *Data;
Data++;
}
Ergebnis = (unsigned short)CRC->DR;
return Ergebnis;
}Please kindly help to find the mistake.
