I am looking for guidance and suggestions on how to fix an SPI conflict between the Adafruit 2.8" TFT Touch Cap shield and Seeedstudio NFC Shield v2. Both are working fine on their individual sketches, even when stacked and connected at the same time. However, when the sketch requires the TFT to perform a function and then the NFC shield to perform a function, only the function from the first shield in the code runs. The SPI activity is not shifting from one shield to the other.
These are connected with an Arduino Yun.
TFT shield
SPI - ICSP header
Pin 8 - CS (Manually wired from pin 10 to pin 8 on the Arduino)
Pin 9 - DC
NFC Shield
SPI - ICSP header
Pin 10 - CS
In the example below, no tags are read by the NFC reader since I ask the TFT to perform a few functions at the end of setup. If I remove those functions, the tags are read.
Any help and ideas would be appreciated.
Thanks!
//Touchscreen shield
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
//NFC Shield
#include <PN532_SPI.h>
#include "PN532.h"
PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 8
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
tft.begin();
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
//NFC Shield
Serial.println("NFC Reader");
nfc.begin();
// Set the max number of retry attempts to read from a card
nfc.setPassiveActivationRetries(0x5);
// configure board to read RFID tags
nfc.SAMConfig();
//Opening TFT sequence
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.fillScreen(ILI9341_RED);
tft.fillScreen(ILI9341_WHITE);
tft.setCursor(100, 50);
tft.setTextColor(ILI9341_BLACK); tft.setTextSize(2);
tft.println("Welcome to My Project");
}
void loop() {
//loop checks to see if NFC tag is present
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// Display some basic information about the card
cardid = uid[6]; //find unique card id
cardid <<=8; cardid |= uid[5];
cardid <<=8; cardid |= uid[4];
cardid <<=8; cardid |= uid[3];
cardid <<=8; cardid |= uid[2];
cardid <<=8; cardid |= uid[1];
cardid <<=8; cardid |= uid[0];
Serial.println(cardid);
// wait until the card is taken away
while (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength)) {}
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}
