CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16-bit CRC using generate_16bit_crc()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCU Luüfter



Joined: 13 Jun 2011
Posts: 6

View user's profile Send private message Send e-mail

16-bit CRC using generate_16bit_crc()
PostPosted: Mon Jun 13, 2011 5:08 am     Reply with quote

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
MCU Luüfter



Joined: 13 Jun 2011
Posts: 6

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 13, 2011 4:58 pm     Reply with quote

Thank you !!
I get it running ...
I have to change
int16 My16bitsData[] = {0x1122};
to
int8 My16bitsData[] = {0x11, 0x22};

Ciao
Ttelmah



Joined: 11 Mar 2010
Posts: 19568

View user's profile Send private message

PostPosted: Tue Jun 14, 2011 2:00 am     Reply with quote

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
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 14, 2011 9:33 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group