EmbeddedRelated.com
Forums
Memfault Beyond the Launch

CRC calculation

Started by janka vietzen February 1, 2007
janka vietzen <janvi@t-online.de> wrote:

> Arlet wrote: > many thanx, i am going to test your code. > > here is my first try with atMega
[snip]
> Assume txbuf contains the 6 byte modbus rtu message: 1,3,0,0,0,2 > the crc should be 0xc40b (what I can see in a old trace record) > but my code calculates 0x98e8 for crc result. Any bugs obvious?
You seem to have mixed up the algorithm from the previous post. Have another look at the algorithm. You are shifting the CRC in the wrong direction (it should be shifted right, not left) and your inner loop structure is wrong: it is supposed to exclusive-OR the polynomial into the result when shifting out a one bit for each of eight bit shift operations. You have it doing eight left shifts then doing a single eor based on the result of the last shift. There may be more errors but I didn't look closely at the rest of it. -- David Empson dempson@actrix.gen.nz
Hi Guys,  this message is too late now , but you may want to consider the
Microchip PIC24F series for your next design.   It has the CRC calculator
built in hardware.   The PIC24F series will save you cycles and code.  
You can find it in Section 19.0 ( page 181) of PIC24FJ128GA006 data sheet 
This is a 64pin device with 128Kbytes flash.  They also have a 28 pin
version w/ 8K ram and 64Kbytes flash sampling in 4-6 weeks with the CRC.  
Good luck. 
Don 

Here is the link to the datasheet on the web.  
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en024813
>janka vietzen <janvi@t-online.de> wrote: > >> Arlet wrote: >> many thanx, i am going to test your code. >> >> here is my first try with atMega > >[snip] > >> Assume txbuf contains the 6 byte modbus rtu message: 1,3,0,0,0,2 >> the crc should be 0xc40b (what I can see in a old trace record) >> but my code calculates 0x98e8 for crc result. Any bugs obvious? > >You seem to have mixed up the algorithm from the previous post. Have >another look at the algorithm. > >You are shifting the CRC in the wrong direction (it should be shifted >right, not left) and your inner loop structure is wrong: it is supposed >to exclusive-OR the polynomial into the result when shifting out a one >bit for each of eight bit shift operations. You have it doing eight left >shifts then doing a single eor based on the result of the last shift. > >There may be more errors but I didn't look closely at the rest of it. > >-- >David Empson >dempson@actrix.gen.nz >

Memfault Beyond the Launch