Using Seeed Studio NFC shield with official Arduino Wi-fi shield

This doesn’t work without some alteration.  The NFC shield will report “chip not found” with any of the examples.

The first problem is that both shields use pin 10 for the SPI chip select.  To fix this, cut the PCB track between the D10 and SS pads on the NFC shield and bridge the pads to link D9 to SS, as shown in the picture below.

link

Following this you will need to use code like

PN532_SPI pn532spi(SPI, 9);

to tell the NFC library to use the correct chip select pin.

The second problem appears to be that the output buffer that connects the Wifi shield to the SPI MISO line does not have a tri-state output.  Hence it does not share the MISO line correctly with the NFC shield.  I fixed this by adding a tri-state buffer to the Ethernet shield’s MISO output.

wifi_fix-svg

I did this by taking the Wifi shield off the board and connecting the required pins with wire (SPI bus, 5V, IOREF, 4, 7, 10, GND).  Be sure to power the 74HC125 with +5V, not +3.3V.

Finally, as discussed by Oleg Mazurov here the NFC shield library sets the SPI bus bit order to LSB first, which is the opposite of what everybody else uses.  Fixing this for the version of the library on my machine requires this patch:


diff --git a/PN532_SPI/PN532_SPI.cpp b/PN532_SPI/PN532_SPI.cpp
index 99ece85..250cb97 100644
--- a/PN532_SPI/PN532_SPI.cpp
+++ b/PN532_SPI/PN532_SPI.cpp
@@ -7,6 +7,11 @@
 #define DATA_WRITE      1
 #define DATA_READ       3

+uint8_t PN532_SPI::reverseLookup[] = {
+       0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
+       0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf,
+    };
+
 PN532_SPI::PN532_SPI(SPIClass* spi, uint8_t ss)
 {
     command = 0;
@@ -20,7 +25,6 @@ void PN532_SPI::begin()

     _spi->begin();
     _spi->setDataMode(SPI_MODE0);  // PN532 only supports mode0
-    _spi->setBitOrder(LSBFIRST);
 #if defined __SAM3X8E__
     /** DUE spi library does not support SPI_CLOCK_DIV8 macro */
     _spi->setClockDivider(42);             // set clock 2MHz(max: 5MHz)
diff --git a/PN532_SPI/PN532_SPI.h b/PN532_SPI/PN532_SPI.h
index 53ff697..f601c28 100644
--- a/PN532_SPI/PN532_SPI.h
+++ b/PN532_SPI/PN532_SPI.h
@@ -24,12 +24,18 @@ private:
     void writeFrame(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0);
     int8_t readAckFrame();

+    static uint8_t reverseLookup[16];
+
+    inline uint8_t reverse(uint8_t v) {
+        return (reverseLookup[v & 0xf] | reverseLookup[v >> 4]);
+    }
+
     inline void write(uint8_t data) {
-        _spi->transfer(data);
+        _spi->transfer(reverse(data));
     };

     inline uint8_t read() {
-        return _spi->transfer(0);
+        return reverse(_spi->transfer(0));
     };
 };