NRF24 and SD card on same SPI

Hi,

I am trying to include a SD card and nrf24 module in my project (using an Arduino nano old bootloader). I test the SD card module and the nrf24 separately and they work fine. However when I connect both modules at the same time only the SD card module works; the nrf24 doesn't.

Hardware connections:
nrf24:
-CE pin 7
-CSN pin 8

SD module:
-CS pin 10

The rest of the connections are the standard SPI hookup. The wiring is verified by the fact that the modules work when tested individually.

test SD:

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

#define sd_chip_select 10

struct Settings
{
  struct Trimmings
  {
    int ch1 = 0;
    int ch2 = 0;
    int ch3 = 0;
    int ch4 = 0;
  } trim;

  struct DualRates
  {
    unsigned ch1 = 100;
    unsigned ch2 = 100;
    unsigned ch3 = 100;
    unsigned ch4 = 100;
  } dualrates;
} settings;

void sd_setup();
void save_dualrates();
void sd_read_duals();

void sd_setup()
{
  SD.begin(sd_chip_select);
}

void save_dualrates()
{
  SD.remove("dual.txt");
  File sd = SD.open("dual.txt", FILE_WRITE);

  if (sd)
  {
    sd.write((unsigned char *)&settings.dualrates, sizeof(settings.dualrates));

    sd.close();
  }
}

void sd_read_duals()
{
  File sd = SD.open("dual.txt", FILE_READ);

  if (sd)
  {
    sd.read((unsigned char *)&settings.dualrates, sizeof(settings.dualrates));

    sd.close();
  }
}

void print_dual()
{
  Serial.print(settings.dualrates.ch1);
  Serial.print("  ");
  Serial.print(settings.dualrates.ch2);
  Serial.print("  ");
  Serial.print(settings.dualrates.ch3);
  Serial.print("  ");
  Serial.println(settings.dualrates.ch4);
}

void setup() 
{
  Serial.begin(9600);
  sd_setup();
  
  //simulate editing dual rates
  settings.dualrates.ch1 = 56;
  settings.dualrates.ch2 = 78;
  settings.dualrates.ch3 = 90;
  settings.dualrates.ch4 = 23;
  print_dual();
  
  save_dualrates(); //check SD card on PC after this.
  
  //simulate power down and up again
  settings.dualrates.ch1 = 100;
  settings.dualrates.ch2 = 100;
  settings.dualrates.ch3 = 100;
  settings.dualrates.ch4 = 100;
  print_dual();
  
  sd_read_duals();
  print_dual();
  //print dualrates
}

void loop() {
  // put your main code here, to run repeatedly:

}

test nrf24 (using the tmrh20 library):

#include <SPI.h>
#include "RF24.h"

#define RECEIVER

RF24 radio(7, 8);

uint8_t address[][6] = {"Node1"};

struct Data
{
  unsigned char ch1;
  unsigned char ch2;
} data;

void setup()
{ 
  Serial.begin(9600);

  radio.begin();
  radio.setAutoAck(false);
  radio.setRetries(0, 0);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setPayloadSize(sizeof(data));
#ifdef RECEIVER
  radio.startListening();
  radio.openReadingPipe(1, address[0]);
#else
  radio.stopListening();
  radio.openWritingPipe(address[0]);
#endif
}

void loop()
{
#ifdef RECEIVER
  if (radio.available())
  {
    radio.read(&data, sizeof(data));

    Serial.print(data.ch1);
    Serial.print(" ");
    Serial.println(data.ch2);
  }
#else
  radio.write(&data, sizeof(data));
  data.ch1 += 1;
  data.ch2 += 2;
  delay(500);
#endif
}

note that for the test nrf24 code there is another Arduino acting as a transmitter (by uploading the same sketch but without defining RECEIVER).

When I upload the test nrf24 sketch with the SD card module connected I get a continuous stream of "0 0" separated by a newline. When I upload the test SD sketch the output is as expected with both the nrf24 connected or disconnected.

Apart from the possibility that pins 8 & 10 are somehow connected to each other. Have you excluded this possibility?

Just tested this with the continuity mode of a multi-meter and the two pins are not connected.

Some SD card modules will not play well with other devices on the SPI bus. The problem is with the way the level shifter on the SD module is wired. The ones that do not work well have the MISO signal running through the level shifter. That causes the MISO signal to not be released so that the other devices can control it. The modules made by Adafruit (and some others) have the MISO signal going from the SD card straight to the MISO, bypassing the level shifter. Look at the schematic for the Adafruit module to see what to look for. DO (data out) is the MISO signal.

I see. What is the solution then? To bypass the logic shifter by wiring the SD card's MISO pin straight to the module's MISO pin?

If you're really committed to this particular SD module, you could always include a CMOS switch in your circuit that connects MISO to either the SD or the MRF depending on one of the chip select lines.

There are pages on the internet that show how to modify the SD card modules to work right. The work is very fine and I did not manage to get one to work. Just ended up ruining a SD card module. Your results may be more successful.

So I scavenged a SD card receptacle from a busted printer and made my own module with a CD4050 hex buffer wired like is shown in the Adafruit schematic that I linked. Works great with my rf24.

Thats one solution.

The other is to just use 3.3V Arduinos and the SD breakouts that dont have any electronics.

SD cards will work just fine when connected directly to 3.3V Arduinos.

I also have the following SD card modules laying around:
41JN2MPxLoL.AC_SS450

The thing that I'm not sure about is whether I need to use a logic level converter or not.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.