07-20-2016 02:52 AM
@jay0909 wrote:
[...] HOw is it different from labview implementation?
You should be able to answer that by yourself.
Hint: The C code is for example using a different mask compared to all webpages i searched during trying to answer your questions. It also shifts the data by a different amount of bits.
However, there are multiple implementations for CRC32 (even ones without a table) so it still could be a valid implementation.
My guess is that the C code has a typo in the table as LV AND external CRC calculators result in a different CRC compared to the one of your controller.
Norbert
07-20-2016 05:15 AM
So, what i shld do now for calculating proper crc? Any suggestions?
07-20-2016 05:55 AM
Well, you stated a frame in your initial post with an expected CRC32. The VIs I linked do calculate exactly this expected behavior for that frame, just like the webpage with the calculator I linked.
A couple of posts before this one, you posted another frame where the online calculator as well as VIs do result in a different CRC32 compared to what you get from the controller. However, the LV and online results are identical.
So either your controller messes things up (as i said, i guess it's a typo in the table) or both LV and online calculator implementation are incorrect.
You might want to find additional calculators for CRC32 to verify the results of LV and the online calculator. With that information, you might be able to identify WHICH one is incorrect.
However, you then have to debug things to find out WHY it is incorrect.
Hint: If the calculator is using a table i would first check all 256 table entries for typos.
Norbert
07-20-2016 06:40 AM
Reminds me that I once worked for a company that implemented an old, proprietary crc calc. It was very similar, but with slightly different numbers in the table. It was used only in one old ICD, but because it worked and it would have been a PITA to change throughout their product line, they let it be. Of course, it's called out in the ICD as the industry standard crc and I went through something very similar to this thread until someone happened by and told me, "Oh, the document is wrong". Apparently this little tidbit of information was known throughout the company, but only by word of mouth.
Thanks a lot.
07-20-2016 09:24 AM
Hi,
After some research i found that the implemenatation of UART and calculation of the CRC is from the below link.
http://pubs.opengroup.org/onlinepubs/009695299/utilities/cksum.html
This is the same implementation in labview as well, but why i get different crc.
07-20-2016 10:47 AM
By George I think I got it. It works for the two test cases that the OP provided.
07-20-2016 11:19 AM
I think there is a bug when the Length is greater than 256. It looks like the C-Code extends the sequence using Least Significant Byte first. I don't have any large data test cases that I can run, so the "reverse 1D Array" may need to be deleted.
07-21-2016 02:57 AM
HI,
what's the value length of sequence in bytes for this sequence "1C0000009DE50200040400000000000000"?
I gave 34 and tried your example but it resuts in wrong crc?
07-21-2016 06:38 AM
@jay0909 wrote:HI,
what's the value length of sequence in bytes for this sequence "1C0000009DE50200040400000000000000"?
I gave 34 and tried your example but it resuts in wrong crc?
Technically the spec says "octets". (I believe) the definition of an "octet" is 8 bits, whereas "bytes" is machine dependant. 99.99% of the time 1 byte = 8 bits, so octets equals bytes.
For your sequence there are 17 bytes. (34 is the number of nibbles)
p.s., Do you have a sequence that is longer than 256 bytes?? My snippet may have a bug and I would like to verify that. It appends the sequence with the number of bytes as big endian. I believe it is sppose to be little endian.
07-21-2016 07:04 AM
Hi,
The maximum number of bytes is 117. below is the frame.
1500 0000 73A1 0000 0468 0000 0000 0000 0042 02F5 C342 0400 007F FFFF FF3E E76C 8B3C 1374 BC42 4AF0 A444 2566 6642 480F 5C43 6D44 DC42 9CCC 9B42 9ECE 4442 9EEE DAC0 D9D1 F6BE CE63 BBBF 1A27 B1BF 84A4 9E3E A9F4 383E AC67 9E3E AC11 7A43 6C00 8343 6B87 F043 6B9B 23FF FFFF FF7F FFFF FF7F FFFF FF
CRC of the above frame : 4705 C23C
Calculation from your program is : EB6E7573.