Hello Forum,
Im trying to setup the to use the hardware CRC generator for calculating Modbus crc values using the CRC api I setup in the configuration tool. Im using the CRC_POLY_CRC_16. I have manual crc generation code I can use as a comparison. My results are not as I expect. Im not sure why Im seeing different results. Other then maybe the CRC is not preloaded with the 0xffff when it starts it calculation. Im not sure what to make of why this is not working other then maybe the preloading of the crc value with the 0xffff.
Thanks for the help!
Matt
Im doing as follows.
static uint8_t xmit_buffer[] = { 0xFC, 0x03, 0x00, 0x02, 0x00, 0x07 };
uint32_t ui32CRC = 0;
uint16_t ui16CRC = 0xffff;
g_crc0.p_api->open(g_crc0.p_ctrl,g_crc0.p_cfg);
g_crc0.p_api->calculate(g_crc0.p_ctrl,xmit_buffer,6,0xA001,&ui32CRC);
From that Im expecting to get back 0x25B0. Im not.
My comparison code is below.
while(i<6)
{
ui16CRC = crc_byte(xmit_buffer[i++],ui16CRC);
}
U16 crc_byte(U08 n, U16 ui_crc)
{
char i=0;
ui_crc ^= n;
while(i<8)
{
if (ui_crc & 1)
{
ui_crc >>= 1;
ui_crc ^= 0xA001;
}
else
ui_crc >>= 1;
i++;
}
return ui_crc;
}