RP2040 SPI-0 four sets of pins named SPI-0 which one is the default? How to change it?

Hi Everybody,

in my current project I want to use a RaspBerry Pi pico RP2040 to communicate with another RP2040 over CAN-BUS using the CAN-BUS-modul with the MCP2515-Chip.

So I looked up the RP2040-Pinout. I found one at adafruit


which show four sets of IO-pins for serial peripheral interface 0

So what does this mean?
Are the pins used for SPI configurable?
If yes what are the default SPI-pins and how can the default-configuration be changed?

best regards Stefan

Yes, it's common practice for processors to have several functions multiplexed on each physical pin.

I've never used that processor. But I can think of three places to look:

  • Examples from the SPI library for the RP2040 Arduino Core.
  • The source code for SPI library for the RP2040 Arduino Core.
  • The processor's datasheet.

Just looking at the prototype for the constructor in SPI.h:

class MbedSPI : public SPIClass
{
public:
    MbedSPI(int miso, int mosi, int sck);
    MbedSPI(PinName miso, PinName mosi, PinName sck);

And here's you see the instances declared:

#if SPI_HOWMANY > 0
extern arduino::MbedSPI SPI;
#endif
#if SPI_HOWMANY > 1
#ifdef SPI1
#undef SPI1
#endif
extern arduino::MbedSPI SPI1;
#endif

first I thought OMG diggin' down all the rabbit-hole of analysing the corefiles.
Did nobody ever before wrote a demo-code?

Sure when arduino-IDE ( I am using the old version 1.8.19) is adjusted to RaspBerry Pi Pico the examples show

File - examples - examples from custom libraries - ACAN2515 - LoopBasicDemoRaspBerryPiPico

And indeed there is a comment

// The Pico has two SPI peripherals, SPI and SPI1. Either (or both) can be used.
// The are no default pin assignments so they must be set explicitly.
// Testing was done with Earle Philhower's arduino-pico core:
// https://github.com/earlephilhower/arduino-pico

though this comment tells not everything that is important:
from this comment I concluded that almost any pin be used and choosed them
"randomly" This resulted in the pico AND Arduino-IDE beeing locked up!

I had to use the task-manager to kill all IDE-processes to make the IDE work again.

So I expanded the comment to explicitly say what is important

// The Pico has two SPI peripherals, SPI-0 and SPI-1. Either (or both) can be used.
// The are no default pin assignments so they must be set explicitly.

// According to the RP2040 data sheet, section 1.4.3 ”GPIO Functions” page 13, 
// you have the following choices for SPI pins:
// SPI-0_SCK            IO-Pins: 2, 6, 18, 22
// SPI-0_MOSI (SPI0 TX) IO-Pins: 3, 7, 19, 23
// SPI-0_MISO (SPI0 RX) IO-Pins: 0, 4, 16, 20
// SPI-0 CS             IO-Pins: 1, 5, 17, 21
  
// SPI-1_SCK            IO-Pins: 10, 14, 26
// SPI-1_MOSI (SPI1 TX) IO-Pins: 11, 15, 27
// SPI-1_MISO (SPI1 RX) IO-Pins:  8, 12, 24, 28
// SPI-1_CS             IO-Pins:  9, 13, 25, 29

I found this better and more detailed information in the doc-file of the
ACAN2515.h-library-sub-folder
C:......\libraries\ACAN2515\extras named acan2515.pdf
As much as I appreciate the voluntary work of so many people to create open source software
and I honor this I want to say additionally: improve the documentation

best regards Stefan

connecting a MCP2515 to RP2040 so

// RP2040 RPi PICO connections
// MCP2515 INT to RP2040 GP20
// MCP2515 SCK to RP2040 GP18 SPI0_SCK
// MCP2515  SI to RP2040 GP19 SPI0_TX
// MCP2515  SO to RP2040 GP16 SPI0_RX
// MCP2515  CS to RP2040 GP17 SPI0_CSn
// MCP2515 GND to RP2040 GND
// MCP2515 VCC to RP2040 GP 3.3V

using the 107-arduino-mcp2515 library and running File>Examples>107-arduino-mcp2515>MCP2515_Loopback program I get

RP2040 RPi Pico MCP2515 test loopback

[ 724675] ID 1 DATA[0] 
[ 735133] ID 2 DATA[4] CA FE CA FE 
[ 745577] ID 3 DATA[8] CA FE CA FE CA FE CA FE 
[ 755519] ID 4 DATA[4] 33 0 10 7C 
[ 765424] ID 7FF DATA[0] 
[ 775812] ID(EXT) 80000000 DATA[0] 
[ 786012] ID(EXT) 9FFFFFFF DATA[0] 

which correspond to the sCanTestFrame values

Hello @StefanL38 ,
I've started playing with these, I'm using Earle Philhower's core, I think if you use it then you'll find the answer to your questions here:
https://arduino-pico.readthedocs.io/en/latest/

Attached pinout shows which pins are default.

Pico-R3-A4-Pinout.pdf (377.0 KB)

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