Author Topic: Arduino / RFID / SDFat mysteries  (Read 1278 times)

0 Members and 1 Guest are viewing this topic.

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Arduino / RFID / SDFat mysteries
« on: March 16, 2018, 11:41:39 am »
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:

Code: [Select]
#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.
 

Offline matseng

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: se
    • My Github
Re: Arduino / RFID / SDFat mysteries
« Reply #1 on: March 16, 2018, 11:52:16 am »
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.
 

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: Arduino / RFID / SDFat mysteries
« Reply #2 on: March 16, 2018, 01:06:34 pm »
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  :-//
 

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: Arduino / RFID / SDFat mysteries
« Reply #3 on: March 16, 2018, 05:22:35 pm »
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:
Code: [Select]
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 ...
« Last Edit: March 16, 2018, 05:24:34 pm by ggchab »
 

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: Arduino / RFID / SDFat mysteries
« Reply #4 on: March 16, 2018, 05:41:02 pm »
Code: [Select]
#define USE_STANDARD_SPI_LIBRARY 0
must be changed to

Code: [Select]
#define USE_STANDARD_SPI_LIBRARY 1
in file SdFatConfig.h   :palm:

 
The following users thanked this post: matseng


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf