Raspberry pi PICO ethernet library change SPI pins

Hello i am trying to use the arduino ethernet library specifically the webclient example with my raspberry pi pico

I have already solved the compiling error exactly as discussed in this thread

But serial monitor is throwin me this error

Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
Ethernet shield was not found.  Sorry, can't run without hardware. :(

Since the shield was not found i suspect that that its looking at a different channel, i have connected the the w5500 to the SPI0 of the pico (GPIO 0,1,2,3)

What is the default pins the webclient example is lookinng for? and how do i change it to GPIO 0,1,2,3? I do not want to changeg pins if possible because the location is very convinient.

You can try the WebClient example of my EthernetWebServer Library

Check defines.h of WebClient

#elif ETHERNET_USE_RPIPICO
  
  // Default pin 5 (in Mbed) or 17 to SS/CS
  #if defined(ARDUINO_ARCH_MBED)
    // For RPI Pico using Arduino Mbed RP2040 core
    // SCK: GPIO2,  MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
    
    #define USE_THIS_SS_PIN       5

    #if defined(BOARD_NAME)
      #undef BOARD_NAME
    #endif

    #if defined(ARDUINO_RASPBERRY_PI_PICO) 
      #define BOARD_TYPE      "MBED RASPBERRY_PI_PICO"
    #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
      #define BOARD_TYPE      "MBED DAFRUIT_FEATHER_RP2040"
    #elif defined(ARDUINO_GENERIC_RP2040)
      #define BOARD_TYPE      "MBED GENERIC_RP2040"
    #else
      #define BOARD_TYPE      "MBED Unknown RP2040"
    #endif
    
  #else
    // For RPI Pico using E. Philhower RP2040 core
  // SCK: GPIO18,  MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
    #define USE_THIS_SS_PIN       17

  #endif
    
  #define SS_PIN_DEFAULT        USE_THIS_SS_PIN

  // For RPI Pico
  #warning Use RPI-Pico RP2040 architecture

and you can know how to connect W5500 to RP2040

  1. Using mbed_rp2040 core
// SCK: GPIO2,  MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
  1. Using arduino-pico core
// SCK: GPIO18,  MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17

Also it's better to apply Ethernet Libraries' Patches if you have compile error or issue

Good Luck,

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Cool, its you ! I have been really interested in your libraries.

but is there a way to change it to GPIO 0,1,2,3 (SPI0)? i have already made the pcb and it seems to be waste to create a new one just to change the SPI pins? how do i do that? i will make that change in the next revision

Normally you can change many things, such as pin assignment / configuration, etc, if you design a new board as variant, but you must have the variants added to the core later so that anybody can easily use.

Doing that by changing the files in variants directory, for example for RASPBERRY_PI_PICO using mbed_rp2040 core, the variant files are in RASPBERRY_PI_PICO directory

but is there a way to change it to GPIO 0,1,2,3 (SPI0)?

// SPI
#define PIN_SPI_MISO  (4u)
#define PIN_SPI_MOSI  (3u)
#define PIN_SPI_SCK   (2u)
#define PIN_SPI_SS    (5u)

static const uint8_t SS   = PIN_SPI_SS;   // SPI Slave SS not used. Set here only for reference.
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK  = PIN_SPI_SCK;

But it always better to use the same pin configuration, unless you have good reason to change (and hassles to follow)

I kinda made the board ahead thinking it was very easy to change.

Anyway how to change the SPI speed ?

The SPI clock settings is Ethernetx library dependent, you can change in the library or modify it to permit setting it inside your sketch.

For example, for modified Ethernet library w5100.h#L61-L77

#if !USE_W5100

// Safe for W5200 and W5500, but also tested OK on W5100
// Use 14MHz if you know your W5100 can't run
// Higher SPI clock results in faster transfer to hosts on a LAN
// or with very low packet latency.  With ordinary internet latency,
// the TCP window size & packet loss determine your overall speed.
#warning Use 25MHz clock for W5200/W5500. Not for W5100
#define SPI_ETHERNET_SETTINGS SPISettings(25000000, MSBFIRST, SPI_MODE0)

#else

// Safe for all chips but too slow
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)
#warning Use 14MHz clock for W5100/W5200/W5500. Slow.

#endif

where SPISettings is defined in HardwareSPI.h#L37-L100

class SPISettings {
  public:
  SPISettings(uint32_t clock, BitOrder bitOrder, SPIMode dataMode) {
    if (__builtin_constant_p(clock)) {
      init_AlwaysInline(clock, bitOrder, dataMode);
    } else {
      init_MightInline(clock, bitOrder, dataMode);
    }
  }

  SPISettings(uint32_t clock, BitOrder bitOrder, int dataMode) {
    if (__builtin_constant_p(clock)) {
      init_AlwaysInline(clock, bitOrder, (SPIMode)dataMode);
    } else {
      init_MightInline(clock, bitOrder, (SPIMode)dataMode);
    }
  }

  // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first.
  SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); }

  ...

  friend class HardwareSPI;
};

It's always better before designing a completely new hardware, do some basic research on the current implementation to have knowledge, make / test on some prototype and avoid costly mistake.

Anyway I guess it's so far so good for you now

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.