SPI Conflict - Adafruit 2.8" TFT & NFC Shield

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");
  }
}

Here are the libraries used...

NFC Shield

steinvb12:
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.

Check this out:

(click pic for link)

It's a really useful board that goes between two boards that use the same pins (i.e. pin conflicts).

The board has a matrix of solderable pads so you can connect any pin to any other pin.

Need to move pin 8 to pin 4? No problem, just solder closed the proper jumper.

Hope this helps.

Thanks, I will have to look at that.

It would make things easier, but it's not my issue. My devices both work, just not together.

The clock settings for the two shields are different in the libraries. Would that matter?

Is there something else I should change?
LCD

NFC

HOWEVER, I did make change that seems to work where I re-initialize the NFC shield before trying to use each time. If I use nfc.begin() before I want to use the NFC shield in loop, it works.

The strange thing is I can always talk to the LCD after talking to the NFC, but I cannot talk to the NFC after talking the the LCD, except if I use nfc.begin() before.

It is not the speed. Acording to the libraries, it is the bit order. You must change to LSBFIRST before using the PN532 and back to MSBFIRST when done. You can change that setting on the fly.

SPI.setBitOrder(LSBFIRST);
// do your PN532 stuff here. Then...
SPI.setBitOrder(MSBFIRST);

edit: The PN532 may also be slower after a second look at the libraries. I would try this:

SPI.setBitOrder(LSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8);
// do your PN532 stuff here. Then...
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setBitOrder(MSBFIRST);