SPI is included with the Adafruit_BBIO library. The following are the basics on how to use it.

You can import the SPI module:
from Adafruit_BBIO.SPI import SPI
Once you've imported it, you'll want to initialize the bus and device:
spi = SPI(0,0)
The BeagleBone Black (BBB) includes SPI0, as well as SPI1. SPI1 is currently not available by default as the HDMI interface is utilizing one of the pins.
Note: It is not possible to use SPI1 on the BeagleBone Black without disabling the HDMI interface.
There are four /dev/spidev* bus and device combinations available. They are available by executing the following code:
#import the library
from Adafruit_BBIO.SPI import SPI

#Only need to execute one of the following lines:
#spi = SPI(bus, device) #/dev/spidev<bus>.<device>
spi = SPI(0,0)	#/dev/spidev1.0
spi = SPI(0,1)	#/dev/spidev1.1
spi = SPI(1,0)	#/dev/spidev2.0
spi = SPI(1,1)	#/dev/spidev2.1
If you'd like to disable HDMI to access SPI1, you can add the following to your uEnv.txt file in the small FAT partition on your BBB:
mkdir /mnt/boot
mount /dev/mmcblk0p1 /mnt/boot
nano /mnt/boot/uEnv.txt
#change contents of uEnv.txt to the following:
optargs=quiet capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN

Pins used for SPI0 and SPI1

SPI0 P9_17 P9_21 P9_18 P9_22
SPI1 P9_28 P9_29 P9_30 P9_31

This guide was first published on Jun 13, 2013. It was last updated on Jun 13, 2013.

This page (SPI) was last updated on May 09, 2021.

Text editor powered by tinymce.