Trouble with Multiple SPI devices (SD card & CC3000 Shield)

Hello all -

It’s my first time posting on this forum so bare with me. This is my current hardware setup:

Arduino Uno
Sparkfun’s CC3000 Wifi Breakout
Cheap SD card breakout from ebay

Both devices are driven using SPI and are wired correctly. When running an the CardInfo sketch with just the SD card on the bus, the information is read perfectly. When running the CC3000 example code (Webclient) with just cc3000 on the bus, the information is transmitted perfectly. As soon as a plug the CC3000 and the SD card to the SPI bus with chip selects 4 and 6 respectively, I am not able to run the CardInfo sketch. I get an “SD card initialization failed!” error.

What’s even weirder…is that the setup() function keeps repeating. Here is the example output:

Initializing SD card…initialization failed. Things to check:

  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?
    initialization failed. Things to check:
  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?
    initialization failed. Things to check:
  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?
    initialization failed. Things to check:
  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?

And here is the output when just the SD card is plugged in:

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3632267264
Volume size (Kbytes): 3547136
Volume size (Mbytes): 3464

Files found on the card (name, date and size in bytes):
SYSTEM~1/ 2014-10-13 17:49:58
INDEXE~1 2014-10-13 17:49:58 76


I’ve tried several things including:

  1. Setting the chipselects of both devices to OUTPUTS and HIGH at the beginning of the sketch
  2. Adding pull-up resistors to each chip select

Does anyone know what could be happening here? My next assumption is an overcurrent condition that triggers a reset when both devices are plugged in. NOTE: both devices are receiving power from the same 5V output from the Uno, which is powered through USB.

Any help would be appreciated!

There are various hardware setting for SPI: data rate, clock edge, bit order... Each library has to re-set those parameters each time they want to access the hardware or they have to all use the same parameters. Many just set them in .begin() and assume they stay set forever. Fortunately you have the library source code so you can examine the code and fix it as needed.

Thanks for your reply! However, I am only running one at a time therefore the SPI settings wouldnt change in between.

Here is a breakdown of what I'm doing:

  1. Plug in SD card and run CardInfo sketch example. Everything runs smoothly.
  2. Unplug SD card. Plug in CC3000 Breakout board. Run Webclient sketch. Everything runs smoothly.
  3. Re-plug in SD card shield so that both SD card shield and Wifi breakout are on the SPI bus.
  4. Try to run CardInfo sketch (same as part 1 - nothing to do with Wifi) - sketch fails and/or keeps repeating.

I've pressed the reset switch as well and sometimes it will output something different on the Serial window for example the initialization will pass but the volume definitions cannot be fetched etc.

Sounds like a hardware problem. One of the devices (probably the CC3000) is not properly getting off the SPI bus when its SlaveSelect (CS) pin is HIGH.

Any known ways to combat this issue given the hardware problem? And I think the SD card might be the culprit because it shows the same behavior with the ethernet shield, which is why I purchased a separate SD shield. But I'm not sure how to move forward from here...

Bump

Still stuck...Tried unplugging the CS, EN and IRQ pins for the CC3000 breakout and still did not allow the SD card to work correctly. The only way that the SD card works is by unplugging the CC3000 entirely.

Any ideas?

It appears the CC3000 uses interrupts, and uses the SPI bus in an interrupt. This will cause problems with the CC3000 and the SD card. If the SD card is using the SPI bus (SD slave select LOW) and the CC3000 triggers an interrupt, that causes problems for both devices.

IDE v1.5.8 BETA is supposed to be able to allow both devices to work together, but I have not tested it yet. The Adafruit library apparently has the mods for IDE v1.5.8 included.

Thanks for your reply.

I see what you mean, and that was my assumption also when I unplugged the IRQ wire from the Arduino entirely. The IRQ wire that goes from the CC3000 is the interrupt wire; with that unplugged, how would it still alter the SD card operation?

:~

That depends on how you have the CC3000 CS (Slave Select) pin set. If you do not set the CC3000 SS as OUTPUT and HIGH, it will garbage up the SPI bus during the SD card init.

I am not only setting the CS of the Wifi to OUTPUT and HIGH in software, but also added an external pull up resistor to the CS pin on the CC3000 to no avail.

Since I do not have access to a scope to see exactly what is corrupting the bus, I removed one wire at a time from the CC3000, and found that nothing worked except removing the power entirely. Really not sure where to go from here...

Hello, I thought I left a reply here awhile ago but apparently I hadn't.

This is a bit of an IF subject but AVR docs clearly state that hardware ports can all act as full speed master-mode-only SPI ports.

The 1284P has two and the Mega2560 has four. But I don't know of any library to use those as SPI.

There is also software SPI at not so great a speed as hardware SPI and quite a CPU load.

You can run dedicated SPI. Think about that.