Use CLRC663 to read HID iClass UID

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use CLRC663 to read HID iClass UID

3,447 Views
henry_w
Contributor I

Hi,

I am able to use CLRC663 to read the iso14443 card uid easily. However, there is no response from HID iClass card which assumed to be compiled with iso15693. All I need is the uid of the card. The CLRC663 chip is connected to a stm32 uC using I2C interface. I attached the code I am using below. Please help me to have a look and kindly provide your suggestions. Thanks.

clrc630_write_reg(0x37, 0xFF); //Selects minimum threshold level for the bit decoder

//load 15693 protocol
clrc630_write_reg(0x0F, 0x98); //config T0
clrc630_write_reg(0x14, 0x92); //config T1
clrc630_write_reg(0x19, 0x20); //config T2 for LFO autotrim
clrc630_write_reg(0x1A, 0x03); //T2 reload value for LFO AutoTrimm
clrc630_write_reg(0x1B, 0xFF);
clrc630_write_reg(0x1E, 0x00); // Configure T3 (for LPCD/ AutoTrimm)

clrc630_write_reg(0x02, 0x90); // Set FiFo-Size and Waterlevel
clrc630_write_reg(0x03, 0xFE);

clrc630_write_reg(0x0C, 0x80); // Init. RxBitCtrl register
clrc630_write_reg(0x28, 0x80); // TxMode register
clrc630_write_reg(0x29, 0x00); // TxAmp register
clrc630_write_reg(0x2A, 0x01); // TxCon register
clrc630_write_reg(0x2B, 0x05); // Init. TxI register
clrc630_write_reg(0x34, 0x00); // Init RxSOFD register
clrc630_write_reg(0x38, 0x12); // Init. RCV register

clrc630_write_reg(0x00, 0x00);
clrc630_write_reg(0x02, 0xB0);
clrc630_write_reg(0x06, 0x7F);
clrc630_write_reg(0x07, 0x7F);

// write in iso15693 protocol params
clrc630_write_reg(0x05, 0x0A);
clrc630_write_reg(0x05, 0x0A);
clrc630_write_reg(0x08, 0x10); // Enable IRQ0, IRQ1 interrupt sources
clrc630_write_reg(0x09, 0x40);
clrc630_write_reg(0x00, 0x0D); // Execute Rc663 command: "Load protocol"
while (!(clrc630_read_reg(0x07)&0x40));

clrc630_write_reg(0x08, 0x00); //disable irq0 and irq1
clrc630_write_reg(0x09, 0x00);

clrc630_write_reg(0x02, 0xB0);

// apply register set
clrc630_write_reg(0x2C, 0x7B);
clrc630_write_reg(0x2D, 0x7B);
clrc630_write_reg(0x2E, 0x08);
clrc630_write_reg(0x2F, 0x00);
clrc630_write_reg(0x30, 0x00);
clrc630_write_reg(0x31, 0x00);
clrc630_write_reg(0x33, 0x0F);
clrc630_write_reg(0x35, 0x02);
clrc630_write_reg(0x37, 0x4E);
clrc630_write_reg(0x39, 0x04);
clrc630_write_reg(0x36, 0x8C); // Set the RxWait register
clrc630_write_reg(0x31, 0xC0);
clrc630_write_reg(0x32, 0x00);

// write timer0 and timer1 reload value
clrc630_write_reg(0x10, 0x18); // tim0
clrc630_write_reg(0x11, 0x86);
clrc630_write_reg(0x15, 0x00); // tim1
clrc630_write_reg(0x16, 0x00);
clrc630_write_reg(0x29, 0x0A);
clrc630_write_reg(0x28, 0x81);
clrc630_write_reg(0x0B, 0x00); // Disable MIFARE Crypto1

// field on
clrc630_write_reg(0x28, 0x89);

// activated card
clrc630_write_reg(0x10, 0x24); // set timeout tim0 and tim1 reload values
clrc630_write_reg(0x11, 0xEB);
clrc630_write_reg(0x15, 0x00);
clrc630_write_reg(0x16, 0x00);

clrc630_write_reg(0x00, 0x00);
clrc630_write_reg(0x02, 0xB0);
clrc630_write_reg(0x06, 0x7F);
clrc630_write_reg(0x07, 0x7F);

clrc630_write_reg(0x05, 0x36); //send the "uid request command"
clrc630_write_reg(0x05, 0x01);
clrc630_write_reg(0x05, 0x00);
clrc630_write_reg(0x05, 0x00);
clrc630_write_reg(0x00, 0x07);

clrc630_write_reg(0x08, 0x18); //IdleIRQEn and TxIRQEn
clrc630_write_reg(0x09, 0x02); //IRQPinEN and Timer1IRQEn
while (!(clrc630_read_reg(0x07)&0x40));

