Problem with redirecting Ethernet Shield pins

Good day,

I am currently working on a project, but have run into an issue.

The problem consists of 2 Arduino Shields, a USB Host Shield and an Ethernet Host Shield.

Both of the shields use the digital port 10 for Salve Select, together with the digital ports 11, 12 and 13.

We are sadly very inexperienced with coding in C++, so as for editing the library “w5100.h” has not resulted in any success.
There have been another user with a similar problem, that tried to change the pins too, so we changed the pins “10, 11, 12 and 13” to the pins “3, 4, 5 and 6”, so they don’t interfere with the USB shield, in the following code, in the file “w5100.h”:

private:
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
  #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
  #if defined(ARDUINO_ARCH_AVR)
    #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); };
    #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); };
//Changed to:
inline static void initSS()    { DDRB  |=  _BV(2); };
      inline static void setSS()     { PORTB &= ~_BV(2); };
      inline static void resetSS()   { PORTB |=  _BV(2); };

    #endif
  #else
    inline static void initSS() {
      *portModeRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
    inline static void setSS()   {
      *portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) &= ~digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
    inline static void resetSS() {
      *portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
  #endif
#else
  #define SPI_ETHERNET_SETTINGS ETHERNET_SHIELD_SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
  // initSS(), setSS(), resetSS() not needed with EXTENDED_CS_PIN_HANDLING
#endif
};

We were also wondering if in the file “w5100.h”, if in the start of the code, where it says:

#define ETHERNET_SHIELD_SPI_CS 10

if we should change it to

#define ETHERNET_SHIELD_SPI_CS 3

Our setup currently consists of a “Go-between Shield”, so we are able to connect the pins that the shield uses easily.

Thanks in advance for any help we can get.

w5100.h (14.8 KB)

The SPI pins, 11, 12, and 13, CAN be shared by multiple devices. You can NOT make the ethernet shield use different pins for SPI.

You MIGHT be able to change the SlaveSelect pin for the Ethernet shield, be changing the value of that #define statement. YOU would be the one to do that and see if it works.

Pin 10 still needs to be an OUTPUT pin, to make the Arduino an SPI master.

PaulS:
The SPI pins, 11, 12, and 13, CAN be shared by multiple devices. You can NOT make the ethernet shield use different pins for SPI.

You MIGHT be able to change the SlaveSelect pin for the Ethernet shield, be changing the value of that #define statement. YOU would be the one to do that and see if it works.

Pin 10 still needs to be an OUTPUT pin, to make the Arduino an SPI master.

Thank you for clarifying that.

I will be trying to see if they work with each other when changing the #define statement.

The different parts of the system work fine, but does not work together, so I hope that this solves it.

Will post the results.

At one time I changed the slave select pin on my Ethernet shield. The code i used no longer works due to the number of variants of the Arduino. This is the section of code you must change. Leave the other SPI pins where they are. You must determine which Arduino you are using to tell which of these to change. You might find it easier to change the W5100 slave select from D10 to D9.

private:
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
  #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
  #if defined(ARDUINO_ARCH_AVR)
    #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); };
    #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); };
//Changed to:
inline static void initSS()    { DDRB  |=  _BV(2); };
      inline static void setSS()     { PORTB &= ~_BV(2); };
      inline static void resetSS()   { PORTB |=  _BV(2); };

    #endif
  #else
    inline static void initSS() {
      *portModeRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
    inline static void setSS()   {
      *portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) &= ~digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
    inline static void resetSS() {
      *portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
    }
  #endif
#else
  #define SPI_ETHERNET_SETTINGS ETHERNET_SHIELD_SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
  // initSS(), setSS(), resetSS() not needed with EXTENDED_CS_PIN_HANDLING
#endif
};

If I do this will I have to change any hardware?