SPI with 2 devices on the same pins

Hi everyone!

I want to take a picture with the ArduCam OV5642 and store it to a SD card.
My OV5642 is on a 'RevC' shield, it has SPI connection for the data, and I2C connection for the parameters.
My SD card reader has SPI connection.

Is it possible to plug my cam & my SD card on the same pins for the SPI ? I used a code from ArduCAM, and it says there is an SPI problem... Any idea of making them work together ?

MOSI - 11
MISO - 12
SCK - 13
CS_Cam - 10
CS_SD - 7

Thank's,

I2C uses addresses to the devices connected and several units can be connected, assuming they use different addresses.
About SPI, Goggle and study the concept, what it is suitable for, how it works.

Your pin connections should work. You will need to post more details if we are to figure out what is wrong.

Like i2c, SPI is a "bus" system where multiple devices share the same pins. On i2c bus, each slave device has a different address, and that is how each slave device knows when to receive instructions or send results to the Arduino (the master). But in SPI bus, there are no addresses. Instead, each slave has a separate "chip select" pin which changes from high to low when that slave should listen/respond to the master. From your description, your slave devices are sharing the clock and data pins, and have separate chip select pins, which is, in theory, correct.

Have you got each library to work on its own? If so and you find the two devices do not work when connected to the same SPI buss, w differing cs pins, then the issue may very well lay with the libraries. For each SPI device the library will have SPI bus settings. If the settings for each library are in conflict with the other library then issues happen.

Consider one SPI device is ran at 1hz and the other device at 2hz. As may be seen the 1hz device would have issues with keeping up with a 2hz clock. You may have to compare the libraries SPI settings and bring the libraries into equality.

Or one of the SPI devices is a full duplex and the other device is not, if the SPI engine is setup to give you full duplex and one device is not full duplex, then the non duplex device will have issues.

Does your SD card module have a level shifter on it? Some SD modules with level shifter are wired so that the MISO line is not released properly. Those SD card modules do not like to play well with other SPI devices.

Thanks a lot for the reply. I've found this :

This is exactly my problem.
It looks like my SD card reader cannot release the SPI bus.

Idahowalker:
Consider one SPI device is ran at 1hz and the other device at 2hz. As may be seen the 1hz device would have issues with keeping up with a 2hz clock. You may have to compare the libraries SPI settings and bring the libraries into equality.

Or one of the SPI devices is a full duplex and the other device is not, if the SPI engine is setup to give you full duplex and one device is not full duplex, then the non duplex device will have issues.

ok I understand better, but I have difficulties finding the SPI bus settings for the 2 libraries (SD and ArduCam), in order to synchronise them. Do you have any idea of where to find these information ?

groundFungus:
Does your SD card module have a level shifter on it? Some SD modules with level shifter are wired so that the MISO line is not released properly. Those SD card modules do not like to play well with other SPI devices.

Yes I think there is one, as you can see in the following picture. I bought it on Ali...
picture

I will first try to use a transistor to "close" my MISO SD card reader, not sure if it will work. If else I will find another SD card reader.

I think there is one, as you can see in the following picture.

First of all, please post your pictures by attaching them to your post, not linking to a sharing site. Some of those sites are simply annoying and others are downright intrusive, there's no need to use them here. You can make your attached pictures appear in your post by attaching, posting, copying the address, modifying the post and using the insert image icon. It's a bit awkward for you, yes, but better for the other forum members.

Which component(s) on the board is a level shifter?

groundFungus:
Does your SD card module have a level shifter on it? Some SD modules with level shifter are wired so that the MISO line is not released properly. Those SD card modules do not like to play well with other SPI devices.

You mean the level shifter does not go "tri-state" (high impedance) when the CS line is high? I can see how a cheap or thoughtless design would not have that ability.

PaulRB:
You mean the level shifter does not go “tri-state” (high impedance) when the CS line is high? I can see how a cheap or thoughtless design would not have that ability.

That is a well known problem with some of the commonly available microSD card modules, particularly with ones labeled “Catalex”. There is a fairly easy fix for the problem that involves removing the ground connection to the enable pin for the MISO buffer and instead connecting it to the CS line.

I've seen one report that the MISO non-release problem can be worked around by inserting a resistor (I think 3.3K) into the MISO line going to the SD card module. Apparently MISO still works ok through the resistor when the SD module is active, and it just acts as a pullup or pulldown resistor when the other device is active, so it still works too. But I haven't tried it, and there might be speed consequences.