08-15-2013 07:01 PM
I am currently trying to create a VI that generates 24 bit crc's for bluetooth communication. I think that I have it working properly but I do not have a way to verify the crc is correct since I still have other issues with the bluetooth packet structure. I have attached my VI. The bluetooth polynomial is as follows: x24+ x10+ x9+ x6+ x4+ x3+ x1+ x0
The initial value I have been using is 0x000000
My VI is based on the following C code below. If anyone recommend a way of verifying my crc values, or check that my VI is consistent with how a crc is calculated I would greatly appreciate it.
char
*MakeCRC(
char
*BitString) {
static char
Res[25]; // CRC Result
char
CRC[24];
int
i;
char
DoInvert;
for
(i=0; i<24; ++i) CRC[i] = 0; // Init before calculation
for
(i=0; i<strlen(BitString); ++i) { DoInvert = ('1'==BitString[i]) ^ CRC[23]; // XOR required? CRC[23] = CRC[22]; CRC[22] = CRC[21]; CRC[21] = CRC[20]; CRC[20] = CRC[19]; CRC[19] = CRC[18]; CRC[18] = CRC[17]; CRC[17] = CRC[16]; CRC[16] = CRC[15]; CRC[15] = CRC[14]; CRC[14] = CRC[13]; CRC[13] = CRC[12]; CRC[12] = CRC[11]; CRC[11] = CRC[10]; CRC[10] = CRC[9] ^ DoInvert; CRC[9] = CRC[8] ^ DoInvert; CRC[8] = CRC[7]; CRC[7] = CRC[6]; CRC[6] = CRC[5] ^ DoInvert; CRC[5] = CRC[4]; CRC[4] = CRC[3] ^ DoInvert; CRC[3] = CRC[2] ^ DoInvert; CRC[2] = CRC[1]; CRC[1] = CRC[0] ^ DoInvert; CRC[0] = DoInvert; }
08-15-2013 09:07 PM
Table lookups are faster. I needed CCITT, so I used this c code to create some VIs:
https://github.com/HEROES-GSFC/SAS/blob/master/aspect/lib_crc/lib_crc.c
I'd post the VIs, but I have to think about whether 24 bits will work as is.
08-16-2013 10:57 AM
I was unable to find a look up table for 24 bits with the proper initial value (0x555555). Am I wrong in thinking that the LUT depended both of crc size and initial value?
08-16-2013 03:08 PM
If I understand correctly, the 256 values are a table for each possible Byte (0x00 - 0xFF). You use the same table for each of the two Bytes in a word, four in a long, or three, in your case. It may be easiest to code this for 32 bit, and modify the polynomial accordingly. I'm working through this article: http://www.ross.net/crc/download/crc_v3.txt because I forgot the details.
08-16-2013 03:16 PM
Here's my version of the lib_crc 16 bit CCITT table generation: