Rfid Code quiting

I am using a PN5180 rfid reader, that's wired correctly. When I run my code it uploads and stops running on line nfc.reset(); and I'm not getting any errors. Any thoughts?

#include <PN5180.h>
#include <PN5180ISO15693.h>

#define PN5180_NSS  10
#define PN5180_BUSY 9
#define PN5180_RST  7


PN5180ISO15693 nfc(PN5180_NSS, PN5180_BUSY, PN5180_RST);

void setup() {
  Serial.begin(115200);
  Serial.println(F("=================================="));
  Serial.println(F("Uploaded: " __DATE__ " " __TIME__));
  Serial.println(F("PN5180 ISO15693 Demo Sketch"));

  nfc.begin();

  Serial.println(F("----------------------------------"));
  Serial.println(F("PN5180 Hard-Reset..."));
  nfc.reset();

  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading product version..."));
  uint8_t productVersion[2];
  nfc.readEEprom(PRODUCT_VERSION, productVersion, sizeof(productVersion));
  Serial.print(F("Product version="));
  Serial.print(productVersion[1]);
  Serial.print(".");
  Serial.println(productVersion[0]);

  if (0xff == productVersion[1]) { // if product version 255, the initialization failed
    Serial.println(F("Initialization failed!?"));
    Serial.println(F("Press reset to restart..."));
    Serial.flush();
    exit(-1); // halt
  }
  
  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading firmware version..."));
  uint8_t firmwareVersion[2];
  nfc.readEEprom(FIRMWARE_VERSION, firmwareVersion, sizeof(firmwareVersion));
  Serial.print(F("Firmware version="));
  Serial.print(firmwareVersion[1]);
  Serial.print(".");
  Serial.println(firmwareVersion[0]);

  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading EEPROM version..."));
  uint8_t eepromVersion[2];
  nfc.readEEprom(EEPROM_VERSION, eepromVersion, sizeof(eepromVersion));
  Serial.print(F("EEPROM version="));
  Serial.print(eepromVersion[1]);
  Serial.print(".");
  Serial.println(eepromVersion[0]);

  /*
  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading IRQ pin config..."));
  uint8_t irqConfig;
  nfc.readEEprom(IRQ_PIN_CONFIG, &irqConfig, 1));
  Serial.print(F("IRQ_PIN_CONFIG=0x"));
  Serial.println(irqConfig, HEX);

  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading IRQ_ENABLE register..."));
  uint32_t irqEnable;
  nfc.readRegister(IRQ_ENABLE, &irqEnable));
  Serial.print(F("IRQ_ENABLE=0x"));
  Serial.println(irqConfig, HEX);
  */

  Serial.println(F("----------------------------------"));
  Serial.println(F("Enable RF field..."));
  nfc.setupRF();
}

uint32_t loopCnt = 0;
bool errorFlag = false;

//SLIX2 Passwords, first is manufacture standard
uint8_t standardpassword[] = {0x0F, 0x0F, 0x0F, 0x0F};
//New Password
uint8_t password[] = {0x12, 0x34, 0x56, 0x78};

void loop() {
  if (errorFlag) {
    uint32_t irqStatus = nfc.getIRQStatus();
    showIRQStatus(irqStatus);

    if (0 == (RX_SOF_DET_IRQ_STAT & irqStatus)) { // no card detected
      Serial.println(F("*** No card detected!"));
    }

    nfc.reset();
    nfc.setupRF();

    errorFlag = false;
  }

  Serial.println(F("----------------------------------"));
  Serial.print(F("Loop #"));
  Serial.println(loopCnt++);

/*
  // code for unlocking an ICODE SLIX2 protected tag   
  ISO15693ErrorCode myrc = nfc.unlockICODESLIX2(password);
  if (ISO15693_EC_OK == myrc) {
    Serial.println("unlockICODESLIX2 successful");
  }
*/
  
/* 
  // code for set a new SLIX2 privacy password
  nfc.getInventory(uid);
  Serial.println("set new password"); 
  
  ISO15693ErrorCode myrc2 = nfc.newpasswordICODESLIX2(password, standardpassword, uid);
  if (ISO15693_EC_OK == myrc2) { 
   Serial.println("sucess! new password set");    
  }else{
   Serial.println("fail! no new password set: "); 
   Serial.println(nfc.strerror(myrc2));  
   Serial.println(" "); 
  } 
 */
  
  uint8_t uid[8];
  ISO15693ErrorCode rc = nfc.getInventory(uid);
  if (ISO15693_EC_OK != rc) {
    Serial.print(F("Error in getInventory: "));
    Serial.println(nfc.strerror(rc));
    errorFlag = true;
    return;
  }
  Serial.print(F("Inventory successful, UID="));
  for (int i=0; i<8; i++) {
    Serial.print(uid[7-i], HEX); // LSB is first
    if (i < 2) Serial.print(":");
  }
  Serial.println();

  Serial.println(F("----------------------------------"));
  uint8_t blockSize, numBlocks;
  rc = nfc.getSystemInfo(uid, &blockSize, &numBlocks);
  if (ISO15693_EC_OK != rc) {
    Serial.print(F("Error in getSystemInfo: "));
    Serial.println(nfc.strerror(rc));
    errorFlag = true;
    return;
  }
  Serial.print(F("System Info retrieved: blockSize="));
  Serial.print(blockSize);
  Serial.print(F(", numBlocks="));
  Serial.println(numBlocks);

  Serial.println(F("----------------------------------"));
  uint8_t readBuffer[blockSize];
  for (int no=0; no<numBlocks; no++) {
    rc = nfc.readSingleBlock(uid, no, readBuffer, blockSize);
    if (ISO15693_EC_OK != rc) {
      Serial.print(F("Error in readSingleBlock #"));
      Serial.print(no);
      Serial.print(": ");
      Serial.println(nfc.strerror(rc));
      errorFlag = true;
      return;
    }
    Serial.print(F("Read block #"));
    Serial.print(no);
    Serial.print(": ");
    for (int i=0; i<blockSize; i++) {
      if (readBuffer[i] < 16) Serial.print("0");
      Serial.print(readBuffer[i], HEX);
      Serial.print(" ");
    }
    Serial.print(" ");
    for (int i=0; i<blockSize; i++) {
      if (isprint(readBuffer[i])) {
        Serial.print((char)readBuffer[i]);
      }
      else Serial.print(".");
    }
    Serial.println();
  }

#ifdef WRITE_ENABLED
  Serial.println(F("----------------------------------"));
  uint8_t *writeBuffer = malloc(blockSize);
  for (int i=0; i<blockSize; i++) {
    writeBuffer[i] = 0x80 + i;
  }
  for (int no=0; no<numBlocks; no++) {
    rc = nfc.writeSingleBlock(uid, no, writeBuffer, blockSize);
    if (ISO15693_EC_OK == rc) {
      Serial.print(F("Wrote block #"));
      Serial.println(no);
    }
    else {
      Serial.print(F("Error in writeSingleBlock #"));
      Serial.print(no);
      Serial.print(": ");
      Serial.println(nfc.strerror(rc));
      errorFlag = true;
      return;
    }
  }
#endif /* WRITE_ENABLED */

/*
  // code for locking an ICODE SLIX2 protected tag   
  ISO15693ErrorCode myrc = nfc.lockICODESLIX2(password);
  if (ISO15693_EC_OK == myrc) {
    Serial.println("lockICODESLIX2 successful");
    delay(5000);
*/
  delay(1000);
}

