Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: RFID is not working
PostPosted: Fri Jun 29, 2012 12:02 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Hello,

I tried using my RFID module with the example code in the development section of this site, but the first example doesn't work because of a call to a function authenticateBlock that I believe does not exist in the RFID API, and the second one only returns this as the output:
Image

How can I solve this problem?

By the way, here is the code I used for reference:
http://www.libelium.com/development/waspmote/example090
Code:
// stores the 16 bytes data to be written in a block:
blockData writeData = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
// stores the 16 bytes data read from a block:
blockData readData;
// stores the key or password:
uint8_t keyAccess[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// stores the block address:
uint8_t address = 0x04;
// stores the UID (unique identifier) of a card:
CardIdentifier CardID;
// stores the answer to request:
uint8_t ATQ[2];
 
 
 
void setup()
{
  USB.begin();
  USB.println("RFID/NFC @ 13.56 MHz module started");
  // switchs on the RFID/NFC @ 13.56 MHz module, type B, and asigns the socket
  RFID13.ON(SOCKET0, B);
  delay(1000);
}
 
 
 
void loop()
{
  USB.print("\n");
  USB.println("Ready to read...");
   
  // get the UID
  RFID13.init(CardID, ATQ);
  USB.print("\n");
  USB.print("the Card UID: ");
  RFID13.print(CardID, 4);
  // auntenticate block number 4 with its access key (2nd sector)
  if (!RFID13.authenticateBlock(address, keyAccess))
  {
    USB.println("Authentication failed");
  }
  else  // success
  {
    USB.println("Authentication OK");
    // after authentication, write blockData in the block
    if (!RFID13.writeData(address, writeData))
    {
      USB.println("Write failed");
    }
    else  // success
    {
      USB.println("Write block OK");
      // read from address after write
      if (!RFID13.readData(address, readData))
      {
        USB.println("Read failed");
      }
      else  // success
      {
        USB.println("Read block OK");
        USB.print("Data read: ");
        RFID13.print(readData, 16);
      }
    }
  }
  USB.print("\n");
  delay(1000); // wait some time each loop
}


http://www.libelium.com/development/waspmote/example091
Code:
// stores the status of the executed command:
short state;
// auxiliar buffer:
unsigned char aux[16];
// stores the UID (unique identifier) of a card:
unsigned char CardID[4];
// stores the key or password:
unsigned char keyAccess[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 
 
 
void setup()
{
  USB.begin();
  USB.println("NFC @ 13.56 MHz module started");
   
  // switchs on the module, type B, and asigns the socket
  RFID13.ON(SOCKET0, B);
  delay(1000);
}
 
 
 
void loop()
{
  USB.print("\r\n++++++++++++++++++++++++++++++++++++");
  // **** init the RFID reader
  state = RFID13.init(CardID, aux);
  if (aux[0] == aux[1])  // if so, there is no card on the EM field
  {
    USB.print("\r\nRequest error-no card found");
  }
  else  // a card was found
  {
    USB.print("\r\nRequest|Answer: ");
    RFID13.print(aux, 2); // show the ATQ
     
    USB.print("\r\nAnticollSelect: ");
    USB.print(state, HEX); // show the status of the executed init command (should be 0)
    USB .print("|Answer: ");
     
    // show the UID (Unique IDentifier) of the read card (4 bytes)
    RFID13.print(CardID, 16);
     
    // we will do the same actions in blocks from 0 to 3 (which is sector 1)
    for (int n=0; n< 64; n++)
    {
      // **** authenticate the key A of each sector
      if (n % 4 == 0) // only one authentication per sector is needed
      {
        state = RFID13.authenticate(CardID, n , keyAccess); // it is supposed all the blocks have the same key
        USB.print("\r\nAuthentication block");
        USB.print(n, DEC); // show the number of the block [n = 0..63 in a 1 kB RFID card]
        USB.print(": ");
        USB.print(state, HEX); // show the state of the executed authentication command
        delay(1);
      }
      // **** if passed authentication in the sector, we will be able to read the data in its blocks
      state = RFID13.readData(n, aux);
      USB.print("\r\nRead block ");
      USB.print(n, DEC); // show the number of the block [n = 0..63]
      USB.print(": ");
      USB.print(state, HEX); // show the state of the executed read command
      USB.print("   ");
       
      if (state == 0) // if the read command was successful, we show the data (16 bytes)
      {
        USB.print(" | ");
        for (int i=0; i< 16; i++)
        {
          if (aux[i] <=  B01111)
          {
            USB.print(" ");
          }
          USB.print(aux[i], HEX); // print the 16 bytes of the block 'n'
          USB.print(" ");
        }
        USB.print("  ");
        if (n==0)
          USB.print("<--UID(first 4 bytes)");
        else if (((n+1) % 4) == 0)
          USB.print("<--Trailer block");
      }
      delay(1);
    }
    USB.println();
  }
  delay(500); // wait 1 second in each loop
}

Thanks!


Top
 Profile  
 
 Post subject: Re: RFID is not working
PostPosted: Fri Jun 29, 2012 12:15 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Also, though the code says socket 0, I have used both socket 0 and socket 1 with the expansion board, with identical results. Neither of them worked.


Top
 Profile  
 
 Post subject: Re: RFID is not working
PostPosted: Mon Jul 02, 2012 10:05 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
uilt,

We have replied you into your other post, due to you ask same question as here.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 3 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use