SPI1 (Auxiliary SPI)
SPI1 (an auxiliary SPI device) is supported in raspbian kernels from 4.4 onwards. Librpip supports SPI1 from version 0.3.0 onwards.
SPI1 uses GPIO16-21 (by default) and is found on all 40 pin rPi’s to date.
It has up to three CS lines allowing you to control 3 devices natively. The kernel module allows for the CS lines to be repositioned on any free GPIO pin via the appropriate options passed to the dtoverlay.
The device reports supporting the following Linux SPIdev options:
- SPI_CS_HIGH (CS inverted)
- SPI_NO_CS (Device is signalled elsewhere) – this option is utilised for the GPIO CS implementation the kernel driver now uses.
Prerequisite Configuration
- Arch requires Prerequisite Configuration. See this page for more information.
/boot/config.txt
The implementation of SPI1 allows for a fair bit of flexibility. There three overlays, a 1CS, 2CS and 3CS option. If you only need to control one device use the 1CS option. You can expand to more CS lines later
#enable spi1 with a single CS line dtoverlay=spi1-1cs #enable spi1 with two CS lines dtoverlay=spi1-2cs #enable spi1 with three CS lines dtoverlay=spi1-3cs
Additionally the CS lines are now software controlled so they can be reconfigured to any available GPIO pin. See the /boot/overlays/README for details. Do not disable the spidev device nodes – this is what librpip uses!
Kernel Module
The module is called spi_bcm2835.
If SPI1 is enabled in the config.txt the kernel module should load automatically after a reboot. Check with lsmod.
$ lsmod | grep spi spi_bcm2835 7216 0
If it doesn’t appear make sure this isn’t blacklisted in/etc/modprobe.d/raspi-blacklist.conf. When the module is running you will find device nodes have been created as per the dtoverlay in the the config.txt.
crw-rw---- 1 root spi 153, 0 Jan 11 15:47 spidev1.0 crw-rw---- 1 root spi 153, 1 Jan 11 15:47 spidev1.1
System Config
You should already have a user group called ‘spi’ which has read/write access to the device nodes. Add yourself and any other accounts that need access to this group if you have not already done so.
sudo usermod -a -G spi <acccount>
Issues
Activating SPI1 whilst the console is on the Aux UART (ttyS0) will cause the rPI to boot slowly and then lockup. All rPIs apart from the PI3B use ttyAMA0 so they are unlikely to be affected but the PI3B uses ttyS0 by default so just activating SPI1 on a PI3B will cause a lockup. See Github Issue and Raspberry PI Foundation Forum Discussion.
SPI1 does not support 3wire mode.