clrc630_write_reg(0x08, 0x00); //disable irq0 and irq1
clrc630_write_reg(0x09, 0x00);

uint8_t irq0 = clrc630_read_reg(0x06);
uint8_t irq1 = clrc630_read_reg(0x07);
if ((!(irq0 & CLRC630_IRQ0_RX_IRQ)) || (irq0 & CLRC630_IRQ0_ERR_IRQ)) {
CLRC630_PRINTF("No RX, irq1: %x irq0: %x\n", irq1, irq0);
return;
}

uint8_t buf[10]; // Size is maximum of 10 bytes
uint8_t len = clrc630_read_reg(0x04);//read FIFO length
for (int i = 0; i < len; i++) {
buf[i] = clrc630_read_reg(0x05); // Read FIFO,Expected - Complete UID (one PICC in HF)
}

CLRC630_PRINTF("%d bytes UID: ", len);
clrc630_print_block(buf, len);
CLRC630_PRINTF("\n");

Tags (2)
0 Kudos
7 Replies

2,693 Views
minabf61
Contributor III

Hi Henry, I am struggleing to read ISO 14443 UID.  I could read ATQA but can not figure out how to read UID. Would you mind sharing your code here? Many thanks in advance. 

0 Kudos

2,693 Views
sb2
Contributor II

Dear Mina

Are you using theNFC Libray or are you writing directly to the CLRC663 ?

I'm using a Mícrochip PIC18 connected to the via SPI.

The below is the function I use to retrieve the UID from both 4 and 7 byte transponders - I have added the support for 7 byte UID - the rest is not my work.

