Discussions about interfacing and electronics
CRC calculation for an RFID tag
Joined: 24 Sep 2008
|Sep 24, 2008 7:54 pm
|I'm trying to re-program an RFID tag without using the provided reader. I'm using the Texas instruments Tag-it RFID tags. Their protocol is available on their website; I could provide a link if that is permissible.
The protocol defines the CRC as CRC-CCITT, 16 bits, x^16 + x^12 + x^5 + 1, Direction: forward, preset: 0xFFFF, Residue: 0x1D0F. The CRC is complimented after calculation.
I have been trying for a while to match their examples, and so afar have had no luck whatsoever. One of my confusions is that several of the commands have an odd number of bits, such as 57 bits. Should zeros be appended to fill out the first byte?
Here are a few examples and their CRCs I apologize for mixing hex and binary; that's how it's given in the protocol.
CRC: 0x3868 Compliment: 0xC797
0b00 0x01 0b0 0b1 0b0 0x00018B1A 0x02
0b11 0x01 0b0 0b1 0b0 0b0 0x00018B1A 0x02 0b00 0x11F27B45
0b00 0x05 0b0 0b1 0b0 0x00018B1A 0x03 0x0700AAAA
I am not much for coding in C yet, so would appreciate your patience with my limited understandings.
Joined: 30 Oct 2007
Location: London, UK
|Sep 25, 2008 4:05 am
|Hello Scott, welcome to the forum.
|mclaughs wrote: |
|One of my confusions is that several of the commands have an odd number of bits, such as 57 bits. Should zeros be appended to fill out the first byte? |
Yes, and that is it as long as the preset is zero. Otherwise the Init argument of a generic CRC calculator cannot be used on messages with partial bytes, and the user has to manually apply the preset to the message. This is just a matter of XORing the first n bits of the message with the preset.
Eg. for the first example: convert the entire sequence to binary (already done.) XOR the first 16 bits with the preset (0xffff):
Group into bytes, right-aligned:
Then calculate the CRC for the bytes 0x1f 0xf7 0xe2 with polynomial 0x1021, preset 0x0000 (as it is pre-applied) and final inversion 0xffff as specified. This should return the result 0xc797 as given in the manual. When given these bytes the Calculator page returns the complemented CRC, 0x3868, under the heading "CRC-CCITT (XModem)".
| 11111 11110111 11100010 |
For reference, the Rocksoft(tm) record for the algorithm is:
(For an explanation of this record, see A Painless Guide to CRC Error Detection Algorithms.) (Search for filename "crc_v3.txt".)
| Name : "CRC-16/I-CODE"
Width : 16
Poly : 1021
Init : FFFF
RefIn : False
RefOut : False
XorOut : FFFF
Check : D64E
(For a generic implementation in C, see A Painless Guide or the Calculator page.)
The algorithm is related to XMODEM and "false" CRC-CCITT except the preset and final XOR are both 0xffff.
Running on php BB © 2001, 2009 php BB Group