Pages: [1]   Go Down
Author Topic: Connecting 2 SPI shields on an arduino Mega2560  (Read 1153 times)
0 Members and 1 Guest are viewing this topic.
Chania-Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

forgive me if this the wrong category but I got a bit lost in the forum.

I have 2 shields working under SPI protocol. 1) ENC28J60 ethernet shield, 2) sparkfun micro-SD shield.

I believe I managed to connect them individually on a Mega2560 by bending pins 10-13 on both shields and connecting them to pins 53,51,52,50.

What I need now is to stack on find another way to use them combined. I assume that something I should do with the SS (CS) pin, but since I am quit new at these stuff, need some help

Any kind of help is accepted. If I need to upload anything to help you suggest me please tell me to do so

Thank you
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11649
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Each slave device needs a separate CS pin.  There is nothing special about the SPI SS pin on the Arduino (except that you should configure it as an output when using hardware SPI - any pin can be used as a chip select with SPI, only the SCK/MISO/MOSI pins should be commoned.

Beware devices which are "sort of SPI" but disobey some of the protocol.  MISO must only be driven when the chip is selected, MOSI must be ignored except when chip is selected and clock is pulsed.  Thinks get a little complex if you need to drive different devices at different clock speeds or want to use SPI transfers in an interrupt routine...
Logged

[ I won't respond to messages, use the forum please ]

Chania-Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Beware devices which are "sort of SPI" but disobey some of the protocol.  MISO must only be driven when the chip is selected, MOSI must be ignored except when chip is selected and clock is pulsed.  Thinks get a little complex if you need to drive different devices at different clock speeds or want to use SPI transfers in an interrupt routine...

High again and thanks for answering. Back with new data:

1) I have changed the default SS pin from 53 to 48 and 49 respectively for the 2 SPI shields through the libraries

My connections are the following:

Ground: Arduino Mega2560,
Level 1: Arduino Ethernet Shield V1.1
Top lvl : Micro Sd shield from Sparkfun

Pins 10-13 of the Ethernet shield are not connected to the Arduino Mega (solder and pins have been removed), so pins 10-13 of the shield are in contact with pins 10-13 of the sd card and they are wired with pins 49,51,50,52 on the mega

Pin 8 from the sd shield is bended and is not in contact with the Ethernet shield. It is connected with wires to pin 48 in the mega. Pins 10-13 are sent to mega as previously mentioned.

2) I have uploaded the EthershieldDNSTest code and the Ethernet shield works great (with the SD shield above)

3) I have uploaded the QuickStart code from the SdFat library and the SD does not initialize when the Ethernet shield is under it. Without the Ethernet shield the SD card works perfectly

In both codes I add in the setup that pin 53 is an output and that it is set as High

You mentioned something about "sort of SPI" devices. Is one of these?

Do you have any idea about what might be going wrong?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 138
Posts: 5843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The ethernet library has some quirks. If you read or write to the ethernet shield before accessing the SD card, no problem. If you try to access the SD card first without disabling the ethernet SPI, that will fail.

I don't know if that is your problem, but I thought I would mention that. It caused me some problems at first.
Code:
void setup()
{
   SD.begin(8);
   // The SD.begin() returns with its SPI disabled
   // Good little monkey!

   Ethernet.begin(mac,ip);
   // The Ethernet.begin() function returns with the ethernet shield SPI enabled.
   // Bad little monkey! So we fix that.
   digitalWrite(10,HIGH);
   // now you should be able to read/write to both without the need to manipulate the SS pins
}

BTW, I would leave digital pins 8 and 10 connected through both shields. Only digital pins 11-13 should be jumpered to the mega SPI data lines (not the SS pins. leave those alone). That will cause the least problems.
« Last Edit: February 10, 2012, 12:10:57 pm by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I'm also a newbie when it comes to micro-controllers and the Arduino.  Since my question is similar, I figured I'd post it here rather than start a new topic.  In short, I'd like to control several identical SPI devices to my Mega 2560 R3.  Here is a link to the device: http://www.macomtech.com/datasheets/MAPS-010166.pdf.  I'm a bit confused with the procedure for using other pins as ss on the 2560.  Many folks state that pin 10 (ss) must be set as an output and high before using any other pins as ss.  On the 2560, however, the ss pin is 53.  Does this mean I need to set 53 to high, instead of pin 10?

Thank you for any guidance on this matter!
Logged

Pages: [1]   Go Up
Jump to: