Library PN532 for nano 33 ble

I can't get a PN532 board to work on arduino nano 33 ble. I assume that the library available for Arduino one is not compatible with the arm processor.

Welcome to the forum.

Can you post a link to the library you are using e.g., on GitHub and a link to the PN532 board?

the following libraries work well with Arduino uno
"github.com/don/NDEF"github.com/Seeed-Studio/PN532"

the nfc board is

the nfc board and libraries do not work with Arduino nano 33 ble. I assume because the processor is arm

From the photo it looks like you are using I2C?
If so, have you set up the PN532 board correctly - usually there's a switch setting to change - sometimes I2C is not the default setting. Also, if so, are you using the PN532_I2C library.

I had a look at the library source. I did not see anything obvious that would prevent this from working on an ARM processor.
The GitHub page states mbed platforms are supported.

Just to be sure. Did you test your module with an Arduino Uno and got it working?

yes. the installed libraries are the following

[image] Schermata 2021-08-16 alle 11.21.15

the code

#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);

void setup(void) {
  Serial.begin(115200);
  
    Serial.print("start find PN53x board");
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
     Serial.print("Ciao");
    while (1); // halt
  }else{
    Serial.println("AllNewStep: NFC Module is Ready !!!");
  }
  nfc.setPassiveActivationRetries(0xFF);
  nfc.SAMConfig();
  Serial.println("Input RFID/NCF card");
}

void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // āļšāļąāļŸāđ€āļŸāļ­āļĢāđŒāļŠāļģāļŦāļĢāļąāļšāđ€āļāđ‡āļšāđ€āļĨāļ‚ ID āļ‚āļ­āļ‡ Tag
  uint8_t uidLength;                        // āļ„āļ§āļēāļĄāļĒāļēāļ§āļ‚āļ­āļ‡ ID (4 āļŦāļĢāļ·āļ­ 7 āđ„āļšāļ—āđŒ āļ‚āļķāđ‰āļ™āļāļąāļšāļ›āļĢāļ°āđ€āļ āļ—āļ‚āļ­āļ‡ Tag )
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); // āļŠāļąāđˆāļ‡āļ­āđˆāļēāļ™ Tag RFID
  if (success) {
    Serial.print("Found a card UID Value: ");
    for (uint8_t i = 0; i < uidLength; i++) // āđāļŠāļ”āļ‡āļœāļĨāđ€āļĨāļ‚ ID āļ‚āļ­āļ‡ Tag RFID
    {
      Serial.print(" 0x"); Serial.print(uid[i], HEX);
    }
    Serial.println("");
    delay(1000);
  }
  else
  {
    Serial.println("Timed out waiting for a card");
  }
}
digita o incolla il codice qui

yes i tested the same code on arduino uno and everything works fine. instead on arduino nano 33 ble it crashes here with error Didn't find PN53x board

 nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
   
    while (1); // halt
  }```

So the function nfc.getFirmwareVersion() failed.

I'm taking a guess here but with NXP I2C there can sometimes be issues with clock stretching on the I2C bus, meaning that some MCU's work while others don't. If you search online you will come across similar problems trying to get esp8266 to work with pn532 via i2c.

Here's a similar clock stretching issue logged on Nordic Semi forum:

Maybe others have a work around.

i tried with spi communication but i have the same problem. Everything works on arduino uno. on arduino ble 33 and esp32 it doesn't work

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (13)
#define PN532_MISO (12)
#define PN532_MOSI (11)
#define PN532_SS   (10)

// Use this line for a breakout with a SPI connection:
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

void setup(void) {
  Serial.begin(115200);

   delay(5000);
  Serial.println("Hello!");
  nfc.begin();
  
   delay(5000);
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  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 ...");
}


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)

  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);

    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);
      Serial.println("");
      Serial.println("");
    }
    delay(2000);
  }
}```

someone says that i2c library code needs to be changed

I can't figure out where to make this change

i managed to get this code to work on arduino nano 33 ble by modifying the library Adafruit_PN532.cpp

old code
new Adafruit_SPIDevice(ss, clk, miso, mosi, 1000000, SPI_BITORDER_LSBFIRST, SPI_MODE0);}

new code
new Adafruit_SPIDevice(ss, clk, miso, mosi, 100000, SPI_BITORDER_LSBFIRST, SPI_MODE0);}

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.