I am having trouble getting a couple of SPI devices to share nicely.
I thought that I remembered seeing a sketch somewhere for listing the SPI devices connected to an Arduino and whether they are communicating with the Arduino. However I cannot find it now.
Has anyone seen this sketch and able to tell me where to find it?
SPI is a master slave protocol. You have a master device which has complete control over which slaves are talking via the use of chip select pins.
The master selects a device to talk to, and then uses the clock like to control data flow between the slave and it. It doesn't make sense that more than one slave can be talking because otherwise their MISO line drivers will short each other out.
You shouldn't need to list the devices connected, because it is not dynamic, you have each device hard wired to its own CS (SS) pin on the arduino.
I thought that I remembered seeing a sketch somewhere for listing the SPI devices connected to an Arduino and whether they are communicating with the Arduino. However I cannot find it now.
Thanks Riva. You are right. That was the one I was thinking of.
@ Tom Carpenter.
Thanks Tom. You state the theory but as other threads has shown, the practice is often different.
I have both devices with their own SS and they both work individually. Put them together and one of them stops working.
I have both devices with their own SS and they both work individually. Put them together and one of them stops working.
With SPI you can have multiple devices, the SCLK, MOSI & MISO is connected to all the devices in parallel and then you need a separate arduino SS output pin to each device. Initially set all the SS pins to output and HIGH and then when you want to talk to a device set it's (and only it's) SS output LOW and talk, when your finished talking set the SS pin HIGH again. Depending on what SS pin is low determines what device will answer.
I notice that you are using the SPI library for the Pot, how are you initialising it? If you are using SPI.begin() then you will run into a problem as by default it configures the SPI bus for Mode3. This is fine for the Pot, however the RF module requires SPI mode 0. This means if the bus is configured for mode 3, the pot will work and the RF wont.
If however you configure the SPI for mode 0, both will work as the Pot datasheet indicates that it too supports mode 0.
I suggest commenting out the SPI.begin() call, as the RF22.cpp does the initialisation itself.
I am of course assuming you are using SPI.begin(), but as you havent posted your full code, I can't know for sure.
Edit:
On second thoughts, SPI is mode 0 by default... Hmmm.
What I suggest you do is to also run the Pot at 3.3v. If the pot is running at 5v, the RF will see +5v on its MISO line when not running which could cause a problem.
You don't need to worry about level shifting the SPI lines to the Pot even if it is running at 3.3v as it won't do any harm. The only thing you have to watch out for is the SS line, this does need to be level shifted as otherwise it may detect the voltage as what it calls Vihh (the value of which the datasheet doesn't actually tell you!) at which point the SS line has reversed meaning. summary connect pot's vdd to 3.3v, and level shift the SS pin.
The pot has MISO and MOSI on the same pin (don't know how that works). But as I am only sending commands from the micro to the pot and none back, I have only connected MOSI.
But I will try level shifting the SS pin and running the pot at 3.3v.
Thanks for the help.