PN532 IRQ Clarification Request

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
kevin_nfc
 
Posts: 7
Joined: Mon May 19, 2014 10:34 pm

Re: PN532 IRQ Clarification Request

Post by kevin_nfc »

adafruit_support_bill wrote:We do not have example code for p2p. If the existing example code is not working as documented, please post clear photos of the board so we can diagnose the problem.
I don't need the code for p2p.Can you provide other example code about PN532,and IRQ must be effective.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PN532 IRQ Clarification Request

Post by adafruit_support_bill »

The example code in the library works. If you are having a problem with it, please describe the problem in detail and post photos of your shield and we will try to diagnose the problem.
https://github.com/adafruit/Adafruit_NFCShield_I2C

jokes_finder
 
Posts: 1
Joined: Sat Jul 05, 2014 9:45 am

Re: PN532 IRQ Clarification Request

Post by jokes_finder »

I can see the problem is left unsolved until now.
I am facing the same problem here!

I took a look at readPassiveTargetID() as pointed out by adafruit_support_bill, but didn't find anything useful there!
I know that the interrupt is enabled in the device by looking at the command "pn532_packetbuffer[3] = 0x01; // use IRQ pin!" in the SAMConfig().

I have thought of something to learn the behavior of the IRQ pin. The IRQ pin is connected to digital pin 3 (I am using Arduino Mega 2560) and in the loop() I always read the pin value. So, the code looks something like this:

Code: Select all

#include <PN532.h>

#define SCK 37
#define MOSI 39
#define SS 40
#define MISO 38

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

void setup(void) {
  Serial.begin(9600);
  nfc.begin(); 
  nfc.SAMConfig();
  pinMode(3, INPUT);
}

void loop() {
  Serial.println(digitalRead(3));
}

The output is always '1'!

I thought of another way. I used the external interrupts provided in the Arduino, so the code looks like this:

Code: Select all

#include <PN532.h>

#define SCK 37
#define MOSI 39
#define SS 40
#define MISO 38

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

volatile boolean state;

void setup(void) {
  Serial.begin(9600);
  nfc.begin(); 
  nfc.SAMConfig();
  pinMode(13, OUTPUT); // not used for the time being
  digitalWrite(13, LOW);
  state =  false;
  interrupts();
  attachInterrupt(1, RFID_ISR, CHANGE);
}

void loop() {
  if (state) {
    Serial.println("Caught!");
    state = false;
  }
}

void RFID_ISR() {
  state = true;
}
However, the serial monitor is flooded with "Caught!" even when there are no tags around! That's strange, isn't it?!

Any help with that?

Thanks in advance.
Regards,
Ahmad.

User avatar
ejcosta
 
Posts: 3
Joined: Mon Feb 01, 2016 6:33 pm

Re: PN532 IRQ Clarification Request

Post by ejcosta »

After a fast look over lib code, I think you miss the "read-tag mode initialization".

The setup calls only inits the shield and doesn't put it on read-tag mode.

Code: Select all

void setup(void) {
  Serial.begin(9600);
  nfc.begin(); 
  nfc.SAMConfig();
  pinMode(3, INPUT);
}
Looking at readPassiveTargetID(), it first put the shield on read-tag mode:

Code: Select all

pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
pn532_packetbuffer[1] = 1;  // max 1 cards at once (we can set this to 2 later)
pn532_packetbuffer[2] = cardbaudrate;

if (!sendCommandCheckAck(pn532_packetbuffer, 3, timeout))
{
  #ifdef PN532DEBUG
    PN532DEBUGPRINT.println(F("No card(s) read"));
  #endif
  return 0x0;  // no cards read
}
and then waits for IRQ:

Code: Select all

// wait for a card to enter the field (only possible with I2C)
if (!_usingSPI) {
  #ifdef PN532DEBUG
    PN532DEBUGPRINT.println(F("Waiting for IRQ (indicates card presence)"));
  #endif
  if (!waitready(timeout)) {
    #ifdef PN532DEBUG
      PN532DEBUGPRINT.println(F("IRQ Timeout"));
    #endif
    return 0x0;
  }
}
So before you wait for IRQ you should put it on "read-tag mode".
This is an unconfirmed suspicion as I haven't tried it yet.

User avatar
samfosteriam
 
Posts: 1
Joined: Tue Jul 09, 2013 2:45 am

Re: PN532 IRQ Clarification Request

Post by samfosteriam »

So is it fair to say the Adafruit_PN532 library doesnt support the use of the interrupt, in the sense that its not possible to run *other* code and be interrupted when the value of the PN532_IRQ pin changes. The readPassiveTargetID method blocks while waiting for the value to go low.

And if this is the behavior I/we want, we'll need to extend the Adafruit_PN532 library or write our own? That's fine btw, its just not clear what the expectation should be.

User avatar
Kelvin_M
 
Posts: 2
Joined: Mon Nov 07, 2016 2:51 am

Re: PN532 IRQ Clarification Request

Post by Kelvin_M »

I am using a GSM shield and the adafruit nfc/rfid shield in my project. But my GSM shield is already using Digital pin 2 which the NFC also requires for IRQ, according to the documentation the IRQ pin for the nfc shield is changeable.. how do i change it to pin D7 instead of D2

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PN532 IRQ Clarification Request

Post by adafruit_support_bill »

Changing the interrupt pin is covered in the guide here: https://learn.adafruit.com/adafruit-pn5 ... do-and-yun

User avatar
Kelvin_M
 
Posts: 2
Joined: Mon Nov 07, 2016 2:51 am

Re: PN532 IRQ Clarification Request

Post by Kelvin_M »

in the Adafruit Nfc library am using the readMifare classic example. Am trying to send the card content via sms to a remote number.
if (uidLength == 4)
{
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
}
as the card content is stored in the cardid variable which is a unsigned int.. my GSM library can only take char parameters. am having problems trying to convert the uint to a char..
unsigned char SendSMS(unsigned char *number_str, unsigned char *message_str);
Send a SMS to the specified number with the specified string.
how do i convert the card id and send it as the message_str?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PN532 IRQ Clarification Request

Post by adafruit_support_bill »

What you need is a character array - which in C++ is essentially the same as a string. You can use the itoa() function to convert your uint32_t into a character array:
http://playground.arduino.cc/Code/PrintingNumbers

Code: Select all

char buf[12]; 
itoa(cardid, buf 10);

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

Return to “Arduino Shields from Adafruit”