Post a new topicPost a reply Page 1 of 2   [ 18 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Programming the RFID Board
PostPosted: Thu Jun 21, 2012 7:26 am 

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

I'm getting some strange output from the RFID module. I was using the RFID/NFC 13.56MHz code and WaspRFID.cpp/WaspRFID.h from this post "http://www.libelium.com/forum/viewtopic.php?f=16&t=9184." Below is the code and the output of what I am getting.
Image
Code:
//almacena el status del comando ejecutado
uint8_t state;
//buffer auxiliar
uint8_t aux[16];
//Almacenar el UID de la tarjeta
uint8_t CardID[4];
//Almacena las respuestas de los comandos
uint8_t ATQ[2];

void setup()

{
 
  USB.begin();
  USB.println("Arrancando el modulo RFID/NFC 13.25)");
  //Arrancamos el módulo en el socket0 tipo B
  RFID13.ON(socket0,B);
  delay(1000);
}

void loop()
{
  RFID13.init(CardID, ATQ);
  USB.print("\n");
  USB.print("Identificador UID: ");
  RFID13.print(CardID, 4);
}


Thank you so much for your great service!


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Thu Jun 21, 2012 8:45 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Oh and by the way, I thought a picture of my hardware setup might also prove useful. Please let me know if I'm doing anything wrong!
Image


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Thu Jun 21, 2012 9:00 am 

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

Take into account that USB and socket0 share UART0 of the microcontroller. You can see connection diagrams into Waspmote technical guide.

The easiest way for you is to use socket 1 (but only if you have an expansion board. If not, please use USB.close() before RFID13.ON(socket0,B);

Any questions please feel free to ask.

Regards


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Fri Jun 22, 2012 12:59 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
I followed your suggestion and used socket 1 instead. Unfortunately, I am still not receiving data. Here is what my setup looks like now:
Image

The modified code now looks like this:
Code:
//almacena el status del comando ejecutado
uint8_t state;
//buffer auxiliar
uint8_t aux[16];
//Almacenar el UID de la tarjeta
uint8_t CardID[4];
//Almacena las respuestas de los comandos
uint8_t ATQ[2];

void setup()

{
 
  USB.begin();
  USB.println("Arrancando el modulo RFID/NFC 13.25)");
  //Arrancamos el módulo en el socket0 tipo B
  RFID13.ON(socket1,B);
  delay(1000);
}

void loop()
{
  RFID13.init(CardID, ATQ);
  USB.print("\n");
  USB.print("Identificador UID: ");
  RFID13.print(CardID, 4);
}


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Mon Jun 25, 2012 9:02 am 

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

Probably you already did it but, could you please test example codes provided in our development section and tell us if they are working?

Also please read carefully RFID networking guide.

Let us know.

Regards.


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Mon Jun 25, 2012 8:37 pm 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
I tested the example codes and the first one on the development webpage, the "Basic Example," doesn't work because it makes a call to an "authenticateBlock" function that doesn't exist in the RFID API. Therefore, I tried the "Read All Blocks" example code and once again, the output was:
Image

For the sake of convenience, I've posted the code for Basic Example and Read All Blocks below
Basic Example
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
}

Read all blocks
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
}
 


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Mon Jul 02, 2012 10:04 am 

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

We see that your serial monitor uses 38400 bauds. Please, could you check RFID baudrate? maybe RFID module has a different baudrate and it has to be same for both parts.

Let us know.

Regards.

One tip: Please do not open new post for same issues.


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Mon Jul 02, 2012 9:02 pm 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Thanks for the tip! I'll keep that in mind.
I tried every baud rate option in the serial monitor, but I'm still getting no response from the board.
This is the code I'm using. I modified it so that USB.println("NFC @ 13.56 MHz module started");" is after "RFID13.ON(SOCKET1, B);". However, this line never appears, indicating that the program crashes on the "RFID13.ON(SOCKET1, B);" command. The only way to prevent this crash is to set the type to something other than B. This skips the block of code that is executed when the type is set to B, so perhaps something in this section of the API is causing the problem?
Place where the code is crashing:
Code:
if (_type == B) {
            getFirmware();
            configureSAM();
        } else {


The code I'm running:
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();
 
   
  // switchs on the module, type B, and asigns the socket
  USB.println("Start");
  RFID13.ON(SOCKET1, B);
  USB.println("NFC @ 13.56 MHz module started"); 
  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
}


Type B Output:

Image

Type A Output:
Image

I'm wondering if I need to use X-CTU to change the the baud rate of the RFID module. I tried, but it couldn't connect ("communicating with modem failed"). How should I properly check the baud rate of the module?


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Tue Jul 03, 2012 11:44 pm 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
I'm sorry if I seem impatient, but it would be really nice to have a definitive answer to this question, either through this post or through the email. Can this problem with the RFID be fixed, or do you need more time with it? Thanks!


Top
 Profile  
 
 Post subject: Re: Programming the RFID Board
PostPosted: Wed Jul 04, 2012 9:44 am 

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

You do not have to apologize, we have to due to our delay.

We are preparing some code to automatically change baudrate of the RFID module to 38400 which works perfectly with Waspmote.

In the meantime, we only can kindly ask you to be patience and wait till we solve this issue.

Of course you can try to do it by yourself if you want.

Sorry for this inconvenience.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 18 posts ]
Go to page 1, 2  Next


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