PN532 slow and libraries question

My PN532 runs the following code;

setup...

#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"

with the loop being....

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

  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)

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success) {
    Serial.println("Found a card!");

    for (uint8_t i = 0; i < uidLength; i++)
    {
      // Serial.print(" 0x");Serial.print(uid[i], HEX);
    }
  }
}

It runs and I have seen a thread that suggests modifying the PN532.h file to reduce the timeout and help speed .....

bool readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength, uint16_t timeout = 0); //timeout 0 means no timeout - will block forever.

This seems to have an affect but from my setup, how do i know I am changing the correct file? I am not sure what #include "PN532.h" refers to?

I have Adafruit PN532 library folders and Adafruit PN532 library folders and I am not sure what is being used?

In addition, I have seen other sketches that put .....

nfc.begin();
  nfc.setPassiveActivationRetries(0x01);
  nfc.SAMConfig();

All in Setup but if I do that the PN532 isnt recognised.

Some progress. In the sketch;

nfc.setPassiveActivationRetries(0x01);

as it states manages the retries before giving up to find a card and can be set very low.

In the PN532.h the line.....

bool readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength, uint16_t timeout = 0); //timeout 0 means no timeout - will block forever.

seems to work down to around 50ms.

Both have an effect

It still seems to slow the rest of the program a bit and if I comment the code out I can see a reasonable gain.

As I am using the V3 Elechouse PN532, does anyone know if this is the latest library?

Pn532 library

I cant see anything else in the loop PN code that would slow it down.

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

  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)

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success) {
    Serial.println("Found a card!");
  
  }

You should not be editing the library. The timeout is a parameter you pass when you call the function and if you don't supply it, it defaults to 0 which mean forever

//success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength, 100); // 100 msec timeout