# CRC check

Hi,

I have programmed my openIMU300ZA with INS application, the output packet is e2, 123bytes of payload, I need your help to check CRC bytes. do you have any sample code to check CRC of e2 packet?

Best regards,
Amin.

Hi,

from PDF downloaded from this link : https://readthedocs.org/projects/openimu/downloads/pdf/latest/

3.6 16-bit CRC-CCITT
Packets end with a 16-bit CRC-CCITT calculated on the entire packet excluding the 0x5555 header and
the CRC field itself. A discussion of the 16-bit CRC-CCITT and sample code for implementing the
13.4. OpenIMU UART Messaging Framework 127
OpenIMU Documentation
computation of the CRC is included at the end of this document. This 16-bit CRC standard is maintained
by the International Telecommunication Union (ITU). The highlights are:
Width = 16 bits
Polynomial 0x1021
Initial value = 0xFFFF
No XOR performed on the final value.
See Appendix A for sample code that implements the 16-bit CRC algorithm.

but there is no Appendix A and there is no example code at the end of file.

Best regards,
Amin.

from crc16.c :

uint16_t CalculateCRC (uint8_t *buf, uint16_t length)
{
uint16_t crc = 0x1D0F; //non-augmented inital value equivalent to the augmented initial value 0xFFFF

``````for (int i=0; i < length; i++) {
crc ^= buf[i] << 8;

for (int j=0; j<8; j++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
}
else {
crc = crc << 1;
}
}
}

return ((crc << 8 ) & 0xFF00) | ((crc >> 8) & 0xFF);
``````

}

may I use this code to compare received bytes count and CRC bytes?

Best regards,
Amin.

There is example code in the open source python driver

There also example code in the open source C++ driver

There is finally embedded C-code in the open imu library source itself