Is it possible to have a crc16 implementation that accept different polynomial ? I mean by different polynomial the same function that can calculate crc16 with, one time, polynomial 0xA001 and an other time polynomial 0x1D0F (for exemple).
I have this code, in C, that work fine for little endian, with modbus polynomial (0xA001). I choose to initialise crc 16 at 0xFFFF :
uint16_t _crc16_update(uint8_t *Trame, uint32_t NbOctets, uint16_t Polynome)
{
uint16_t u16CRC;
int_t i;
int_t j;
u16CRC = 0xFFFF;
for (i = NbOctets - 1; i >= 0; i--)
{
u16CRC = u16CRC ^ Trame[i];
for (j = 0; j < 8; ++j)
{
if (u16CRC & 1)
u16CRC = (u16CRC >> 1) ^ Polynome;
else
u16CRC = (u16CRC >> 1);
}
}
return u16CRC;
}
But when I execute this code with other polynomial, as 0x1D0F, result is wrong regards on this crc 16 online calculator.
Am I trying to do something impossible ?