tags:

views:

688

answers:

3

Hi, I am working with a device that requires me to generate a 16 bit CRC.

The datasheet for the device says it needs the following CRC Definition:

CRC Type    Length    Polynomial           Direction  Preset      Residue
CRC-CCITT   16 bits   x16 + x12 + x5 + 1   Forward    FFFF (16)   1D0F (16)

where preset=FFFF (16 bit) and Residue=1D0F (16 bit)

I searched for a CRC algorithm and found this link: http://www.lammertbies.nl/comm/info/crc-calculation.html

It has both on it. CRC-CCITT (0xFFFF) CRC-CCITT (0x1D0F)

What's the difference between the preset and the residue?

A: 

The difference is in what the algorithm does with the two values. I just looked at a CRC algorithm myself and it looks pretty simple.

Preset is the value it starts with and residue is XOR'd with the value at the end.

Now, the reason for choosing particular values for preset and residue, that I don't know.

Zan Lynx
A: 

Something's not right here.

You're looking for a 16-bit CRC, but you've specified a 24-bit Preset and Residue. Post a link to the datasheet for the device you're looking at.

The best source for CRC information is, by the way, is Ross Williams' guide to CRC.

edit: Ah-hah, I see the "24-bit" preset was just the formatting of the table.

XPav
+2  A: 

You initialize the CRC register with the preset before feeding in your message.

The residue is what should be left in the CRC register after feeding through a message, plus its correct CRC.

If you just want to send a message, you won't see the residue value. But when the device runs your message+CRC through the CRC algorithm again, it'll see a final value of 0x1D0F if there were no transmission errors.


You can also demonstrate this to yourself without getting the device involved. This can help you confirm that your algorithm is doing something that, at least, resembles a CRC.

  • First, calculate the CRC for your message.
  • Append your message and that CRC, then pass the whole thing through a new CRC calculation (remember to reset to the preset value first.)
  • If all went well, your CRC register should contain the residue value.


The best CRC explanation I've ever found is here:

http://www.repairfaq.org/filipg/LINK/F_crc_v31.html#CRCV_001

Harry Tsai