Interface for the main and auxiliary SPI peripherals.
RPPAL provides access to the available SPI buses by using the
/dev/spidevB.S, where B points to an SPI bus (0, 1, 2), and S to
a Slave Select pin (0, 1, 2). Which of these buses and pins is available depends on
your Raspberry Pi model and configuration, as explained below.
The Raspberry Pi's GPIO header exposes several SPI buses. SPI0 is available on all Raspberry Pi models. SPI1 is available on models with a 40-pin header. SPI2 is only available on the Compute and Compute 3.
SPI0 is disabled by default. You can enable it by running
sudo raspi-config, or by manually adding
/boot/config.txt. The associated pins are listed below.
- MISO: BCM GPIO 9 (physical pin 21)
- MOSI: BCM GPIO 10 (physical pin 19)
- SCLK: BCM GPIO 11 (physical pin 23)
Ss0BCM GPIO 8 (physical pin 24),
Ss1BCM GPIO 7 (physical pin 26)
SPI1 is an auxiliary peripheral that's referred to as mini SPI. According
to the BCM2835 documentation, using higher clock speeds on SPI1 requires
additional CPU time compared to SPI0, caused by smaller FIFOs and no DMA
support. It doesn't support
Mode3. SPI1 can be enabled by
1cs if you only require 2 or 1 Slave Select pins.
The associated pins are listed below.
- MISO: BCM GPIO 19 (physical pin 35)
- MOSI: BCM GPIO 20 (physical pin 38)
- SCLK: BCM GPIO 21 (physical pin 40)
Ss0BCM GPIO 18 (physical pin 12),
Ss1BCM GPIO 17 (physical pin 11),
Ss2BCM GPIO 16 (physical pin 36)
SPI2 shares the same characteristics and limitations as SPI1. It can be
enabled by adding
3cs with either
1cs if you only require 2 or 1 Slave Select
pins. The associated pins are listed below.
- MISO: BCM GPIO 40
- MOSI: BCM GPIO 41
- SCLK: BCM GPIO 42
Ss0BCM GPIO 43,
Ss1BCM GPIO 44,
Ss2BCM GPIO 45
The GPIO pin numbers mentioned above are part of the default configuration.
Some of their functionality can be moved to different pins. Read
/boot/overlays/README for more information.
spidev can handle up to 4096 bytes in a single transfer. You
can increase this limit to a maximum of 65536 bytes by appending
spidev.bufsiz=65536 to the single line of parameters in
Remember to reboot the Raspberry Pi afterwards. The current value of bufsiz
can be checked with
Some features exposed by the generic
spidev interface aren't fully
supported by the underlying driver or the BCM283x SoC:
first bit order),
SPI_3WIRE (bidirectional mode),
SPI_LOOP (loopback mode),
SPI_NO_CS (no Slave Select),
SPI_READY (slave ready signal),
SPI_RX_DUAL (dual SPI),
SPI_RX_QUAD (quad SPI),
and any number of bits per word other than 8.
If your slave device requires
SPI_LSB_FIRST, you can use the
reverse_bits function instead to reverse the bit order in software.
SPI_LOOP mode can be achieved by connecting the MOSI and MISO pins
SPI_NO_CS can be implemented by connecting the Slave Select pin on your
slave device to any other available GPIO pin on the Pi, and manually
changing it to high and low as needed.
Part of a multi-segment transfer.
Provides access to the Raspberry Pi's SPI peripherals.
Errors that can occur when accessing the SPI peripheral.
SPI modes indicating the clock polarity and phase.
Slave Select polarities.
Slave Select pins.
Reverses the bits of each byte in
Result type returned from methods that can have