crc16
Earl Foster
Posts: 185
Has anybody written code for crc16 (crc-ccitt)·and·is willing to share?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
Comments
The routine calculates the CRC on all data plus the CRC values and returns zero if the data is OK, non-zero on error. I haven't run it for a long time but I believe it was working properly.
Corrected version. Use your own polynomial for init if you like. Init must happen before CRC16 calculation. A demo is enclosed in { } above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
Post Edited (jazzed) : 4/17/2009 10:32:12 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
I think I am using your program incorrectly.· I am assiging "get(...)" to a variable and I am getting the incorrect CRC.· I modified the top to do a simple test and the r = $E415 when it should equal $2348 according to a·online CRC calculator. (http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=000501&method=hex)
Can you set me straight?
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
One thing to note is you would need to pass the value by reference as in: r := get(@value, 3, $ffff) .... still get the wrong value though.
I'll post a corrected and more flexible version sometime today.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
I have tried playing with the code you provided and I am unable to get the correct CRC based on CRC site is use (http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=000501&method=hex).· I am probably using it incorrectly.· I have made some assumptions and adjusted the code:
·- adjust byteloop to fit data size
·- crc_value is the initial value
·- ccitt is the poly
Can you provide guidance?
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
When I was learning how to get the floppy CRC to work, I found lots of variations in how CRCs are calculated. Some routines initialize the crc_value to 0, some to $FFFF, some to some other number. Some implementations invert results at some stage, some don't. And there are lots of different polynomials in use.
Floppy disks seem to initialize the crc_value to 14197 for the crc on the floppy header and to 14192 for the crc that follows the 512 bytes of data, but I've never found any documentation explaining why this is the case.
I'll hack around with your example and see if I can get it to work, and post what I find in a day or so.
David
This is great! You should post it in the obex since there has not been a CRC16 routine until now. Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
It, of course, includes the crc16 code....