PN532 Breakout with SPI

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: PN532 Breakout with SPI

Post by adafruit_support_rick »

Let's take this one step at a time. I've branched a modified version of the Adafruit_PN532 library. It contains a new function, enableRead, which sets up the PN532 to fire the IRQ interrupt.
Download and install the Rick_Temp branch of the library, here:
https://github.com/adafruit/Adafruit-PN ... /rick_temp

Then run this sketch with it to see the interrupt count increment in Serial Monitor

Code: Select all

#include <Adafruit_PN532.h>

#define SCK  (13)
#define MOSI (11)
#define SS   (10)
#define MISO (12)

Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  Serial.println("Waiting for an ISO14443A Card ...");
  
  attachInterrupt(0, IRQ_ISR, FALLING);
}

int intcount = 0;
int previntcount = 0;

bool firsttime = true;

void IRQ_ISR()
{
  intcount++;
}

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
   
   
   if (intcount != previntcount)
   {
     Serial.println(intcount);
     previntcount = intcount;
   }
   
  nfc.enableRead(PN532_MIFARE_ISO14443A, uid, &uidLength);


}
NOTE: This is just a very quick and dirty hack to see if we can get you on the road. If this works reliably, we can spend some time updating the library to support interrupts.

User avatar
eumel
 
Posts: 8
Joined: Thu Aug 21, 2014 9:02 am

Re: PN532 Breakout with SPI

Post by eumel »

It works! I have only modified the SPI and IRQ pin definitions. It is not easy to measure, but there are approximately 60 seriel prints when holding card 1 second in field.

it's great that you're going to modify the library! Thank you very much! But I'm not a microcontroller expert and I wonder that this issue isn't adressed by other users using the Breakout Board with SPI. It means that all users will have a delay of approximately 1000 ms in main loop when no card is in field.....??

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: PN532 Breakout with SPI

Post by adafruit_support_rick »

eumel wrote:But I'm not a microcontroller expert and I wonder that this issue isn't adressed by other users using the Breakout Board with SPI. It means that all users will have a delay of approximately 1000 ms in main loop when no card is in field.....??
You're the first person I know of to raise this issue.
eumel wrote:it's great that you're going to modify the library!
Well... we're looking into it. I can't guarantee if or when we will get it done.

What else do you think you need to get your sketch working? Is this enough for now?

User avatar
rob____s
 
Posts: 6
Joined: Thu Oct 06, 2011 9:45 pm

Re: PN532 Breakout with SPI

Post by rob____s »

Anyone make any progress here regarding using an interrupt with SPI?

Running into the same thing here.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”