case 6: // Select card and retrive full UID
{ // int Clrc663::iso_14443A_select(uint8_t *uid)
// Get UID, Apply cascade level-1
WriteSPI(RC663_TxDataNum, 0x08); //BIT3 If cleared - it is possible to send a single symbol pattern.If set - data is sent.
WriteSPI(RC663_RxBitCtrl, 0x00); //
WriteSPI(RC663_Command, RC663_Idle); // Terminate any running command.
WriteSPI(RC663_FIFOControl, 0xB0); // Flush_FiFo

WriteSPI(RC663_IRQ0, 0x7F); // Clear all IRQ 0,1 flags
WriteSPI(RC663_IRQ1, 0x7F); //

WriteSPI(RC663_FIFOData, 0x93); //Write "Anticollision CL1" cmd into FIFO (SEL=93, NVB=20,cascade level-1)
WriteSPI(RC663_FIFOData, 0x20); // 4 Byte UID CL1
WriteSPI(RC663_Command, RC663_Transceive); //Start tranceive command
RC663IrqWait(0x18, 0x2); // Wait for idle, tx, or timer1

len = ReadSPI(RC663_FIFOLength); //read FIFO length
if (len != 5)
return 0x01; // No transponder

for (int i = 0; i < len; i++)
{
RC663.buffer[i+2] = ReadSPI(RC663_FIFOData); // Read FIFO,Expected - Complete UID (one PICC in HF)
}
//now we got UID ,we continue to use this UID to select the card
//this command needs CRC appended
WriteSPI(RC663_TxCrcPreset, 0x19); // Preset value is6363,use crc16,crc is apended to the data stream
WriteSPI(RC663_RxCrcPreset, 0x19); //

WriteSPI(RC663_Command, RC663_Idle); // Terminate any running command.
WriteSPI(RC663_FIFOControl, 0xB0); // Flush_FiFo

WriteSPI(RC663_FIFOData, 0x93); // Write "Select CL1" cmd into FIFO (0x93 / 0x70)
WriteSPI(RC663_FIFOData, 0x70); //

for (int i = 0; i < len; i++) //
{
WriteSPI(RC663_FIFOData, RC663.buffer[i+2]); // Add UID0-UID3 + BCC or CT + UID0-UID2 + BCC
}

WriteSPI(RC663_Command, RC663_Transceive); //Start tranceive command ,expecting to receive SAK ,select acknowlegement
RC663IrqWait(0x18, 0x2); // Wait for idle, tx, or timer1
len = ReadSPI(RC663_FIFOLength); // Read FIFO length -> should be 0x01 for SAK returned

if (len == 0x01)
RC663.SAK = ReadSPI(RC663_FIFOData);// Read FIFO,Expecting SAK, here wo should next level of anti-collision
else
return 0x01; // No transponder

if ((RC663.SAK & 0x04) == 0x00) // SAK's bit2=0,then UID is complete
{
for (int i = 0; i < 4; i++)
{
RC663.UID[i] = RC663.buffer[i+2]; // Save UID (4 bytes))
}
RC663.UIDlen = 4; // Save UID length
return 0x00; // Transponder succesfully selected
}
// if SAK's bit2=1,then UID is not finished yet
if ((RC663.SAK & 0x04) == 0x04) // Cascade level-2
{
Delay(1); // Wait 1 ms before sending data again - Request Guard Time > 0,5 ms
WriteSPI(RC663_TxCrcPreset, 0x18); // Preset value is6363,use crc16,crc is _NOT_ appended to the data stream
WriteSPI(RC663_RxCrcPreset, 0x18); //

WriteSPI(RC663_Command, RC663_Idle);// Terminate any running command.
WriteSPI(RC663_FIFOControl, 0xB0); // Flush_FiFo

WriteSPI(RC663_IRQ0, 0x7F); // Clear IRQ0 flags
WriteSPI(RC663_IRQ1, 0x7F); // Clear IRQ1 flags

WriteSPI(RC663_FIFOData, 0x95); // Write "Anticollision CL2" cmd into FIFO (SEL=95 NVB=20,cascade level-2)
WriteSPI(RC663_FIFOData, 0x20); // 7 Byte UID CL2
WriteSPI(RC663_Command, RC663_Transceive); //Start tranceive command
RC663IrqWait(0x18, 0x2); // Wait for idle, tx, or timer1

len = ReadSPI(RC663_FIFOLength); //read FIFO length
if (len != 5)
return 0x01; // No transponder

for (int i = 0; i < len; i++)
{
RC663.buffer[i+7] = ReadSPI(RC663_FIFOData); // Read FIFO,Expected - Last part of UID (one PICC in HF)
}

//now we got UID ,we continue to use this UID to select the card
//this command needs CRC appended
WriteSPI(RC663_TxCrcPreset, 0x19); //preset value is6363,use crc16,crc is apended to the data stream
WriteSPI(RC663_RxCrcPreset, 0x19); //

WriteSPI(RC663_Command, RC663_Idle);// Terminate any running command.
WriteSPI(RC663_FIFOControl, 0xB0); // Flush_FiFo

WriteSPI(RC663_FIFOData, 0x95); // Write "Select CL2" cmd into FIFO (0x95 / 0x70)
WriteSPI(RC663_FIFOData, 0x70); //

for (int i = 0; i < len; i++)
{
WriteSPI(RC663_FIFOData, RC663.buffer[i+7]); // Add CT + UID0-UID2 + BCC
}

WriteSPI(RC663_Command, RC663_Transceive); //Start tranceive command ,expecting to receive SAK ,select acknowlegement
RC663IrqWait(0x18, 0x2); // Wait for idle, tx, or timer1
len = ReadSPI(RC663_FIFOLength); //read FIFO length

if (len == 0x01)
RC663.SAK = ReadSPI(RC663_FIFOData);// Read FIFO,Expecting SAK,here wo should next level of anti-collision
else
return 0x01; // No transponder

if ((RC663.SAK & 0x04) == 0x00) // SAK's bit2=0,then UID is complete
{
for (int i = 0; i < 3; i++)
{
RC663.UID[i] = RC663.buffer[i+3]; // Save UID (3 bytes))
}
for (int i = 3; i < 7; i++)
{
RC663.UID[i] = RC663.buffer[i+4]; // Save UID (4 bytes))
}
RC663.UIDlen = 7; // Save UID length
return 0x00; // Transponder succesfully selected
}
Nop();
}

break;
}

Regards

Søren

0 Kudos

2,693 Views
mina_farah
Contributor II

Thanks Soren for sharing your code.

Update- I finally made it work using the code here:

GitHub - iwanders/MFRC630: A library for NXP's MFRC630 NFC IC. 

However, there was only some lines missing in this code(At least for my case) which I added and then that was it. The problem was the RF field needed to get on before recognising the card and  also I loaded the protocol and rx and tx speed (AN1657 for reference).

Regards,

2,693 Views
Jonathan_Iglesias
NXP TechSupport
NXP TechSupport

Hello Guys, Please check the following script, 

BR

Jonathan

0 Kudos

2,693 Views
s_
Contributor I

Hello Henry,

i am forcing with the same problem. 

Did you solve the problem with Hid hid numbers and nxp chips?

best regards 

Gunther

0 Kudos

2,693 Views
henry_w
Contributor I

Hi Gunther,

Not yet. As I said, all I need is the UID. So if iClass card is a ISO 15693 type, it should respond to the above script. Are you using a similar script? Does your iClass card respond in any way?

Best regards

Henry

0 Kudos

2,693 Views
s_
Contributor I

Hi Henry,

We do not get any respond yet.

Best regards

Gunther

0 Kudos