Multiple SPI


I'm trying to control an ADXL accelerometer with an arduino but I have some problems due to my ethernet shield. In fact as I read, the SD slot of the ethernet shield is controlled by SPI and that id why I can not use it for an other purpose... Of couse the proble is a software problem (I already tried to bypas the pin 4 of the ethernet shield without any difference).

In the project I have to include
-> Ethernet.h
-> Spi.h (because ethernet needs it)
-> Wire.h (because of my accelerometer)

Does someone have an idea on what I can do to solve this problem?

Thanks in advance

Those devices should work together. Post your code.

Which ADXL are you using? How are you wiring it up? The first one I looked at can be I2C or SPI - which are you using?

SPI is a shared bus, so you can have multiple devices connected to it - what is the problem you are having doing that?

If the accelerometer needs Wire.h, then it needs I2C, not SPI.

There is no problem with using both I2C and SPI.

After some experimentation your are right.

In fact I have 2 shields on my arduino:

  • MP3 Shield
  • Ethernet Shield
  • And the ADXL

The problem occures when I use the SD card on the MP3 shield and this is because the SD is commanded by SPI. If I swith to usb the problem disapear.
Nevertheless, from my point of view this is strange as even if we have multiple SPI it should works together because we send the device adress in the beginning of the communication. It might come from the way SPI is used by the code from the MP3 library..

SPI doesn't use device addresses. It uses a separate physical "chip select" wire, controlled by the master device ( the arduino ), to control which of the spi slave devices it is communicating with.

I suggest you do some more research on how spi and/or i2c actually work, before waffling aimlessly.

In fact I have 2 shields on my arduino:

  • MP3 Shield
  • Ethernet Shield
  • And the ADXL

And you apparently have several SPI devices (2 SD card slots?). When you are attempting to use the SD card, are you disabling the other SPI devices, like the w5100 on the ethernet shield and the MP3 player on the MP3 shield? That causes problems.

I will suggest again that you post your code, and also a link to the shields. The MP3 shield has two SPI slave selects (MP3 player and SD), and the ethernet shield has two (w5100 and SD).

Is the ADXL an I2C interface or SPI?


As you understood SurferTim the problem came from the multiple spi affeccted to the sd card on the mp3 shield and the ethernet shield. After some modifications in the source code now it perfectly works.

I will not post the code which is long and a bit unclear…
I have enclosed some pictures of the full device that enable you to understand the full project.
It is a remotedly controled preventive alarm based on door sensors (Adxl and Bump sensor of my own).

I thank all people that have helped me in this forum.