I buffer MISO coming back from 3.3V devices to:
a) prevent poorly behaved devices from interfering with MISO from other devices when not selected
b) prevent 5V from being applied to 3.3V devices - a good example is Programmers connected to ICSP pins.
c) prevent input diode protection on 3.3V devices from dragging down 5V signals.
My method is typically use cd74HC4050 to buffer 5V down to 3.3V, and some form of HC125 to enable 3.3V MISO onto 5V MISO line using the devices chip select. Put a pullup resistor on the Chip Select line so the buffer is not accidentally active due to a floating pin when the microcontroller is being reset. You can see that in U9 and U10 here, with the pullup on D10:
#include <SPI.h> #include <Mirf.h> #include <nRF24L01.h> #include <MirfHardwareSpiDriver.h> #include <MirfSpiDriver.h> #include <SD.h>
const int SelectSD = 4; // pinnenummer brukt for CS til SD-kortet
const int Radio_CSN = 10; // pinnenummer brukt for CSN på radio (ikke endre denne)
const int Radio_CE = 8; // pinnenummer brukt til CE på radio (kan være uansett ledig pin)
const byte payload = 4; // max er 32 bytes i hver pakke.
union
{
byte ch[payload];
long tid;
} rx_buffer ;
void setup()
{
SD.begin(SelectSD);
Serial.begin(9600);
digitalWrite(SelectSD,HIGH); // disable sd-kortet
Mirf.csnPin = Radio_CSN; ; // kan endres etter behov. Kan utelates hvis default
Mirf.cePin = Radio_CE;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = payload;
Mirf.channel = 101; // any channel: 1..125 (avtales med den som sender)
Mirf.config();
Mirf.setRADDR((byte *)"aaaaa"); // sett inn 'receive'-navn - alltid 5 tegn!
digitalWrite(Radio_CSN,HIGH); // disable radio
digitalWrite(SelectSD,HIGH); // disable sd-kortet
}
void loop()
{
digitalWrite(Radio_CSN,LOW); // enable radio
while(!Mirf.dataReady()) {}; // wait for data to arrive
Mirf.getData(rx_buffer.ch); // read to buffer
Serial.println(rx_buffer.tid);
digitalWrite(Radio_CSN,HIGH); // disable radio
digitalWrite(SelectSD,LOW); // enable sd-kortet
if (File dataFile = SD.open("testA.txt", FILE_WRITE))
{
dataFile.println(rx_buffer.tid); // 'tid' is time (millis() from sender)
dataFile.close();
}
else Serial.println("Can't save");
digitalWrite(SelectSD,HIGH); // disable SD-card
}
Thanks for this mod, If I understand your image correctly.
It says that cut connection of pin 13 in that chip from ground and connect CE to pin 13 of the chip.
Is it correct?
I am facing the exact same while trying to connect an micro sd card reader and rf24 together on one uno.
if i disonnect the SD reader it works. If i connect both the radio initialisation fails.Cause i got a micro sd reader the connections are all stuffed together so no modding opportunity.Is there any way know to make them work together anyway ?.Heres the code i use :
I have heard that this condition is related to the SD card. And some people have had success by just sending null out on the SPI bus after SD card functions. Like this:
void setup() {
Serial.begin(115200);
printf_begin();
pinMode(SD_CHIP_SELECT, OUTPUT);
digitalWrite(SD_CHIP_SELECT, HIGH);
if (!SD.begin(SD_CHIP_SELECT)) {
Serial.println("CardBegin failed");
}
else{
Serial.println("CardBegin succeded");
}
SPI.transfer(0); // just activate the SPI SCK for 8 pulses, none of the devices on the bus
// have their CS pin low, so there should be no reaction, but sometimes the SD card does not release
// the MISO pin until it sees a few clocks, so by sending a null without any CS driven low it tends to
// 'clear' the SPI bus
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setRetries(15, 15);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
radio.startListening();
radio.printDetails();
Serial.println("RadioBegin succeded");
}
One other question, do these two libraries(RF24.h and SDFat.h) correctly control the SPI bus?
look through their code, look for calls to SPI.beginTransaction() and SPI.endTransaction().
If they only use SPI.setBitOrder(), SPI.setClockDivider(), SPI.setDataMode(), BOTH Libraries MUST use the EXACT SAME parameters.
If they use different config options, that could be why only one will work at a time.
As this is nothing but a temporary solution to the problem, is there any sd card modules out there that work out of the box? I have tried this mod, but it don't seem to work at all with my nRF24L01+ module.
I have never seen one.
The chineese designers should have made this easy fix a long time ago.
You say you have done the fix to your card. (and you are of course sure thats OK)
The next step is to make sure that the radio has its (often) necessary fix: The module will fail if its powerline ins't a clean voltage. Add a cap (10uF +/-) directly onto the module.
(you will find pictures/discussions on problem this fix in this forum)
Also this one has Dout directly to Arduino MISO (which is our problem)
Solution: Force the SD-card to release the line or add a buffer to 'stop' the signal
I have also come across this problem, attempted mod and first time damaged the card during soldering, second time ok and works fine. There is however a module " Adafruit 254 micro Sd breakout board " works out of the box and seems faultless ,I obtained mine from Maplin. Hope this helps.