In this post, we’re going to quickly tell you how to use the second hardware SPI port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all that’s needed to do is call the appropriate functions in your sketch.
The default hardware SPI port uses the D10 (SS), D11 (MOSI), D12 (MISO) & D13 (SCK) pins for communication. This is very common across almost all the Arduino boards. The second hardware I2C port uses the A6 (SS), A7 (MOSI), A0 (MISO) & A1 (SCK) pins for communication.
For this example, we are going to interface a 3rd party 8×8 LED matrix board (MAX7219) that uses SPI for communication. The Pico and Nano are both 5V boards so please make sure the module you use is 5V compatible or else you will need to use a level shifter to convert the 5V signals to 3.3V and vice-versa.
Here’s what the connections look like:
- Connect the CLK pin to A1
- Connect the SS pin to A6
- Connect the MOSI pin to A7
- Connect the 5V and GND pins to the microcontroller or appropriate power source
Using the new SPI port is very simple. You simply need to use SPI1 instead of SPI. Here’s what the sketch looks like:
We start by setting up the SPI port we then call the initialization function for the module which initializes the MAX7219 chip. We then repeatedly display the characters BNBE on the module.
Here’s what the function that sends two bytes to the MAX7219 looks like:
We have omitted the initialization function from this post as that’s dependent on the module that’s being interfaced. You can download the entire sketch using the link below if you need to use it.
Here’s what the output looks like: