How can I calculate the CRC? Documentation Category

This page contains documentation, downloads, firmware, and support materials for this product or topic.

Choose a different product/topic



More Info

The calculation of the CRC is illustrated in the function below.  The “preset” value for CRC calculations is 0x0000.  More calculation functions can also be found in a file called CRC.c, which is located in the SkyeWare4 (or SkyeWare v3) install package.   This package can be downloaded from the support portal under API’s.

For simpler calculation you can also download an example SkyeTek CRC Generator C# project and executable application here.

 

NOTE:  In both SkyeTek Protocol v2 and v3, the crc is calculated across all data except the initiator and terminator bytes.

unsigned short crc16(unsigned short preset, unsigned char *dataP, unsigned short n)

{

unsigned short i; // byte counter

unsigned char j;    // bit counter

unsigned short crc_16;    /* calculation */

 

crc_16 = preset;         /* PRESET value */

 

for(i = 0; i < n; i++)

{

crc_16 ^= *dataP++;

 

for(j = 0; j < 8; j++) /* test each bit in the byte */

{

if(crc_16 & 0x0001)

{

crc_16 >>= 1;

crc_16 ^= 0x8408;

}

else

crc_16 >>= 1;

 

}

 

}

 

return(crc_16);  /* returns calculated crc (16 bits) */

}






← Return to Documentation Search