void showIRQStatus(uint32_t irqStatus) {
  Serial.print(F("IRQ-Status 0x"));
  Serial.print(irqStatus, HEX);
  Serial.print(": [ ");
  if (irqStatus & (1<< 0)) Serial.print(F("RQ "));
  if (irqStatus & (1<< 1)) Serial.print(F("TX "));
  if (irqStatus & (1<< 2)) Serial.print(F("IDLE "));
  if (irqStatus & (1<< 3)) Serial.print(F("MODE_DETECTED "));
  if (irqStatus & (1<< 4)) Serial.print(F("CARD_ACTIVATED "));
  if (irqStatus & (1<< 5)) Serial.print(F("STATE_CHANGE "));
  if (irqStatus & (1<< 6)) Serial.print(F("RFOFF_DET "));
  if (irqStatus & (1<< 7)) Serial.print(F("RFON_DET "));
  if (irqStatus & (1<< 8)) Serial.print(F("TX_RFOFF "));
  if (irqStatus & (1<< 9)) Serial.print(F("TX_RFON "));
  if (irqStatus & (1<<10)) Serial.print(F("RF_ACTIVE_ERROR "));
  if (irqStatus & (1<<11)) Serial.print(F("TIMER0 "));
  if (irqStatus & (1<<12)) Serial.print(F("TIMER1 "));
  if (irqStatus & (1<<13)) Serial.print(F("TIMER2 "));
  if (irqStatus & (1<<14)) Serial.print(F("RX_SOF_DET "));
  if (irqStatus & (1<<15)) Serial.print(F("RX_SC_DET "));
  if (irqStatus & (1<<16)) Serial.print(F("TEMPSENS_ERROR "));
  if (irqStatus & (1<<17)) Serial.print(F("GENERAL_ERROR "));
  if (irqStatus & (1<<18)) Serial.print(F("HV_ERROR "));
  if (irqStatus & (1<<19)) Serial.print(F("LPCD "));
  Serial.println("]");
}

What does this correct wiring look like?

What status does the nfc.begin() return?

I am using a Arduino Nano.
Wiring
Nano--------------------------PN5180
5V-------------------------------5V
3V3-----------------------------3V3
Gnd---Level Converter---Gnd
D7-----Level Converter---RST
D9-----Level Converter---Busy
D10---Level Converter---NSS

When ran I only get this in the serial monitor.

==================================

Uploaded: Jun 9 2024 16:00:49

PN5180 ISO15693 Demo Sketch


PN5180 Hard-Reset...

I hope this is what you where looking for.

does it work without that line? What happens?

If I comment out That line it stops on
Line 25 uint8_t productVersion[2];
If I comment that out
Line 41 uint8_t firmwareVersion[2];
If I comment that out
Line 50 uint8_t eepromVersion[2];
If I comment that out
Line 75 nfc.setupRF();
If I comment that out it enters the loop() but stops on line 131 uint8_t uid[8]; after printing


Loop #0
In the serial monitor

Not good enough. Please see this for the full connection list.

I thought you only needed those if you had more then one PN5180?
I have changed my pin layout to this


My code still stops running at those lines. Is there anything I'm missing?

What does the note "Only have one Level shifter" actually mean?

I only own one level shifter and all the pins are being used so I can not shift the RST and Busy lines.

So therefore you can't wire it up correctly. Simple as that.

I see other projects with the Pn5180 rfid reader that do not put all the wires through the level shifter. I have tried these with my uno and nano, but it still does not work. So I do not think the wiring is incorrect. Is there any other reasons as to why its failing?

Yes there are a hell of a lot of bad wiring diagrams out there on the internet. That is the whole point of my comments, basically just do it right to begin with.

Thank you for being really kind and understanding as I look for help and try to learn about this. If you have any other resource's you'd like to recommend feel free.

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