From: David Empson on 3 Feb 2007 08:47 janka vietzen <janvi(a)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(a)actrix.gen.nz |