Go Down

Topic: Due i2C Issue - TFT Touch Shield and NFC Shield (Read 488 times) previous topic - next topic

steinvb12

I have an Arduino Due with Adafruit shields - 2.8" TFT Touchscreen (cap) and NFC shield. The touchscreen shield is stacked on the Due and the RFID is wired separate via prototyping board to project requirements. Both are connected to the SDA1/SCL1 pins on the Due and powered by the 3.3v pin from the Due.

The touchscreen uses i2C for the touch controller and RFID also uses i2C. Everything is great most of the time. Both shields initialize and my code works the way I want. However, seemingly random, the code freezes on this line:
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

I know it freezes here because I put Serial.print statements before and after this line.

I can read many, many RFID cards one after another. It's only when I have an input from the touchscreen controller, and then the code continues, where the next time the NFC checks for a card with nfc.readPassiveTargetID, where it will freeze. The interesting part is that it will not freeze all the time. I can press the touchscreen 10 times in a row and it will not freeze. But then I start the device back up, and the first time I press the touchscreen, it will freeze right after.

So to me it seems random, but maybe there is something I can change to make it more reliable? The NFC reads fine when there are no inputs from the touchscreen, it's only when it goes back and forth between the i2C devices when there is an issue. And again, it's not all the time.

Do you think there is something in the code I can fix? Do you think it's a voltage issue? An interference issue? Any suggestions and potential solutions would be helpful.

Here are some of the relevant parts of the code…I know I left a lot out, but I think there are only a few possibilities to change.

Code: [Select]
#include <Adafruit_PN532.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>

#define PN532_IRQ   (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

Adafruit_FT6206 ctp = Adafruit_FT6206();

Setup
tft.begin();

 if (! ctp.begin(40)) {  // pass in 'sensitivity' coefficient
    Serial.println("Couldn't start FT6206 touchscreen controller");
    while (1);
  }

nfc.begin();
nfc.setPassiveActivationRetries(0x02); //attempt read 2 times before continuing
nfc.SAMConfig();


Loop
TS_Point p = ctp.getPoint();
  p.x = map(p.x, 0, 240, 240, 0);
  p.y = map(p.y, 0, 320, 320, 0);

if (p.x > 180 && p.x < 240) {
          if (p.y > 260) {         
            DO SOMETHING…
            }
        }

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
DO SOMETHING..
       }

Go Up