Pages: [1]   Go Down
Author Topic: Switch Slave Select pin with Ethernet shield  (Read 2533 times)
0 Members and 1 Guest are viewing this topic.
New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to see if I can use a slave select pin other then pin 10 to control an Ethernet Shield (R3).  My end goal is to take an Ethernet shield and connect it to a panStamp (this is like an Arduino Pro Mini 3.3v Atmega328 with RF chip).  The panStamp uses SPI to communicate with the RF chip and it's hard wired to use pin 10 for SS. 

As a test just to see if I could get an Ethernet shield to work using a different SS pin, I took a Duemilanove and connected it to a Arduino Ethernet shield R3.  I didn't plug the shield into the headers, I just used wires to connect the two.  I had pin 10 on each connected, then pins 11-13 on the Duemilanove wired to the SPI connector on the shield. Plus 5v and Gnd.  This setup worked fine and I could use the Ethernet shield to upload to cosm.com.

I did some research on changing the SPI pin and found this forum post which was pretty informative.  Basically he says to change modify 5100.h file.  So I changed
Code:
inline static void initSS()    { DDRB  |=  _BV(2); }; 
inline static void setSS()     { PORTB &= ~_BV(2); };
inline static void resetSS()   { PORTB |=  _BV(2); };
to
Code:
inline static void initSS()    { DDRB  |=  _BV(0); }; 
inline static void setSS()     { PORTB &= ~_BV(0); };
inline static void resetSS()   { PORTB |=  _BV(0); };

This should change to SPI from pin 10 to pin 8.

For my test I connected pin 8 on the Duemilanove to pin 10 on the Ethernet shield.  But I couldn't get the Ethernet shield to work with this setup.  I also tried to set pin 8 low in my sketch with digitalWrite() before I made an Ethernet call, but that didn't help.  Is it even possible to use a pin other then 10?  If so, are their certain pins that will work and others that won't?  I'd appreciate any suggestions in getting this to work.

 
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8084
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For my test I connected pin 8 on the Duemilanove to pin 10 on the Ethernet shield. 

Did you connect all the other data pins?  Power?  Ground?  Check the Ethernet Shield schematics to see which Arduino pins it connects to.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Piemonte, Italia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
Just a brick in the wall
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right today I have been testing a way to connect ad Ethernet Shield to an Arduino clone that has a different form factor (Luigino 1000pads, BTW). This involved doing something like you did (i.e. connect the shield through wires) so I took the opportunity to test what you ask: I changed 5100.h like you did, then compiled the webserver example, which successfully worked. My connections are the following:

Using female headers:
Code:
L (Luigino) D8 -> ES (Ethernet Shield) D10
L +5V -> ES 5V
L GND -> ES GND

Luigino female headers to ES ICSP/SPI connector:
Code:
L11 -> 4
L12 -> 1
L13 -> 3
(This is wrt the SPI pinout as described at http://www.bitwizard.nl/wiki/index.php/SPI_connector_pinout)

Note that my ES is not the official one, but rather a clone, so YMMV. Maybe you might try connecting the SS signal to pin 5 of the SPI header.

Hope it helps!
« Last Edit: August 13, 2012, 02:28:18 am by SukkoPera » Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you connect all the other data pins?  Power?  Ground?  Check the Ethernet Shield schematics to see which Arduino pins it connects to.

I didn't connect the other data pins, I did have power and ground connected.  As I said, this setup worked when pin 10 on the Arduino was connected to pin 10 on the Ethernet shield.  So I see no reason to hook up other pins. All I did was change 5100.h and recompiled and uploaded to the Arduino.  Physically, I moved the wire from pin 10 to pin 8 on the Arduino.
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you might try connecting the SS signal to pin 5 of the SPI header.

Looking at the Ethernet shield schematic pin 5 on the SPI header is reset.  There is no SS pin on the header, it's connected to Digital pin 10 (ie pin 3 on J1 header).
Logged

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

Did you set the default SS pin (digital pin 10) to OUTPUT and HIGH? Even tho you are using digital pin 8 for the w5100 SS, you must set the default SS to OUTPUT, or the SPI will not be in master mode. Normally, Ethernet.begin() does that, but it will now set digital pin 8 instead.

Just a thought...
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you set the default SS pin (digital pin 10) to OUTPUT and HIGH? Even tho you are using digital pin 8 for the w5100 SS, you must set the default SS to OUTPUT, or the SPI will not be in master mode. Normally, Ethernet.begin() does that, but it will now set digital pin 8 instead.

Yes, I tried that, it didn't help.
Logged

Piemonte, Italia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
Just a brick in the wall
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Another alternative could be using a shield based on the ENC28J60 chip. You will have to use EtherCard instead of the official Ethernet library, which has quite a different interface, but it will allow you to pass the SS pin to the begin() method.
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another alternative could be using a shield based on the ENC28J60 chip. You will have to use EtherCard instead of the official Ethernet library, which has quite a different interface, but it will allow you to pass the SS pin to the begin() method.

I want to stick with the Arduino shields since I have several of them.  Plus a different chip would be different libraries and a lot more to learn.  I experienced some of this when I purchased some nanodes - these are Arduino based boards with Ethernet built in.  It used the ethercard.h library and ended up being very time consuming for me to get working.  Also, some other libraries I want to use, like twitter.h assume I'm using Arduino's ethernet.h library. 
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried my setup again, and now it's working.  I tried it with SS on pin 9 and pin 8 and it worked on both.  Also, at the beginning of setup() I set pin 10 as an OUTPUT and to HIGH.  Which I had done before.

Now I have another problem I'm trying to solve.  To get this SS pin change working, I made a change to 5100.h, but I'd like to use an #if defined to control when I change the SS pin to something else. but I can't get 5100.h to see my defined name.  At the top of my sketch I defined _CC1101_H.  But 5100.h doesn't see "#if defined (_CC1101_H)" as true. Here's what I have in 5100.h; I'm trying to get the first section to execute.

Code:
#if defined (_CC1101_H)
// Set digital pin 8 (Port B, Pin 0) as Slave Select for Ethernet shield
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega32U4__)   
  inline static void initSS()    { DDRB  |=  _BV(6); };
  inline static void setSS()     { PORTB &= ~_BV(6); };
  inline static void resetSS()   { PORTB |=  _BV(6); };
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#else       
  inline static void initSS()    { DDRB  |=  _BV(2); }; 
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's so because the IDE is restructuring your sketch before sending the generated source file to the compiler. It works if you use it in another tab (a separate source file, these are sent to the compiler as-is).
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's so because the IDE is restructuring your sketch before sending the generated source file to the compiler. It works if you use it in another tab (a separate source file, these are sent to the compiler as-is).

That explains why it's not working.  I just tried your suggestion and it didn't work.  I created another tab called EthernetTest.h and put my #define in there.  But w5100.h still doesn't recognize it.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But w5100.h still doesn't recognize it.
Does w5100.h include EthernetTest.h? #defined values don't magically become visible to other compilation units.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But w5100.h still doesn't recognize it.

You have to remove the

Code:
#include "Ethernet.h"

from your main sketch, move it to the EthernetTest.h and put your #define before the #include statements. This way it works for me but I'm not happy with it.

Remember: this means you have to move your whole Ethernet related code to the EthernetTest.cpp because the main sketch doesn't know about anything "Ethernet".
Logged

Pages: [1]   Go Up
Jump to: