Multiple SPI devices: sd shield, rtc & adc

Hi all,

Relative newbie, please be nice :slight_smile:

I'm running a freetronics Eleven (uno clone) with the sparkfun uSD shield, and on the development area of the shield have a sparkfun DeadOn RTC (DS3234) and an ADC (ADS8341).

The code i'm using is essentially a cut & paste job of the provided sample code:
RTC: http://www.sparkfun.com/datasheets/BreakoutBoards/DS3234_Example_Code.c
ADC: Arduino Playground - MCP3208
uSD: using the sdfat library, and have minor minor changes to the the "Analog Logger" example code provided

Now, the ADC doesn't use SPI.h and the normal Arduino SPI pins (10-13), but instead uses CS:9, MOSI:2, MISO:3, SCLK:4
uSD shield uses CS:8, MOSI:11, MISO:12, SCLK:13
RTC pins set using std SPI (CS:10, MOSI:11, MISO:12, SCLK:13)

I can get the uSD and ADC to work at the same time (while disabling the RTC), but never all three at once. I'm not sure if this is something to do with the Sparkfun uSD breakout, or not. Also, the RTC only seems to work if I use CS:10, and not other pins. Has anyone had similar problems? I've check my code to ensure the individual devices never have CS low at the same time.

Any suggestions would be greatly appreciated! Thanks in advance!

Ok, so you're not really using the SPI hardware for the ADC. That's fine, it will just be slow as heck.

The uSD resets the SPI mode to what it needs whenever it executes a function, that's probably why it works.

The RTC, on the other hand, has no indication of doing that. Execute the RTC_init() function any time you actually use the chip. Since the ADC is literally bit-banged, it won't care, and the uSD already does it's own on the fly init of the SPI.

Why would this work? Because "SPI" is an interface that has several modes of operation. The RTC requires mode 1 or mode 3 to work. I don't know what the uSD needs, but it's best to just reset the mode when you switch with on-demand devices like this.

Thanks for the reply TeslaFan, much appreciated! I'll give it a try.

I've noticed that almost all example code for interfacing ADCs with SPI is via 'bit-banging' rather than utilising the SPI.h library. Is there a reason for this? Has anyone come across any code that uses the SPI library for an ADC? Speed is likely to be an issue for my project so I might need to implement the fastest possible code. Do know how slow as 'slow as heck' actually is?

This may be the solution to my situation as well.