Hello, I am trying to run two SPI devices on my NANO - an RF24 module and a SD card reader. Both work fine independently and are using different CS pins. It appears that the SD library locks the MISO pin so subsequent use by the RF library fails. I saw this mentioned in another post - https://forum.arduino.cc/t/problems-with-arduino-uno-spi-microsd-module-and-spi-max6675/960023
But no clear resolution. Any thoughts? I only need the SD card to start then I can shut it down completely and leave the MISO pin strictly for the RF module.
Thanks
EDIT: I just saw an example of using the SPI interface directly. Not sure how hard that would be but I wonder if that would fix this problem...
Can you share your code ?
SD libraries do initialize the CS pin, but tend not to switch it HIGH when the bus could be free for other devices.
Try to set the SD-CS pin HIGH between actual read & write to and from the SD card. With the CS pin LOW the SD card will respond to the data on the MOSI thru the MISO even though messages are not intended for it. Things may even break. This may also be the case for the RF library btw.
Well, I tried setting CS high and it had no effect.
I saw that about the tri-state buffer but I was hoping to fix this in software without having to make a more complicated circuit. I guess I will investigate that possibility.
Thanks for the replies.
Hi, I am the guy from the other post. The tri-state buffer was a solution to isolating the micro sd module from the SPI bus because it was not releasing the MISO channel. But that is a solution for my particular board, I know there are some that work ok and no need to do modifications to the board or isolate.
The second problem I was having was with the libraries I was using. Do you have an osciloscope to check what is going on with the SPI bus when you run the SD.begin() line?
In my case, if I remembre correctly, the thermocouple module was using a software SPI instead of the hardware SPI. So when I would run the SD.begin() command, it would deconfigure the software SPI from the MAX6675.
I would do some more research on what does each of the libraries you are using use. If the hardware SPI or it builds its own software SPI.
If you don't have a oscilloscope to chech the SPI bus and see what happens, but if both modules work individualy (and if the RD24 module library allows to define all SPI pins) what you could do is set those pins different than the SD.h library. This did work for me
Thanks for the reply. The RF24 library does not allow me to specify the MISO and MOSI pins unfortunately. The SD library is the standard Arduino library v 1.2.4. I have not been able to figure out if they are using software or hardware SPI. Not sure where I would find that without really digging into the source code. I do have an oscilloscope so I may try to debug the bus. I will also order some tri-state buffers. Thanks for your help.
I think all you have to do is connect the Data Out pin of the SD card holder directly to the MISO header, and cut the trace from the level shifter gate output to the MISO header. The card itself will behave properly, and release MISO when its CS is not selected. If your microSD module looks like mine, these pictures demonstrate what to do.
I should add that the Adafruit microSD card adapter does it this way, and it plays well with others. A 3.3V output on MISO from the card will be received as a high by a 5V processor. Actually, there was no point routing MISO through the level shifter in the first place since it just shifted it from 3.3V to 3.3V.
Well I wish I could claim credit for discovering it, but it's just a problem I kept reading about here and elsewhere, and someone said the Adafruit module didn't have that problem, so I looked at that schematic, which led to the solution.
It's odd that the module makers of the Far East continue to pump out these modules by the thousands. You'd think word would have gotten back to them by now. Anyway, the standard full-size SD card module has an even bigger problem. So maybe we should just all buy from Adafruit.
I bought mine on AliExpress Cheap as chips and simple and works as a 3.3v device without issue. Might be more complex on a 5v logic system. Still it is so simple that all it is is a holder and a few pullup resistors. When i found some loose holders i tried to copy the schematic, and that was easy enough, now i can simply put a holder on a custom PCB and add a few resistors.
This is interesting. Now that I look at the SD card board, I see that there is only a voltage regulator and a quad tri-state buffer chip. So are all the "smarts" actually built into the media card itself??