Using nRF24 and SD card module together

Hy,

in my project I try to receive values via the RF24 module (using libraries RF24 and RF24network) and store them to an SD card via an SD card module (using SPI and SD library).

Unfortunately, as soon as I put the MISO pin of the SD card module into the breadboard (11, 12, 13 are shared for RF24 and SD card SPI), the values are not received any longer.

I tried to figure out the signal by using an OSZI Probe but as soon as I stick in the cable of the probe to the breadboard the communication stops. Taking the cable out continues the retrieval of the values.

If the SD card module is connected, the SD card can be initalized and seems to work properly but as described, I can then not receive the values to be logged.

Already tried the use of 10uF capacitors between 3.3V and GND.

Thanks for any suggestions!

Regards,
Daniel

PS: The SD card module operates on 5V and RF24 on 3.3V (SD card module has a level shifter inlcuded)

Insure you set all SPI slave selects high before initializing any of them.

Also, there is a bug in the SD library. The SD card may not release the MISO line in all cases, so a couple changes must be made to the SD library. The required changes are in this post by fat16lib.

Thanks for the reply!

I have checked all lines and the signals, as far as they can be measured are OK. (All SS pins are HIGH/LOW as they should be, no signal on MISO line while SS of SD card module is HIGH).

To me it seems more like an circuit design issue. As soon as I try to measure the signal of the RF24 MISO line with the Oszi probe, the values are not retreived any longer. Taking out the probe continues the transmission.

I have already played around with different caps on the supply lines without success.

Regards,
Daniel

Try the mod SurferTim suggests, and also be sure the SPI speeds have not been changed when switching between the sdcard and the nRF.

Are you initializing the SD card or just disabling the SPI (SS HIGH)?

Did you apply the bug fix as fat16lib suggested?

edit: What pin are you using for the SD card slave select?
What pins are you using for the CE and CSN on the nRF24?

pito:
Try the mod SurferTim suggests, and also be sure the SPI speeds have not been changed when switching between the sdcard and the nRF.

..or better try to run the sdcard and the nRF at the same SPI speed..

Hy,

I'm using 9,10 for the RF24 module as per the RF24 library standard. SD card module SS is set on pin 4.

I have already tried the bugfix for the library without success.

The weird thing is, the radio stops working even if I only put the Oszi probe into the breadboard to measure the signal. Is it possible that the signal is too weak if an additional component is added?

Will try the SPI issue and comment back.

PLS find below my example code (Currently not including any SD card outputs). Is there a possibility to change the pinmapping of SPI temporary e.g. from 12 to 6 for the SD card module?

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>
#include <SD.h>

// nRF24L01
RF24 radio(9,10);
 
// Network
RF24Network network(radio);
 
// Node Adresses
const uint16_t this_node = 0;
const uint16_t other_node = 1;
 
// Initialize payload structure _payload_t_
struct payload_t
{
  float Data[4];

};

void setup(void)
{
  Serial.begin(9600);
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,DMS1,DMS2,DMS3");
 
  //--------DEBUG----------------
  pinMode(4,OUTPUT);
  pinMode(10,OUTPUT);
  digitalWrite(4,HIGH);
  digitalWrite(10,HIGH);
  //-----------END DEBUG-----------
  
  SPI.setClockDivider(SPI_CLOCK_DIV2); // 16/2 MHz (Check equal speed)
  
  SPI.begin();
  
  SD.begin(4); //SS on pin 4
  
  radio.begin();
    
  network.begin(/*channel*/ 90, /*node address*/ this_node); 
  
}

void loop(void)
{

  // Pump the network regularly
  
  network.update();
   
  while ( network.available() )
  {
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    float Data[sizeof(payload)];
   
   //Excel-DAQ
     for (int i = 0; i < sizeof(payload)/4; i++)        //long in the range needs 4 bytes 
      //sizeof(payload) = number of values x 4
    {   
      Serial.print("Probe");
      Serial.print(i);
      Serial.print("  ");
      Serial.print(payload.Data[i]);
      Serial.println(",");

    }
    if (int i = sizeof(payload)/4 - 1)                 //since sizeof(payload) = number of sensors x 4 then number of sensors
      //is quarter the sizeof(payload)
    {
      Serial.println("");
      Serial.print("Received ");
      Serial.print(sizeof(payload)/4);
      Serial.println(" Readings from Arduino");
      Serial.println("");
    }
  }
}

