Hello,
I was trying to do some BT handover with my NFC shield V2 and then exchange data between the SD card on my arduino ethernet but I have some problems with card emulation. It finally managed to init both the SD and the NFC (only activated the pn532 without emulation) with the spi by switching the mode from LSB to MSB but as soon as I add the code for starting emulation nothing work anymore (not even the start message on the console). Same thing happens if I use the “setNdefFile” in the setup. Here is the test code I’m curently using to make the NFC emulation and SD card work at the same time.
#include "SD.h"
#include "SPI.h"
#include "PN532_SPI.h"
#include "emulatetag.h"
#include "NdefMessage.h"
//def SD
#define SD_CS 4
//def nfc
#define PN532_CS 9
//def nfc
PN532_SPI pn532spi(SPI, PN532_CS);
EmulateTag nfc(pn532spi);
uint8_t ndefBuf[120];
NdefMessage msgnfc;
int msgnfcSize;
uint8_t uid[3] = { 0x12, 0x34, 0x56 };
/* Chip select routine */
void spiSelect(int CS) {
// disable all SPI
digitalWrite(PN532_CS,HIGH);
digitalWrite(SD_CS,HIGH);
// enable the chip we want
digitalWrite(CS,LOW);
switch(CS){
case PN532_CS:
SPI.setBitOrder(LSBFIRST);
break;
default:
SPI.setBitOrder(MSBFIRST);
break;
}
}
void setup() {
//init console
Serial.begin(19200);
Serial.println("Start test");
pinMode(PN532_CS,OUTPUT);
pinMode(SD_CS,OUTPUT);
spiSelect(SD_CS);
if (!SD.begin(4)) {
Serial.println("Error init SD!");
return;
} else {
Serial.println("init SD Ok.");
}
spiSelect(PN532_CS);
//init nfc tag
msgnfc = NdefMessage();
msgnfc.addUriRecord("weceipt-box:autoLaunch?boxId=0.0.0.1");
msgnfcSize = msgnfc.getEncodedSize();
if (msgnfcSize > sizeof(ndefBuf)) {
Serial.println("ndefBuf is too small");
while (1) { }
}
Serial.print("Ndef encoded message size: ");
Serial.println(msgnfcSize);
msgnfc.encode(ndefBuf);
// comment out this coMmmand for no ndef message
//nfc.setNdefFile(ndefBuf, msgnfcSize);
// uid must be 3 bytes!
nfc.setUid(uid);
if(!nfc.init()) {
Serial.println("Error init NFC!");
return;
} else {
Serial.println("init NFC Ok.");
}
}
void loop() {
spiSelect(PN532_CS);
// NFC uses LSB first so we have to explicitly set that
//nfc.emulate();
}
If you have any idea it would be great
Thank you!