How to configure Pi Pico as SPI Slave?

All of the examples that I’ve seen are examples of setting up the Pi Pico as an SPI Master. In the application that I’m working on I need the pico to be configured as a slave. Can anyone provide me with an example that will enable the same functionality as would be achieved with this:

Thanks in advance!

Did you check this out? pico-examples/spi/spi_master_slave/spi_slave/spi_slave.c at master · raspberrypi/pico-examples · GitHub

I’m looking at it now. It looks like to use this I would need to grab a bunch of files from the pico sdk github to make everything work.

The standard Wire library in ArduinoCore-mbed is I2C slave capable and the RP2040 has it implemented. No need to go to the Mbed-os abstraction level.

Essentially this is a duplicate of

You should be able to implement an I2C slave with the begin(SLAVE_ADDRESS) / onReceive / onRequest callback functions just fine, just as described in official tutorials like

I2C won’t work for me because I’m connecting boards via several feet of ethernet cable and I2C doesn’t work well much past 50cm. Based on what I’ve read SPI is good to a couple of meters which is why I’m trying to use it.

…emberrasing, I’ve misread SPI as I2C.

ArduinoCore-mbed per the patches did not seem to be adding DEVICE_SPISLAVE capabilities to the RP2040 implementations, only STM32 has it.

However, Arduino-Pico by Earlephilhower, an alternative (I would even say, better) implementation of the Arduino core does have a SPISlave library with an example and documentation.

You can use it in PlatformIO too if you install this third-party platform as documented.

If you want it in ArduinoCore-mbed, you need to file an issue there, or add to the SPI slave impelementation to the patch files, recompile the whole of mbed-os etc. (a pain).

That seem a bit paradoxical because higher-frequency signals (usually SPI, multiple MHz) should degrade more over longer distances than lower-frequency signals (usally I2C, 400kHz standard).

And just to have mentioned it, there are “I2C to differential I2C” converters, which give the I2C signal a much, much longer distance.

Also, RS485 (again, differential), or Ethernet would come in question for longer distances. Some boards like “WIZNET W5500 EVB Pico” even come with on-board ethernet chips, directly integrated.

This seems promising. I’ll check it out and post some sample code when I have a chance