PDA

View Full Version : CRC Calculations



timmers
- 15th June 2009, 23:30
Trying to work out comms for the Maxon Motor controllers. We need to send a CRC code at the end of a frame. Anyone got any sugestions how to calculate this. Even my teenage kids don't get this one!

Extract from data sheet:
The algorithm used is CRC-CCITT. The CRC
calculation includes all bytes of the frame. The data bytes have to be
calculated as a word. At first you have to shift in the high byte of the data
word. This is the opposite way you transmit the data word.
The 16-bit generator polynomial ‘x16+x12+x5+1’ is used for the calculation.
Packet M(x): WORD DataArray[n]
Generator Polynom G(x): 10001000000100001 (= x16+x12+x5+x0)
DataArray[0]: HighByte(OpCode) + LowByte(len-1);
DataArray[1]: data[0]
DataArray[2]: data[1]

DataArray[n-1]: 0x0000 (ZeroWord)

So in their example
ReadObject ‘SoftwareVersion’ (Index = 0x2003, SubIndex = 0x01)
OpCode len-1 data[0] data[1] CRC
0x10 0x01 0x2003 0x0201 0xA888
OpCode: 0x10 = ReadObject
Len-1: 0x01 = 2 Words
data[0]: 0x2003 = Index
LowByte data[1]: 0x01 = SubIndex
HighByte data[1]: 0x02 = Node-ID
Transmission Order: 0x10,0x01,0x03,0x20,0x01,0x02,0x88,0xA8

How did they calculate the CRC to be $A888
Adding all the bytes up comes to $2215
Any sugestions how to calculate the CRC most welcome.

Tim.

GoldStar
- 16th June 2009, 17:10
I can't really follow the pseudo code written but what happens if you add the 2 byte "words"?