1

Hello i have a custom board of the RP2040 and would like to use the ethernet library. But the ethernet example webClient uses the default SPI pins of whatever board it is being used, but what if im going to use a board (such as the RP20400 with multiple SPI channels or have alternate pins for the spi chanels, How do i set the SPI mosi,miso,cs of the SPI in the ethernet library?

So i have found a way to make it work, i Edited the file under

\AppData\Local\Arduino15\packages\arduino\hardware\mbed_rp2040\2.4.1\variants\RASPBERRY_PI_PICO\pins_arduino.h

change the number to the pin you like.

// SPI
#define PIN_SPI_MISO  (0u)
#define PIN_SPI_MOSI  (3u)
#define PIN_SPI_SCK   (2u)
#define PIN_SPI_SS    (1u)

But problem with this now is every RP2040 board will now make it their default SPI pins,

Is there anything i can do to keep the modification to my own sketch only?

DrakeJest
  • 201
  • 1
  • 7
  • the Arduino Ethernet library uses the SPI object from the SPI library – Juraj Oct 19 '21 at 17:36
  • @Juraj I could not find any SPI macros or declerations on ethernet.h which makes it tricky to trace – DrakeJest Oct 19 '21 at 18:07
  • https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/SPI/SPI.cpp#L117 – Juraj Oct 19 '21 at 18:37
  • @Juraj Oh ! so its initialized at the inside the SPI.h and not ethernet.h. So as mentioned in my edit changing pin.arduino.h changes the setting for all the boards, in my sketch can i override that decleration. So maybe redeclare it after the SPI.h include, something like `#include ; arduino::MbedSPI SPI(0, 3, 2); #include `. I will try this out right away – DrakeJest Oct 19 '21 at 18:49
  • https://arduino.stackexchange.com/questions/54484/adding-a-custom-board-to-the-arduino-ide/60660#60660 – Juraj Oct 19 '21 at 18:52
  • It would be a hasle if another PC will be used as i have to port the new variant every single time. For now im looking for ways to override that decleration, with my own. I think its easier that way plus, it makes the sketch portable as everything is done on the sketch – DrakeJest Oct 19 '21 at 19:02
  • you can't do it in the sketch. the library files are compiled without knowing about the sketch. you can put the variant files on github as I do – Juraj Oct 19 '21 at 19:07
  • @Juraj yes, thats why the redifinition must happen at compile time not at runtime, via a macro or some other means (not sure if C/C++ allows it, still looking for ways) – DrakeJest Oct 19 '21 at 19:12
  • it is not possible. custom variant files or changing the library are your only options to change what pins will the SPI library use – Juraj Oct 19 '21 at 19:14
  • @Juraj you are right the definition was not in the .h but the .cpp so that mean there is no way to access it in my sketch. a bit off topic quesiton, why do i not see what frequency the spi is set at? which file was the spi frequency set at? – DrakeJest Oct 19 '21 at 22:07
  • the frequency is set for SPI transaction in the Ethernet library. https://github.com/arduino-libraries/Ethernet/blob/7c32bbe146bbe762093e4f021c3b12d7bf8d1629/src/utility/w5100.h#L21 – Juraj Oct 20 '21 at 05:16
  • Nice its using the default 14MHz , im using the w5500 and can go to 30Mhz – DrakeJest Oct 21 '21 at 08:34
  • @Juraj there is way !! but sadly i cannot post it because question has been closed, we can reassign the pin as mentioned here https://github.com/arduino/ArduinoCore-mbed/issues/339. For i2c `MbedI2C myWire(6, 7);` for SPI `MbedSPI mySPI(4, 3, 2);` and for uart `UART mySerial(0, 1);` – DrakeJest Oct 28 '21 at 20:08
  • and how do you tell the Ethernet library to use mySPI? – Juraj Oct 29 '21 at 04:44

0 Answers0