0

I'm working with Arduino Uno, Adafruit PN532 NFC/RFID Shield and along with other modules. I'm posting this test program because I found there's conflict with the serial output while writing code to integrate all the modules together. I tried troubleshooting by running this code. The result wasn't what I'd expected.

In Arduino, as far as I know, setup() only runs once after starting the program and then loop() will be executed repeatedly. I ran the example sketch called readMiFare provided by Adafruit alone and it was fine. This code can be found at https://github.com/adafruit/Adafruit_NFCShield_I2C/blob/master/examples/readMifare/readMifare.pde. However, when I did the following in main,

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

void loop(void) 
{
  nfctestloop();
}

the following conflict showed up. When happened was that whenever I scanned a card to the reader it executed the loop() partially and exited the loop. Even worse, it executed the setup() again and again whenever I scanned a card.

Serial output

In nfctestsetup(), I just commented out Serial.begin(115200); from readMiFare.

My hardware setup was a no brainer since I'm using I2C. Uno and PN532 Shield

Appreciate the help.

After spending a good amount of hours on troubleshooting, I found something interesting. When I commented out all other files except NFC and main, it worked like a charm. So I suspect there could be redefinitions on the pins that the NFC shield uses on other files. I suspect the following code in the other file gave me the problem because I commented out the rest of the code in this file and ran this block of code together with NFC and main. In fact, it's the last line of code in this block that gave me the problem.

Also, I probed on the RESET pin (see the readMiFare link above). It generated a high-low-high pulse whenever I scanned a card. Is this related to the problem?

#include <SPI.h>
#include "Adafruit_BLE_UART.h"

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 3     // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 9

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

Any thought is appreciated.

migrated from electronics.stackexchange.com Dec 2 '14 at 19:05

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Spitballing: A better question might be, what did you do that is causing the Arduino to constantly reset itself? I'd verify that the pinout of your Arduino is the pinout that your Adafruit board is expecting- if you've got a short somewhere, or an input/output difference somewhere, that could be causing this. – TheNoonMoose Dec 1 '14 at 21:33
  • 5
    Sounds like you're not providing enough power and the board is brownouting. – Ignacio Vazquez-Abrams Dec 1 '14 at 21:35
  • adafruit-nfc-shield. This is how they plug this nfc shield to the board. No wiring necessary. My UNO was connected to the computer via USB. The serial output was fine when I ran readMiFare alone. It didn't reset itself. – VequalsIR Dec 1 '14 at 22:45
  • 1
    In setup after Serial.begin put Serial.println(MSUSR,BIN); MCUSR = 0x00; This will print the reset reason: • Bit 3 – WDRF: Watchdog System Reset Flag • Bit 2 – BORF: Brown-out Reset Flag • Bit 1 – EXTRF: External Reset Flag • Bit 0 – PORF: Power-on Reset Flag – geometrikal Dec 2 '14 at 12:45
  • thanks all for your advice. I found out what the problem is. I have other files that redefine pin2 which is already used by the NFC shield. I appreciate your help. Took me some time to realize my mistake but I learned a thing or two about debugging. Thank you for your time. – VequalsIR Dec 2 '14 at 17:40
1

This can happen when your sketch uses too much memory - the board can no longer assign addresses so it resets leading to an endless loop. Try reducing the amount of memory you are allocating.

  • Adafruit support team helped me out on this. I just had to reduce the memory size used by adding wrapping the strings in the print function with F(). – VequalsIR Dec 11 '14 at 16:49
  • Please mark this question as answered in that case :) – ScaryLooking Jan 5 '15 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.