RFID Click example not working

General discussion on mikroC PRO for PIC.
Author
Message
saharul
Posts: 489
Joined: 08 Jul 2010 08:11

RFID Click example not working

#1 Post by saharul » 22 Jan 2014 07:54

Dear All,

Could someone please share what is the common problem and solution with RFID click .I run RFID example program to read from RFID card but it doesn't read anything and no beep sound. if the card is new does it contain datas?

Thanks
Last edited by saharul on 29 Jan 2014 13:42, edited 1 time in total.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: RFID Click example not working

#2 Post by filip » 22 Jan 2014 13:56

Hi,

Please, can you tell me which hardware and code example are you using ?

Regards,
Filip.

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#3 Post by saharul » 22 Jan 2014 20:29

thanks filip.

i bought RFID CLICK and RFID reader. i try both examples (with EASYPIC 7)from mikroelektronika web.below is the code for RFID click.

Code: Select all

/*
 * Project name:
     RFid Click (using CR95HF contactless transceiver)
 * Copyright:
     (c) Mikroelektronika, 2013.
 * Revision History:
     20130624:
       - initial release (DO);
 * Description:
     This is a sample program which demonstrates the use of the ST's
     CR95HF contactless transceiver. The CR95HF is used in the applications such 
     as near field communication (NFC) using 13.56 MHz wireless interface.
     In this example, when the RFid tag is put over the RFid Click antenna, 
     the tag ID will be displayed on the Lcd display and sent via UART module.
 * Test configuration:
     MCU:             PIC18F45K22
                      http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
     Dev.Board:       EasyPIC v7
                      http://www.mikroe.com/easypic/
     Oscillator:      HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
     Ext. Modules:    RFid Click Board - ac:RFid_Click
                      http://www.mikroe.com/click/rfid/
     SW:              mikroC PRO for PIC
                      http://www.mikroe.com/mikroc/pic/
 * NOTES:
     - Place RFid click board in the mikroBUS socket 1 on the EasyPIC v7 board.
     - Place Lcd display in the Lcd display socket and turn on the backlight using the switch SW4.6
     - Short connect RE1 with VCC pin on port headers using jumperwire
 */

// CR95HF Commands Definition
#define    IDN                    0x01
#define    ProtocolSelect         0x02
#define    SendRecv               0x04
#define    Idle                   0x07
#define    RdReg                  0x08
#define    WrReg                  0x09
#define    BaudRate               0x0A
#define    ECHO                   0x55

// RFID Click Connections
sbit SSI_1  at LATA.B2;
sbit SSI_0  at LATE.B1;
sbit IRQ_IN at LATC.B0;
sbit CS     at LATE.B0;

sbit SSI_1_Direction  at TRISA.B2;
sbit SSI_0_Direction  at TRISE.B1;
sbit IRQ_IN_Direction at TRISC.B0;
sbit CS_Direction     at TRISE.B0;
// End RFID Click module connections

// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End Lcd module connections

unsigned short sdata[18];
unsigned short rdata[18];
unsigned short res = 0, dataNum = 0;
unsigned short j = 0, tmp = 0;
char ID[10] = {0};
char txt_hex[3];

// Write command to the CR95HF
void writeCmd(unsigned short cmd, unsigned short dataLen){
  unsigned short i = 0;
  
  CS = 0;
  SPI1_Write(0x00);  // Send cmd to CR95HF
  SPI1_Write(cmd);
  SPI1_Write(dataLen);
  while (dataLen == 0){
    CS = 1;
    break;
  }
  for(i=0; i<dataLen; i++){
    SPI1_Write(sdata[i]);
  }
  CS = 1;
}

// Poll the CR95HF
void readCmd(){
  unsigned short i = 0;

  while(1){
    CS = 0;
    SPI1_Write(0x03);
    res = SPI1_Read(0);
    CS = 1;

    if((res & 0x08) >> 3){
      CS = 0;
      SPI1_Write(0x02);
      res = SPI1_Read(0);
      dataNum = SPI1_Read(0);
      for(i=0; i<dataNum; i++)
        rdata[i] = SPI1_Read(0);
      CS = 1;
      break;
    }
    CS = 1;
    Delay_ms(10);
  }
}

// Calibrate CR95HF device
void Calibration() {
  //TFT_Write_Text("Calibrating CR95HF...", 55, 100);
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x00;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0xFC;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x7C;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x3C;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x5C;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x6C;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x74;
  writeCmd(Idle, 0x0E);
  readCmd();

  sdata[11] = 0x70;
  writeCmd(Idle, 0x0E);
  readCmd();
}

// Select the RF communication protocol (ISO/IEC 14443-A)
void Select_ISO_IEC_14443_A_Protocol() {
  sdata[0] = 0x02;
  sdata[1] = 0x00;
  writeCmd(ProtocolSelect, 2);
  readCmd();

  // Clear read and write buffers
  for(j=0; j<18; j++ ){
    rdata[j] = 0;
    sdata[j] = 0;
  }
}

