Sketch for listing attached SPI devices?

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.

I think your confusing SPI with I2C. Nick Gammon has a I2C scanner on his website Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino

I think your confusing SPI with I2C.

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.

Do you have links to datasheets for both devices? And could you post the communication bit of your code.

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.

The two devices are a transceiver module:
http://www.hoperf.com/upload/rf/RFM22B_23B.pdf

and a digital potentiometer:

The code for the digital pot is:

byte writecmd = B00000000;
uint8_t SolarSS = 36;

 if (voltage < 11)
    {
      if(Wiper > 2)
      {
        Wiper--;
        digitalWrite(SolarSS,LOW);
        SPI.transfer(writecmd);
        SPI.transfer(Wiper);
        digitalWrite(SolarSS,HIGH);
      }

The code for SPI write for the radio module is buried in a library that I use:
http://www.open.com.au/mikem/arduino/RF22/RF22-1.19.zip

SS for the radio module is pin 53.
SS for the pot is pin 36.
Both are set as OUTPUT.

Both devices work individually but when they are both put on the bus the pot works fine but the radio initialises OK but will not receive or transmit.

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.

Are you making sure that pin 53 is pulled LOW before trying to use the radio?

PaulS:
Are you making sure that pin 53 is pulled LOW before trying to use the radio?

The RF22.cpp code he posted does that itself.

Here is one for you, how are you accounting for the fact that the RF module runs at 3.3v? Could you post your circuit.

It is a custom board with two regulators, providing 5v and 3.3v.

I use 1.8k/3.3k voltage dividers on MOSI, SCK and SS of the radio module.

The interupt and Miso pins from the radio to the Atmega connect directly. The 3.3 v signals have proven OK in standalone mode.

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.