How to view red LED (hard fault / SOS) reason or log? Using DFRobot PN532 NFC module

Hi, I am playing around with a DFRobot PN532 Gravity module (link to library that I ported: Particle Web IDE).

I have it mostly working, but if I sometimes move the NFC tag too quickly / do so repeatedly, the Photon goes into red LED / hard fault and restarts. One thing I did observe is when this occurs, the card UID length that it picks up is quite long (200+) when it is actually 7 on a full read - so perhaps some kind of heap overflow?

I have also seen the “this card type is not NTAG21x…” message sometimes show up before the crash as well when moving the tag too quickly, even though it is an NTAG NFC tag.

The example code I am using to try and read the card UID is below. Is there a way to see why the SOS happens? Thanks!

// This #include statement was automatically added by the Particle IDE.
#include <dfrobot-pn532.h>

#define BLOCK_SIZE 16

#define block          (5)

//Initialize MEGA2560
DFRobot_PN532_UART  nfc;
DFRobot_PN532:: sCard_t NFCcard;

void setup() {
  Serial.begin(115200);
  while (!nfc.begin(&Serial1)) {
    Serial.println("initial failure");
    delay (1000);
  }
  Serial.println("Waiting for a card......");
}

void loop() {

  if (nfc.scan()) {
      Serial.println("card detected");
    /*!
      The NTAG's EEPROM memory is organized in pages with 4 bytes per page. NTAG213 variant has
      45 pages, NTAG215 variant has 135 pages and NTAG216 variant has 231 pages in total.
      The memory organization can be seen  in the following table .
           page Adr      BYTE number within a page
                         0            |    1    |   2       |    3      |
              0                       serial  number
              1                       serial  number
              2          serial number|internal | lock bytes| lock bytes|
              3                       Capability Container(cc)
              ----------------------------------------------------------------
              -----------------------NTAG213----------------------------------
              4
              ...                     user memory
              39
              ----------------------------------------------------------------
              ------------------------NTAG215---------------------------------
              4
              ...                     user memory
              129
              ----------------------------------------------------------------
              ------------------------NTAG216---------------------------------
              4
              ...                     user memory
              225
    */  NFCcard = nfc.getInformation();
    if (NFCcard.AQTA[1] == 0x44 && memcmp(NFCcard.cardType, "Ultralight", 10) != 0) {      
    Serial.print("UID Lenght: "); Serial.println(NFCcard.uidlenght);
    Serial.print("UID: ");
    if (NFCcard.uidlenght <= 10) {
        for (int i = 0; i < NFCcard.uidlenght; i++) {
          Serial.print(NFCcard.uid[i], HEX);
          Serial.print(" ");
        }
    }
    }
    else {
      Serial.println("The card type is not NTAG21x...");
    }
  }
  else {
    Serial.println("no card");
  }
  delay(2000);
}

Hi, here are some useful info from where to start:

Best,
Arek

1 Like

@dreamER thank you - I didn’t read that closely enough to realize the red LED blinks can reveal what the specific fault is. I’ll try this as well as the logging you linked, I appreciate it.