// https://forum.arduino.cc/t/crc16-xmodem-woes/1426398
byte message2[] = {0xFE, 0x0B, 0x01, 0x01, 0x01, 0x14, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x54, 0x66 };
unsigned int CRC16(unsigned char *ptr,unsigned int count)
{
unsigned int crc=0;
unsigned char i;
while (count>0)
{count--;
crc=(crc^(((unsigned int)*ptr)<<8));
for(i=0;i<8;i++)
{
if(crc&0x8000)crc= ((crc<<1)^0x1021);
else crc<<=1;
}
ptr++;
}
return crc;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("CRC Test");
uint16_t c = CRC16(message2,sizeof(message2)-2);
message2[sizeof(message2)-2]=highByte(c);
message2[sizeof(message2)-1]=lowByte(c);
Serial.print("Array: ");
for (int i = 0 ; i < sizeof(message2); i++){
Serial.print(message2[i],HEX);Serial.print(" , ");
}
}
void loop() {
// put your main code here, to run repeatedly:
}