Problem with Arduino Ethernet and Shield NFC v2.0

Hello,
we’ve got a problem with the sd card reader, when we use this one + the NFC shield, the NFC Shield doesn’t read the RFID card, I suppose there is a conflict between both cards.

How can I fix it please ?

lp-14

we've got a problem with the sd card reader,

Which SD card reader?

when we use this one + the NFC shield

There are multiple NFC shield. Which ONE do you have?

I suppose there is a conflict between both cards.

Or your code or some libraries.

How can I fix it please ?

Resolve the conflicts. How is impossible to say, given how little information you provided.

ok, we got the Arduino Ethernet card and a NFC shield v2.0 (http://www.lextronic.fr/P28725-platine-nfc-shield-pour-arduino.html).
We change the SS pin of the NFC shield to 9, and Ethernet and RFID work. But when we plug an SD card into Arduino Ethernet, RFID don’t work.

we use the PN532 library

#include <PN532.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

#define PN532_CS 9
#define ETHNET_CS 10
#define SD_CS 4
PN532 nfc(PN532_CS);

void setup()
{
 //Set SD
  spiSelect(SD_CS);
  SPI.setBitOrder(MSBFIRST);
  SD.begin(SD_CS);
 //Set RFID
  SPI.setBitOrder(LSBFIRST);
  spiSelect(PN532_CS);
  nfc.begin();
  nfc.SAMConfig();
 //Set Ethernet
  spiSelect(ETHNET_CS);
  SPI.setBitOrder(MSBFIRST);
  Ethernet.begin(mac, ip,gateway);
  server.begin();

}


void spiSelect(int CS) {
  // disable all SPI
  pinMode(PN532_CS,OUTPUT);
  pinMode(ETHNET_CS,OUTPUT);
  pinMode(SD_CS,OUTPUT);
  digitalWrite(PN532_CS,HIGH);
  digitalWrite(ETHNET_CS,HIGH);
  digitalWrite(SD_CS,HIGH);
  // enable the chip we want
  digitalWrite(CS,LOW);  
}

void loop () {

    lectureRFID();

}


void lectureRFID () {

      Serial.println("debut");
      spiSelect(PN532_CS);
      Serial.println("select");
     // NFC uses LSB first so we have to explicitly set that
     SPI.setBitOrder(LSBFIRST);
     Serial.println("bitfort");
    
     /* look for MiFare type cards */
      uint32_t id;
      id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
      Serial.println("read");
       if (id != 0) {
       Serial.print("Read card #"); 
       Serial.println(id);
       SPI.setBitOrder(MSBFIRST);
    
       // boolean rep = IsAllowed(id,ZONE);
        LOG_ID("0000",false);
   }
  
}
 //Set SD
  spiSelect(SD_CS);
  SPI.setBitOrder(MSBFIRST);
  SD.begin(SD_CS);
 //Set RFID
  SPI.setBitOrder(LSBFIRST);
  spiSelect(PN532_CS);

The SD card reader is an SPI device. You don't suppose that trying to initialize it in the middle of f**king with the SPI parameters will cause problems, do you?

PaulS is right. Don’t mess with the SPI settings while any of the SPI devices are active. The SPI.setBitOrder() should be called with all SPI slave selects HIGH. You also should not need to manipulate the slave select pins after the setup function. Those should be handled by the appropriate libraries for each device.

This i the way I do it. If one device is not using the default setting(s), I change that setting(s) for that device, then change it back after the communication with that device is complete. Your different device is the PN532, so:

#include <PN532.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

#define PN532_CS 9
#define ETHNET_CS 10
#define SD_CS 4
PN532 nfc(PN532_CS);

void setup()
{
   // set all slave selects as OUTPUT and HIGH
   pinMode(SD_CS,OUTPUT);
   digitalWrite(SD_CS,HIGH);
   pinMode(ETHNET_CS,OUTPUT);
   digitalWrite(ETHNET_CS,HIGH);
   pinMode(PN532_CS,OUTPUT);
   digitalWrite(PN532_CS,HIGH);

 //Set SD
  SD.begin(SD_CS);

 //Set RFID
  SPI.setBitOrder(LSBFIRST);
  nfc.begin();
  nfc.SAMConfig();
  SPI.setBitOrder(MSBFIRST);

 //Set Ethernet
  Ethernet.begin(mac, ip,gateway);
  server.begin();
}

void loop () {

    lectureRFID();

}

void lectureRFID () {
   SPI.setBitOrder(LSBFIRST);
   // do your PN532 device comm ONLY
   SPI.setBitOrder(MSBFIRST);
}

thank you guys, it work pretty good

thanks lp-14

Hi,

i am starting a project using NFC and am wounded if the arduino YÙN board is the best option to combine with a NFC shield from adafruit. I will need the arduino to take the information from the NFC tag and send it via ethernet (the YÙN board has built in ethernet) to an online database. Any suggestions of what arduino to use or is this the right one also does anyone have any helpful code modules that will help with NFC and sending and receiving data?

thanks Jamie

Guys Do you mind telling me Which NFC shield and what libraries were you using ?

I am using NFC seed V2 and Don NDEF libraries with Arduino EtherNet can i do the same thing ? In my libraries this command is not allowed, PN532 nfc(PN532_CS); it does not take integer input