// Configure IndexMod & Gain
void IndexMod_Gain() {
  sdata[0] = 0x09;
  sdata[1] = 0x04;
  sdata[2] = 0x68;
  sdata[3] = 0x01;
  sdata[4] = 0x01;
  sdata[5] = 0x50;
  writeCmd(WrReg, 6);
  readCmd();
}

// Configure Auto FDet
void AutoFDet() {
  sdata[0] = 0x09;
  sdata[1] = 0x04;
  sdata[2] = 0x0A;
  sdata[3] = 0x01;
  sdata[4] = 0x02;
  sdata[5] = 0xA1;
  writeCmd(WrReg, 6);
  readCmd();
}

// Read the tag ID
char GetNFCTag() {
  sdata[0] = 0x26;
  sdata[1] = 0x07;
  writeCmd(SendRecv , 2);
  readCmd();

  sdata[0] = 0x93;
  sdata[1] = 0x20;
  sdata[2] = 0x08;
  writeCmd(SendRecv , 3);
  readCmd();

  if(res == 0x80) {
    for( j = 1; j < dataNum - 3; j++) {
      ByteToHex(rdata[j], txt_hex);
      strcat(ID, txt_hex);
      LATD.B0 = 1;
    }
    ID[10] = 0;
    return 1;
  }
  else
  {
    LATD.B0 = 0;
    return 0;
  }
}

// Initialize MCU and peripherals
void MCU_Init(){
  // Configure RFid Click pins
  ANSELA = 0;
  ANSELB = 0;
  ANSELC = 0;
  ANSELD = 0;
  ANSELE = 0;
  SLRCON = 0;
  
  CS_Direction = 0;
  IRQ_IN_Direction = 0;
  SSI_0_Direction  = 0;
  SSI_1_Direction  = 0;
  
  IRQ_IN = 1;
  CS = 1;
  // Set in SPI mode + Jumper wire workaround required, see header notes
  SSI_1 = 0;
  SSI_0 = 1;
  // Initialize SPI module
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
  UART1_Init(9600);
  Lcd_Init();                           // Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR);                  // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);             // Cursor off
  Lcd_Out(1,1,"RFid example");          // Write text in first row
  UART1_Write_Text("RFid example\r\n");
}

// Get Echo reponse from CR95HF
char EchoResponse() {
  CS = 0;
    SPI1_Write(0x00);  // Send cmd to CR95HF
    SPI1_Write(ECHO);
  CS = 1;
  while(1){
    CS = 0;
      SPI1_Write(0x03);
      tmp = SPI1_Read(1);
    CS = 1;

    if((tmp & 0x08) >> 3){
      CS = 0;
      SPI1_Write(0x02);
      tmp = SPI1_Read(1);
      CS = 1;
      if(tmp == ECHO){
        return 1;
      }
      return 0;
    }
  }
}

void main() {
  MCU_Init();                           // Initialize MCU and peripherals
  while (!EchoResponse()) {             // Until CR95HF is detected
    IRQ_IN = 0;                         //   put IRQ_IN pin at low level
    Delay_ms(10);
    IRQ_IN = 1;                         //   put IRQ_IN pin at low level
    Delay_ms(10);
  }
  Lcd_Out(2, 1, "Calibration...");      // Write text in first row
  UART1_Write_Text("Calibration...\r\n");
  // Configure RFid
  Calibration();
  IndexMod_Gain();
  AutoFDet();
  Select_ISO_IEC_14443_A_Protocol();
  // Ready for TAG scanning
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "Tag ID:       ");      // Write text in first row
  UART1_Write_Text("RFid Ready\r\n");
  while(1){
    if(GetNFCTag()){                    // Get tag ID
      Lcd_Out(2,1, &ID);                // Display tag on Lcd
      UART1_Write_Text("Tag ID:");
      UART1_Write_Text(ID);
      UART1_Write(13);
      UART1_Write(10);
      // Clear ID buffer
      for(j=0; j<10; j++){
        ID[j] = 0;
      }
      Delay_ms(500);
    }
  }
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: RFID Click example not working

#4 Post by filip » 23 Jan 2014 10:44

Hi,

OK, so you are using default RFid Click code for the default chip on the EasyPIC7 ?
Can you attach the photo of your hardware and connections ?

Regards,
Filip.

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#5 Post by saharul » 23 Jan 2014 11:05

2014-01-23 17.54.35.jpg
2014-01-23 17.54.35.jpg (1.56 MiB) Viewed 7648 times
Thanks filip

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: RFID Click example not working

#6 Post by filip » 23 Jan 2014 12:00

Hi,

Please, can you turn off the LED switches and put pull-up/down port DIP switches in neutral position and bring the blue tag closely to the antenna part of the RFID click board ?

Regards,
Filip.

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#7 Post by saharul » 24 Jan 2014 02:09

Thanks filip,

i tried your suggestion but nothing changes happened. Still did not read anything. anyway why do you suggest to turn off LEDs and put switch on middle of pull up/down

