SPI BeagleBone Black

Enabling SPI on BeagleBone Black

A year ago, I came across few folks who were facing issues on how to enable and use the SPI device on their Beaglebone, from that point of view, I decided to write this article to show how to load and enable an SPI module, for use on the Beaglebone.

In embedded Linux, enabling an SPI device basically means, letting the kernel know that you’d like to use this device for communication.  However, the method of enabling the device/modules for use may slightly differ from one kernel version to another.

So first, let’s ssh into the Beaglebone and check the kernel version as shown below:

Now, you should see an output with the kernel version like below, currently, I am using ‘kernel 4.1.18-ti-r53’

dtbo for SPIDEV0 on the BBB

Let’s check if the .dtbo object file for the SPIDEV0 exists by running the below command,

Below you can see the .dtbo’s that you can use to enable any modules such as SPI, LCD CAPE, PWM etc…

On BBB, we have two SPI modules. As you can see above in the 1st Column ‘ 24th and 25th row, the two SPI devices are BB-SPIDEV0 and BB-SPIDEV1. In this article, we will be enabling the  BB-SPIDEV0.

In case, you can’t find the .dtbo’s for the SPI devices, then you will have to compile one by your own i.e. write or generate a .dts file and compile it using the device tree compiler. There is a nice tool to generate a .dts file along with some good information here. Another source of good information on this topic by Adafruit is here

Enable the BB-SPIDEV0 on BBB

This one’s pretty simple, provided you follow the below steps very carefully:

Step 1: Go to the ‘boot’ directory as shown below,

Step 2: In the ‘boot’ directory, open the ‘uEnv.txt’ file using your choice of editor. I use nano.

Step 3: In the ‘uEnv.txt’ file, you will find the below lines,

Edit the above lines as shown below, you can see that we have enabled the capemgr by uncommenting the second line and we have assigned it to BB-SPIDEV0. Doing this will load the SPIDEV0 to the slot making it usable for communication.

Step 4: Reboot your BBB by making a system call as shown below, or just press the reset button on your BBB.

Step 5: Now check if the SPIDEV0 has been loaded into the slot and enabled as shown below, by going to the ‘bone_capemgr’ directory. You can also check this by issuing a ‘dmesg’ command.

You should see an output as shown below. You can see that the BB-SPIDEV0 has been loaded and now you can use it to communicate with external spi devices.


You can see that, I have also loaded the PWM2 module, which I did a couple of days back to control a servo motor.

As I had mentioned in the starting of this article, that some folks were facing issues enabling the SPI device, one of the reasons were due to the difference in the kernel versions. Rudy and I have answered most of the queries and discussed regarding these issues in Google groups, so you’re facing any trouble enabling the spi device or using an older version of the kernel such as 3.8, then please view the discussion here.

In the upcoming articles, I will show how to test the enabled spi device and interface some external devices that use SPI interface for communication. Until then, be in sync with Deeply Embedded.

Leave a Reply

Your email address will not be published. Required fields are marked *