Computer Interfacing
Discussions about interfacing and electronics
 

CRC calculation for an RFID tag


 

       Computer Interfacing Forum Index -> Error detection and correction
Author Message
mclaughs
New User



Joined: 24 Sep 2008
Posts: 1


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.

000000000100000000010
CRC: 0x3868 Compliment: 0xC797

0b00 0x01 0b0 0b1 0b0 0x00018B1A 0x02
CRC: 0xDA39

0b11 0x01 0b0 0b1 0b0 0b0 0x00018B1A 0x02 0b00 0x11F27B45
CRC: 0xC0C1

0b00 0x05 0b0 0b1 0b0 0x00018B1A 0x03 0x0700AAAA
CRC: 0xC4C7

I am not much for coding in C yet, so would appreciate your patience with my limited understandings.

Thank you,
-Scott McLaughlin
regregex
Preferred Member



Joined: 30 Oct 2007
Posts: 184
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):
Code:
000000000100000000010
1111111111111111      XOR
---------------------
111111111011111100010
Group into bytes, right-aligned:
Code:
   11111 11110111 11100010
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)".

For reference, the Rocksoft(tm) record for the algorithm is:
Code:
   Name   : "CRC-16/I-CODE"
   Width  : 16
   Poly   : 1021
   Init   : FFFF
   RefIn  : False
   RefOut : False
   XorOut : FFFF
   Check  : D64E
(For an explanation of this record, see A Painless Guide to CRC Error Detection Algorithms.) (Search for filename "crc_v3.txt".)
(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.

HTH.

Greg

       Computer Interfacing Forum Index -> Error detection and correction
Page 1 of 1



Running on php BB © 2001, 2009 php BB Group
   Lammert Bies     Interfacing     Sitemap     Forum