Dxmaxim
Posts: 80
Joined: 30 Sep 2008 08:10
Location: South Africa
Contact:

Re: RFID Click example not working

#8 Post by Dxmaxim » 16 May 2014 22:38

Hi All,

I have followed the thread as best I could, but as far as I can see there was no resolution posted. I have tried raising the RE PIN to VCC and no response. I am using the default code sample . . .

If the UART option works better, is there a code sample which makes it a bit easier . . .

Guys: as much as the MikroBus Click boards are great, personally I have found there is still a lot of guess work in making sure the connections are right before something happens or in this case does not happen. Perhaps rather than documenting all the possible connections that can be used, how about the ones that work per code sample - may just make it that much easier.

Back to the RFID Click - I am also not getting a tag read. Pity cause it's all wired up and good to go :(

Michael
ZarDynamix | Fidelis et fortis semper
An embedded solutions company
Site | http://www.zardynamix.com

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#9 Post by saharul » 18 May 2014 13:33

so do you dxmaxim?...

what went wrong here?.....

Dxmaxim
Posts: 80
Joined: 30 Sep 2008 08:10
Location: South Africa
Contact:

Re: RFID Click example not working

#10 Post by Dxmaxim » 18 May 2014 17:09

saharul wrote:so do you dxmaxim?...

what went wrong here?.....
Do I what? If you mean get a tag to read using the RFID Click the answer is, No, I don't.

What went wrong, well after programming a PIC and then connecting the RFID Click, the RFID click does not read a tag and output the TAG ID to the LCD or the USRT as its suppose to. According to the forum this is an established issue, and from what I can tell no resolution was posted. Even for the PIC 32 code sample it seems it was the same problem. So my guess is that there is something amiss with the SPI interface connections on the RFID Click

The recommendation from the MIKROE Team was that we switch to using the RS232 PORT, but this requires that you de-solder and re-solder two minute jumpers which I would rather not do ( Also recommend for REV 2 of the PCB please use jumpers that can be switched using shunts), unless it can be confirmed by someone who has pursued this avenue that this route does work. I don't have SMD desoldering equipment so any soldering work I do on the PCBs can damage them which I would like to avoid. Which is why I was asking if there were perhaps any one kind enough to supply code snippet illustrating how the RS232 option works.

In the mean time I have switched back to using the original RFID reader, which is working fine for the development of my project but the size if the RFID makes producing compact RFID Reader modules challenging.

So I suppose the questions are:

1) Has anyone who purchased the RFID click got it working using the standard code sample with the standard connections ?

2.1) If yes, could that intrepid contributor could please describe what they did, as it would be greatly appreciated
2.2) If no, but yes to the RS 232 option could that intrepid contributor please describe what they did as it would be greatly appreciated

3) If there is a problem with the RFID click, could the MIKROE team please advise on their progress to resolve it or point out where I am doffing it as out of the box I don't have a "Click" rfid solution functioning. The image in the forum posting which shows the Easy PIC 7 with the LCD displaying the standard text is what I am getting and no further response from the rfid CLick.

Kind regards :D :) :| :(
ZarDynamix | Fidelis et fortis semper
An embedded solutions company
Site | http://www.zardynamix.com

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: RFID Click example not working

#11 Post by filip » 19 May 2014 12:49

Hi,

The example for the RFid Click for EasyPIC7 on the LibStock works, just make sure that you have short connected RE1 with VCC pin on port headers as described in the Notes section.

Regards,
Filip.

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#12 Post by saharul » 21 May 2014 08:39

Hi filip,dxmaxim

if you look closely to the picture that i attached, i already did connecting the RE1 with Vcc..but it doesn't work....

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#13 Post by saharul » 21 May 2014 09:42

Hi filip,

I have to say sorry to you , i tried it again just now and it works, it reads the blue chip.

just two questions
1. BUT Why it does NOT read THE WHITE COLOUR CARD.

2. it is possible to wire to the chip?

Many thanks :D :D :D :D

Dxmaxim
Posts: 80
Joined: 30 Sep 2008 08:10
Location: South Africa
Contact:

Re: RFID Click example not working

#14 Post by Dxmaxim » 21 May 2014 09:55

I am going on a limb here, but the cards work at different frequencies which would make them incompatible ... :?

Did you do anything else to make it work? I retried and my custom board is not working with the RFID Click. I have resorted to buying a EsyPic 7 to try and get it to work and I am hoping that I have not damaged the RFID Click :oops:
ZarDynamix | Fidelis et fortis semper
An embedded solutions company
Site | http://www.zardynamix.com

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: RFID Click example not working

#15 Post by saharul » 21 May 2014 10:05

Hi DXMaxim,

i use easypic7


i connect the vcc to RE1.. attach the click at mikroBUS1. set the power supply to 3.3V.use 8Mhz oscillator crystal, and press reset button and switch off the main switch selector few times and suddenly it works with blue chip but still not the white colour card.

hope you'll get it

Post Reply

Return to “mikroC PRO for PIC General”