Changing SS Pin for Ethernet library

Hello,

I’m using an Arduino Ethernet Shield with a Mega board.

In order to get Ethernet running, I’ve mapped these pins:

53 → 10
51 → 11
50 → 12
52 → 13

Only these pins are mapped for the Ethernet board functionality. My Ethernet-Shield is not attached directly, because there is an additional board between the Mega and Ethernet Shield that does this mapping. So the mapping between these pins is hardfixed.

And here comes the problem: In the libraries\Ethernet\utility\w5100.h , I’ve found the hard-coded SS-PIN here:

#if 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); };
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif

According to pins_arduino.c, PB4 is Pin 10 - so it doesn’t cause any trouble if you attach the Shield directly on the board, because you have then a direct Pin 10 <-> Pin 10. But in my case I need to specifically use Pin 53 as SS-Pin. Leaving the default definitions and using an additional wire to map Pin 10 → Pin 10, the Ethernet Shield works.

Now I’d like to use Pin 53 for SS, so I have changed the code in w5100.h:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  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

And PB0 is Pin53 according to pins_arduino.c

But somehow, this doesn’t work on Pin53 as SS.
I’ve also tried to use many different custom pins, and if I change the definition here and connect the specified pin to the shield, it works.

SS as Pin53 is not functional in any way.

Is there any trick to use Pin53 as SS? Is there any advantage/disadvantage over using a special pin or can I use any? (problem is that I already have my platine that has the pin 53 mapped)

The only requirement is pin 53 needs to be set as an OUTPUT. You should not need to map anything if you are using pins 50-53. They are already the default SPI pins on the Mega without that.

The ethernet shield does not use pins 11-13 with a Mega. Only pin 10 as the SS pin. The rest are connected through the ICSP connector in the center of the Mega.

But I explicitly want Pin 53 as SS, and not Pin 10. The mapping 10 -> 53 is there and I cannot ( don't want) to change that.

Then you did good changing the w5100.h code. That should use pin 53 as the SS pin. The rest of the SPI pins are hardwired. Pins 11-13 on a Uno, and pins 50-52 on a Mega.

How are you "mapping" the other pins?

Edit: I would connect the pins to the ethernet shield (all but the SS pin) to the ICSP connector on the shield, not pins 11-13. They are not connected to anything.

It’s soldered on an extra board, which is like a sandwich between the Ethernet Shield and the Mega. (there are more components on that extra board, but these don’t matter here)

I can do additionaly manually mapping with normal wires, but I don’t want that.

My change in w5100.h was obviously not enough.

It isn't enough. You must connect the rest of the pins to the correct pins on the Mega. Do not connect the Mega pins 50-52 to pins 11-13 on the shield. They must be connected to the appropriate pins on the ethernet shield ICSP connector!

What do you mean by "the rest of the pins" ? Off course I've also connected the Reset, Ground, Power supply lines, etc.

And why do I have to use the ICSP Header? I was already sucessfull with my pin connections - but not with Pin 53 as SS.

And if I plug the Ethernet shield directly on the Mega / Uno board (doesn't matter which), the ICSP header is also open end.

As I said, I already connected pins 50-52 to pins 11-13 - like suggested in this older post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284605439#5

I don't see why this is wrong?

What does this mean?

And if I plug the Ethernet shield directly on the Mega / Uno board (doesn't matter which), the ICSP header is also open end.

AFAIK, the ethernet shield does not get SPI through pins 11-13. On both the Uno and Mega, the SPI data pins are on the ICSP connector.

I will check the schematic of the ethernet shield tho, just to make sure.

I think they are connected to both, according to Uno / Mega Schematic.

But however, as I already said: The shield works with pin 10 as SS. (using PB4 in w5100.h) But not with pin 53 as SS (using PB0 in w5100.h)

I can also use PD7 (just a random pin), which is Pin 38 on the Mega. All but 53.

Yes, they are connected to both the ICSP and pins 50-52 on the Mega, and pins 11-13 on the Uno.

Ah, but the ethernet shield is a whole different story. There are no connections for SPI on anything but the ICSP connector. Here is a link to the schematic. If you feel it is in error, you should report it to the Arduino crew. http://arduino.cc/en/uploads/Main/arduino-ethernet-shield-06-schematic.pdf

I must say that I'm not using the original Arduino Ethernet Shield, so it is a modified one (I don't know the details, just that it's compatible or "improved"). But for me it's safe to assume that my handling with the MOSI, MISO and SCK line is fine.

I'm only stuck with the SS Pin53 issue.

If your assumption is correct, then this should work.

pinMode(53,OUTPUT);
digitalWrite(53,LOW);

Now the shield SPI interface is active until you

digitalWrite(53,HIGH);

Does it?

No, and I also changed the definitions already mentioned in w5100.h

With Pin 8 (PH5) for example, it works.

Do you detect a pin state change on pin 53 when you try that? Is it going LOW? Can you toggle it as a test to see if it is changing?

Can you do the same with pin 49 as pin 8? Would that do for an SS pin?

Otherwise, I have nothing left to add. Maybe someone else will see something I didn't.

I just tried with an older Mega board here. It is an Mega1280.

Using the same program and the same wiring, my Ethernet Shield works on Pin53 as SS.

While the Mega2560 does not. Is there a hardware change that could cause this?