The sd.begin and the radio.begin may set the spi clock speed differently. Double check what are the spi speeds. Set spi clock equally in the sdcard driver and in the radio driver for testing purposes.

Adding oscope probe may (will) change the behavior of a circuit. It depends where you measure and how is the impedance of your probe (set it 1:10).

As a test, try a slower SPI speed after SD.begin(4). The SD startup sets the SPI bus speed pretty high. Maybe you have a bit too much capacitance on your breadboard circuit to run that fast.

  SPI.begin();
  
  SD.begin(4); //SS on pin 4

  SPI.setClockDivider(SPI_CLOCK_DIV8); // 16/8 = 2MHz
  
  radio.begin();

SD Cards tend to draw a lot of power, so a separate power supply is generally required if trying to operate SD + nrf24l01+ from an Arduino. Some SD cards have built-in 3.3v regulators, and running the radio off that instead of the Arduino 3.3v works sometimes also.

You can also try using softSPI or SPI_UART to give yourself a second SPI BUS and rule out any SPI conflicts. See https://github.com/TMRh20/RF24/issues/24#issuecomment-57610280 and Sketches/SPI_UART at master · TMRh20/Sketches · GitHub

Thanks for all the inputs.

I have measured the behavior of the MISO line of the SD card with my Oszi and it seems that it stays in HIGH state while the program is running. Only during upload cycle the signal changes the state HIGH/LOW a few times. Afterwards it stays high, even after I have implemented the changes in the SD library that where suggested above.

Any idea whether there is an additional bug in the SD library that blocks the MISO line?

I have checked the SPI speeds now and they are the same in both libraries (SD and RF24). It seems the problem arises by the blocked MISO line.

I also brought the Oszi to work. Switching the probe to 1/10 solved the issue, as was suggested above.

Hy,

using SoftSPI for the SD card module worked. Using HardwareSPI was not possible since I could not mange to switch off the MISO line of the SD card module. It seems to just block it.

THX for your inputs.

DesertEagle:
Hy,

using SoftSPI for the SD card module worked. Using HardwareSPI was not possible since I could not mange to switch off the MISO line of the SD card module. It seems to just block it.

THX for your inputs.

Hello,

If you are using MicroSd card Adapter (catalex v1.0 ) just like me. Nothing can help you, to make it works with another device on same SPI line.
The reason:
It uses SN74LVC125A http://www.ti.com/lit/ds/scas290q/scas290q.pdf as level shifter. In order to work with other devices the chip has to release all the lines. It will happen if he go in So called Z state. So the device can`t affect the logical state of the line. The Z state wil lbe acheaved if 1OE, 2OE, 3OE , 4OE goes HIGH (see 9.4 Device Functional Modes).

BUT. The Designers of the board decided to solder all needed pins to GND in this way it will block the SPI cos it will have L or H (it does not matter which is true).

The Only ONE solution without modification of the bord will be softwareSpi for the other devices

nikitz:
Hello,

If you are using MicroSd card Adapter (catalex v1.0 ) just like me. Nothing can help you, to make it works with another device on same SPI line.
The reason:
It uses SN74LVC125A http://www.ti.com/lit/ds/scas290q/scas290q.pdf as level shifter. In order to work with other devices the chip has to release all the lines. It will happen if he go in So called Z state. So the device can`t affect the logical state of the line. The Z state wil lbe acheaved if 1OE, 2OE, 3OE , 4OE goes HIGH (see 9.4 Device Functional Modes).

BUT. The Designers of the board decided to solder all needed pins to GND in this way it will block the SPI cos it will have L or H (it does not matter which is true).

The Only ONE solution without modification of the bord will be softwareSpi for the other devices

i wish i read this 4 days ago... solder everything 2 times still not working , so i need a other SD card adapter.

I found one article where nick VK2FH wrote this:

I had the same problem with an RFID-RC522 card which wouldn't work when the Catalex module was connected. I put a 2K2Ω resistor between MISO on the Catalex MicroSD card and MISO (Pin 12) on the Arduino (pro mini) and it is working fine now.

And wuala it works. Now I can read from SD and write received data to SD module connected on normal SPI pins. (11,12,13)

rc522 is powered 3.3V and catalex SD is powered from 5V power source connected to raw pin.

SD-card MISO release hardware fix

Bad MISO! Software fix:
http://forum.arduino.cc/index.php?topic=276274.0