josh_blackburn
Posts: 4
Joined: Fri Dec 13, 2019 9:48 pm

How to use SPI1 bus on Raspberry Pi Zero 2 W?

Wed Sep 21, 2022 11:53 pm

In the more in depth pinout guides for the zero 2 w, like the one linked below, a second SPI bus, SPI1 is listed as being accessible through the GPIO header. Unfortunately, I haven't been able to find any info at all on using that second SPI bus, not even a mention of it existing at all, outside of graphical pinouts.
Is SPI1 usable? If so, how would I go about using it to communicate with sensors?
The reason I want to be able to use it in the first place is because I'm trying to get a setup where the console is displayed through an SPI TFT display AND I can have a second SPI TFT display controlled through regular python, plus some other SPI sensors. I plan to have two of the Adafruit 240x240 mini PiTFTs, linked below, one console and one programmable. Adafruit's kernel module works great for displaying the console on one screen, but it monopolizes the whole SPI0 bus, preventing anything else from using it. If there's a way to display the console to one screen without nuking SPI0, that'd work fine as well, but it seems to me that using SPI1 for the other display + sensors would be the easier method.



Pinout: https://www.etechnophiles.com/wp-conten ... ebp/ngcb40
Adafruit display: https://www.adafruit.com/product/4484
Adafruit kernel module guide: https://learn.adafruit.com/adafruit-min ... le-install

User avatar
thagrol
Posts: 7936
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 12:11 am

Searching /boot/overlays/README for spi1- is likely a good starting point.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

alphanumeric
Posts: 3140
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 10:43 am

I'm using it on a Pi Zero. There is a dtoverlay entry that needs to be added to the config.txt file. I have three small LCD's wired up so I used

Code: Select all

dtoverlay=spi1-3cs

That gets me the use of 3 chip selects.

SPI0
GPIO 7, Pin 26, CE1
GPIO 8, Pin 24, CE0
GPIO 9, Pin 21, MISO
GPIO 10, Pin 19, MOSI
GPIO 11, Pin 23, SCLK

SPI1
GPIO 16, Pin 36, CE2
GPIO 17, Pin 11, CE1
GPIO 18, Pin 12, CE0
GPIO 19, Pin 35, MISO
GPIO 20, Pin 38, MOSI
GPIO 21, Pin 40, SCLK

/boot/config.txt

dtparam=spi=on

dtoverlay=spi1-1cs #1 chip select
dtoverlay=spi1-2cs #2 chip select
dtoverlay=spi1-3cs #3 chip select

SCLK - Serial ClocK
CE - Chip Enable (often called Chip Select)
MOSI - Master Out Slave In
MISO - Master In Slave Out
MOMI - Master Out Master In

josh_blackburn
Posts: 4
Joined: Fri Dec 13, 2019 9:48 pm

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 7:54 pm

I will give that a shot, thank you very much!

josh_blackburn
Posts: 4
Joined: Fri Dec 13, 2019 9:48 pm

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 8:59 pm

For anyone who finds this looking for the same thing, alphanumeric's solution worked for me. I added

Code: Select all

dtoverlay=spi1-1cs #1 chip select
dtoverlay=spi1-2cs #2 chip select
dtoverlay=spi1-3cs #3 chip select
right after

Code: Select all

dtparam=spi=on
in my /boot/config.txt file and rebooted, the I could see /dev/spidev1.0/1/2 with the "ls /dev/spi*" command. To use SPI1 in my code, I just had to change board.SPI to busio.SPI, which gives the ability to change the pins used. The pins were then set to SCLK_1 instead of the default SCLK. Here's the simple code for a BMP388 sensor in SPI mode that I used to test all this.

Code: Select all

import time
import board
import busio
import adafruit_bmp3xx

# SPI setup
from digitalio import DigitalInOut, Direction
#spi = busio.SPI(board.SCLK, MOSI=board.MOSI, MISO=board.MISO) #use spi0
spi = busio.SPI(board.SCLK_1, MOSI=board.MOSI_1, MISO=board.MISO_1) #use spi1
cs = DigitalInOut(board.D16)
bmp = adafruit_bmp3xx.BMP3XX_SPI(spi, cs)

bmp.pressure_oversampling = 8
bmp.temperature_oversampling = 2

n = True
while n == True:
    try:
        print(
            "Pressure: {:6.4f}  Temperature: {:5.2f}".format(bmp.pressure, bmp.temperature)
        )
        time.sleep(1)
    except KeyboardInterrupt:
        print()
        n = False
Thanks again alphanumeric

User avatar
thagrol
Posts: 7936
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 9:12 pm

josh_blackburn wrote:
Thu Sep 22, 2022 8:59 pm
For anyone who finds this looking for the same thing, alphanumeric's solution worked for me. I added

Code: Select all

dtoverlay=spi1-1cs #1 chip select
dtoverlay=spi1-2cs #2 chip select
dtoverlay=spi1-3cs #3 chip select
right after

Code: Select all

dtparam=spi=on
in my /boot/config.txt file and rebooted, the I could see /dev/spidev1.0/1/2 with the "ls /dev/spi*" command.
You don't need all three of those overlays. Just include the one for the number of CS lines you need.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

josh_blackburn
Posts: 4
Joined: Fri Dec 13, 2019 9:48 pm

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Thu Sep 22, 2022 9:20 pm

thagrol wrote:
Thu Sep 22, 2022 9:12 pm
You don't need all three of those overlays. Just include the one for the number of CS lines you need.
That makes sense, my project will probably use all three, at least two, but that is good to know. Thanks

alphanumeric
Posts: 3140
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: How to use SPI1 bus on Raspberry Pi Zero 2 W?

Fri Sep 23, 2022 1:33 am

You don't need the dtparam=spi=on either, as far as I know, if all your using is SPI1
dtparam=spi=on turns on / enables SPI0
dtoverlay=spi1-1cs turns on / enables SPI1 with 1 Chip Select. 2cs gets you two Chip Selects etc.

Return to “Interfacing (DSI, CSI, I2C, etc.)”