Hello,
I am working on a small project that uses an Arduino compatible board (Teensy 3.2), an RFID module (Velleman VMA405) and the microSD module from an LCD display (Velleman VMA412) .
I can't make the RFID and SdFat libraries working together. Here is a simple test code:
#include "spi4teensy3.h"
#include "RFID.h"
#include <SdFat.h>
#define RFID_CS 10 // RFID board ChipSelect signal
#define RFID_RST 9 // RFID board Reset signal
#define SD_CS 16 // SDcard ChipSelect signal
RFID rfid(RFID_CS,RFID_RST);
SdFat SD;
void setup() {
Serial.begin(9600);
SPI.begin();
delay (100);
rfid.init();
delay (100);
//SD.begin (SD_CS, SD_SCK_MHZ(10));
}
void loop() {
while (true) {
if (rfid.isCard()) {
char msg[50];
rfid.readCardSerial();
sprintf (msg,"RFID: %i,%i,%i,%i,%i",rfid.serNum[0],rfid.serNum[1],rfid.serNum[2],rfid.serNum[3],rfid.serNum[4]);
Serial.println (msg);
}
}
}
As soon as I uncomment the "SD.begin() line", I can't no longer read any RFID tags. Even if I physically disconnect the microSD module. I tried to swap RFID and SDFat initialisation code, but same result.
Also, if I remove the "delay()" after the "SPI.begin()", the reader is no longer working
I am using SDFat 1.0.5 from Bill Greiman and the RFID Library from Miguel Balboa (Jan, 2012).
Thanks for any suggestion.
Both the SD card and the RFID module are using SPI so you either need to connect them to separate SPI busses on the Arduino (you probably will have to bitbang (software emulate) at least one of them), or you have to connect the CS/ChipSelect/Enable pins on both modules to extra GPIOs so you can select which module you want to talk to at the moment.
Thanks for your reply. But that's how this is already done: each module has its own select line. In addition, this is certainly not a hardware conflict since the RFID library stops working even when the microSD module is not physically connected
I captured the initialization sequence of the RFID module with/without a call to "SD.begin()" before "rfid.init():
The 2 last packets are not sent if the SD module is initialized. That's normally done by this function in RFID.cpp:
void RFID::antennaOn(void)
{
unsigned char temp;
temp = readMFRC522(TxControlReg);
if (!(temp & 0x03))
{
setBitMask(TxControlReg, 0x03);
}
}
If "setBitMask()" is not called this is obviously because temp is not equal to 0x80 as returned by the RFID module on the bus.
That means "SPI.transfer()" (used by "readMFRC522()") does no longer return valid data from the bus after the call the "SD.begin()" .
I still have to discover why ...