View previous topic :: View next topic |
Author |
Message |
MCU Luüfter
Joined: 13 Jun 2011 Posts: 6
|
16-bit CRC using generate_16bit_crc() |
Posted: Mon Jun 13, 2011 5:08 am |
|
|
Hi all,
I am using the 16-bit CRC available in \PICC\Drivers\
and I need your experience.
In fact I am checking the result of CRC usign the following online tool:
http://depa.usst.edu.cn/chenjq/www2/software/crc/CRC_Javascript/CRCcalculation.htm
and my code is:
Code: |
int16 My16bitsData[] = {0x1122};
int16 computed16bitscrc = 0;
computed16bitscrc = generate_16bit_crc(My16bitsData, 2, 0x8005); |
Using the online I get 0x66CC.
But using the generate_16bit_crc() I get 0xCC66.
As you can see, the LSB and MSB are swapped !!!
Is there an explanation for this?
I am a little bit lost and thank you for your help.
MCU Lüfter |
|
![](templates/subSilver/images/spacer.gif) |
MCU Luüfter
Joined: 13 Jun 2011 Posts: 6
|
|
Posted: Mon Jun 13, 2011 4:58 pm |
|
|
Thank you !!
I get it running ...
I have to change
int16 My16bitsData[] = {0x1122};
to
int8 My16bitsData[] = {0x11, 0x22};
Ciao |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Tue Jun 14, 2011 2:00 am |
|
|
Or just reverse the bytes.
Key here is _byte order_. When you type 0x1122, this is a 16bit value, with the LSB to the right. The PIC puts the LSB into the low byte in memory, so will store the value internally as 0x22, 0x11. When you define the int8 array, you are loading this with the 0x11 first, so you store 0x11, 0x22.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jun 14, 2011 9:33 am |
|
|
If you want to use CRC16 with the standard polynomial 0x8005, then it is possible to use the highly optimized implementation from the Code Library. |
|
![](templates/subSilver/images/spacer.gif) |
|