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.
1 Answer 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– VequalsIR2014年12月11日 16:49:10 +00:00Commented Dec 11, 2014 at 16:49
-
Please mark this question as answered in that case :)ScaryLooking– ScaryLooking2015年01月05日 10:34:13 +00:00Commented Jan 5, 2015 at 10:34
setup
afterSerial.begin
putSerial.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