Enable SPI with device tree on BeagleBone Black (copy-paste)

Here is a copy-paste version of of how to enable SPI on the new BeagleBone Black. This version should work for 3.8.6 and 3.8.13 of the kernel.

Update June 3 2013: I’ve updated the instructions to match the standards defined in the device tree overlay documentation. This overlay is currently in conflict with the HDMI firmware with audio support. A patch for that is being worked on. If you need SPI working right now, try SPI0 instead or disable the HDMI framer firmware.

Update June 10 2013: There is a pending pull-request in the BeagleBoard kernel for splitting the HDMI overlay into audio and video. In the meantime, here are the overlays:



And you probably need the new board device tree descriptors:



Note: I’ve not tried plugging these directly into a BeagleBone (the overlays must be compiled and placed in /lib/firmware and the board descriptors must be placed in /boot/), so something bad might happen. Use at your own risk! Worst case you bork it (it’s the same as “brick it” only less severe, can be fixed with a uSD card.. ) Apparently this is the right expression, but don’t quote me on that..

Update July 17. 2013: The latest 3.8.13 kernel has two different HDMI overlays, one with and one without audio. The one with audio has part number ‘BB-BONELT-HDMI’ and the one without audio has part number ‘BB-BONELT-HDMIN’.

Start nano

nano BB-SPI1-01-00A0.dts

Copy-paste this into the file:


/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "BB-SPI1-01";

    /* version */
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
        /* the pin header uses */

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            pinctrl_spi1: pinctrl_spi1_pins {
                pinctrl-single,pins = <                                        
                    0x190 0x13    /* P9_31 = mcasp0_aclkx.spi1_sclk                 , OUTPUT_PULLUP | MODE3 */
                    0x194 0x33    /* P9_29 = mcasp0_fsx.spi1_d0                     , INPUT_PULLUP  | MODE3 */
                    0x198 0x13    /* P9_30 = mcasp0_axr0.spi1_d1                     , OUTPUT_PULLUP | MODE3 */
                    0x19c 0x13    /* P9_28 = mcasp0_ahclkr.spi1_cs0                 , OUTPUT_PULLUP | MODE3 */                    
                    0x164 0x12  /* P9_42 = GPIO0_7 =  eCAP0_in_PWM0_out.gpio0[7] , OUTPUT_PULLUP | MODE2 */

    fragment@1 {
        target = <&spi1>;
        __overlay__ {
            #address-cells     = <1>;
            #size-cells     = <0>;
            status            = "okay";
            pinctrl-names    = "default";
            pinctrl-0        = <&pinctrl_spi1>;    
            cs-gpios         = <&gpio4 17 0>, <&gpio1 7 0>;

                #address-cells       = <1>;
                #size-cells       = <0>;
                compatible           = "spidev";
                reg               = <0>;
                spi-max-frequency = <16000000>;
                #address-cells       = <1>;
                #size-cells       = <0>;
                compatible           = "spidev";
                reg               = <1>;
                spi-max-frequency = <16000000>;
                // Mode 0 (CPOL = 0, CPHA = 0)

Close the file (Ctrl-o, Ctrl-x) and compile using dtc:

dtc -O dtb -o BB-SPI1-01-00A0.dtbo -b 0 -@ BB-SPI1-01-00A0.dts

Then, copy the file into /lib/firmware/:

 cp BB-SPI1-01-00A0.dtbo /lib/firmware/

Then enable the device tree overlay:

 echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots

Make sure it is enabled
You should now have two spidev-files in the folder /dev/

ls -al /dev/spidev1.*

You should also be able to see the pingroups:

cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pingroups

Install the python module
Note: The python module is not my work, it is the work of Volker Thoms according to the install script.

wget http://www.hipstercircuits.com/wp-content/uploads/2013/05/python-spi.zip
unzip python-spi.zip
cd spi
opkg update
opkg install python-distutils
python setup.py install

Test it with Python

Start Python:


Make an object of the SPI module and send some data. Make sure you have something interesting connected on the other end : )

from spi import SPI

spi1 = SPI(1, 0)
spi1.writebytes([0xCF, 0x00])

135 thoughts on “Enable SPI with device tree on BeagleBone Black (copy-paste)

  1. I am new to all the device tree manipulation and I am having problem compiling this code. I copied and pasted as you suggested and I got the error:

    Error: enable-spi1.dts:29.26-27 syntax error
    FATAL ERROR: Unable to parse input tree

    which I assume is the reference to:

    #address-cells = ;

    My assumption is that it is throwing an error due to equaling nothing. Should something be filled in? Is there somewhere I can go to learn how to use the device tree?

    I can remove all the stuff that have the variable =; and that will compile.

      • I’m still having this issue. What version of dtc is required? I’m using debian with kernel version 3.8.13-bone26 and dtc 1.3.0. Also, it does not support the -@ flag, and I suppose it may not be the only incompatibility. The parse error is terribly vague.

  2. Are you using Ubuntu 12.04 or 13.04?
    If I enable the DT I get an error which can be found due to “dmesg”:
    pin 44e10990 already requested by 48038000.mcasp; cannot claim for 481e000.spi

    How I can unload or avoid loading the Bone-Black-HDMI device tree?

    • Gerd, the distribution does not matter, its the kernel version that matters. You can find that out by:
      uname -a
      You should see the kernel version. Still for this case it is probably the HDMI firmware that is the culprit..

      As for the mcasp pin, that is probably the result of audio support through HDMI being added to the kernel. If you do not need audio, you should be able to edit the HDMI firmware and remove the line that muxes the pin.
      It should be possible to decompile the HDMI firmware, remove the line that muxes the pin and recompile. I don’t have a BBB available now, so I cannot fix it..

    • Ok, so you disabled the HDMI framer all together? That will work! As a less intrusive alternative, you should also be able to disable specific firmware on the kernel commadn line. Glad it worked for you, though! For others, they might switch the new audio enabled HDMI firmware with the older one that does not have audio-support and does not claim the pin.

  3. Does this work for anyone? I realized there were a bunch of cut and paste errors but even after fixing them it doesn’t work. I changed the pins and made another DTS file for SPI0 which works fine but SPI1 shares pins with the HDMI and doesn’t seem to work at all.

    • Bbb3, sorry for the typos, my online editor keeps removing stuff in brackets.. (but also a missing “1″ in the name) I think it’s OK now.
      Like Gerd says in the above comment there is a conflict with the HDMI firmware. I’ve been working on a solution to this, one that disables the audio support for the HDMI so the pins can be claimed, but haven’t got a solution yet..

      • Works fine on BBB with SPI0 instead of SPI1 which doesn’t conflict with HDMI. Probably good idea to update code to reflect SPI0 until it is resolved.

        • According to Koen Kooi, the maintainer of Angstrom, the HDMI firmware should be split up. I’ll start working on this, and submit a patch. SPI 0 is not an alternative for me : )

    • To be honest, I’m uncertain of the preferred way to handle a case like this. I’ve posted a comment on the beagleboard G+ group so we’ll see..

  4. Dumb question, but am I compiling this on the BeagleBone or on a linux box and then copying it over? Cause if I’m doing it on the BBB then the python setup fails with
    error: command ‘arm-angstrom-linux-gnueabi-gcc’ failed with exit status 1

    And for the life of me I can’t find a package or copy of the arm-angstrom-linux-gnueabi-gcc that will install on the BBB.

      • Thanks found the file where you indicated. I am such a duffus, I need to read the error message. The GCC is there, it was complaining about missing header files.

        arm-angstrom-linux-gnueabi-gcc: error trying to exec ‘as’: execvp: No such file or directory
        spimodule.c:19:20: fatal error: Python.h: No such file or directory

        • For those that have got a stock BBB image (as of this post BBB-eMMC-flasher-2013.05.27.img.xz) you will need to install a few extra things before you can follow these steps.

          opkg install dtc
          opkg install python-distutils
          opkg install python-email
          opkg install gcc
          opkg install binutils
          opkg install linux-libc-headers-dev

          Also be aware that if you reboot you need to re issue the command
          echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots

  5. I’m new to Beaglebone and device tree overlays. I would like to know where the information comes to create a device tree overlay (not the actual structure but the details). For example where does the address 0×190 0×13 for pin9_31 comfrom? Or would I know the line with “pinctrl_spi1: pinctrl_spi1_pins {pinctrl-single,pins” needed to be in there and where did these names come from? And for the code listed under fragment, where did those details come from?

    Thank you,

    • Stephen, it can be removed at runtime. First cat the manager to find out the cape index:
      cat /sys/devices/bone_capemgr.*/slots
      Then remove the right index:
      echo -6 > /sys/devices/bone_capemgr.*/slots
      There has been an error causing you to be thrown out of your SSH session, not sure if this has been resolved..

  6. I have problems to compile the overlay. I have kernel “Linux ubuntu-armhf 3.8.12-bone17″. Compiling it, it tells me that it does not know the option -@. Removing this “-@” it tells me:
    “Error: BB-SPI1-01-00A0.dts:2.2-8 syntax error
    FATAL ERROR: Unable to parse input tree”.
    I’m using device tree compiler 1.3.0.
    Any idea?

    • Mmh… I have a very strange situation. I downloaded the file and unzipped it. It is for 100% in the folder, i made it executeable, and it is for 100% in the directory. But it is not executable.
      root@ubuntu-armhf:/home/ubuntu/enablespi# ls -l
      total 112
      -rw-rw-r– 1 ubuntu ubuntu 2180 Jan 1 2000 BB-SPI1-01-00A0.dts
      -rwxr-xr-x 1 root root 69712 Jun 10 2013 dtc
      -rw-r–r– 1 root root 34113 Jan 1 00:11 dtc.zip
      root@ubuntu-armhf:/home/ubuntu/enablespi# ./dtc
      bash: ./dtc: No such file or directory
      Any idea?
      By the way: I got my ubuntu package by apt-get install dtc.

  7. I would like to share my experience to get SPI0 working. It is a mixture of this and the google group linked below.
    1. Download SPI0.dts here.
    2. Compile it with dtc.
    dtc -O dtb -o spi0-00A0.dtbo -b 0 -@ spi0.dts
    Make sure, it is named with 00A0 – without it will not work.
    3. Enable it:
    echo spi0 > /sys/devices/bone_capemgr.8/slots
    4. Check if SPI is available
    ls -al /dev/spi*
    cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pingroups
    5. You can echo something over SPI.
    echo “SPI” > /dev/spidev1.0

    • Very good, Michael. Notice that you can specify the revision on the command line, so if you have a revision 00A1, add it after a colon:
      echo spi0:00A1 > /sys/devices/bone_capemgr.8/slots
      Can I ask you what you are making ? :)

      • Thank you for your valueable comment on the revision. Didn’t knew that; I’ll use that!
        This will be a testbench for a DC/DC Converter. The SPI switches the loads over an 74HC595. Nothing fancy…

    • Attention, there’s an error. The SPI0 CLK must be defined as an output. Change the line in the SPI0.dts to
      0×150 0×10 /* spi0_sclk, OUTPUT_PULLUP | MODE0 */
      instead of
      0×150 0×30 /* spi0_sclk, INPUT_PULLUP | MODE0 */

      • Just one last comment to it:
        In case you want to send a hex-code over the bash, use the following command:
        echo -ne “\xFF” > /dev/spidev1.0

  8. Hi, Your update of 10th June with news about splitting the HDMI video and audio is very welcome as I am struggling to get the original audio cape to work on a Black. However your links for the 2 overlays both appear to point to the same zip file. The -audio one is missing. Since I do not need the audio on HDMI at all for my current project I will try just using the video overlay and let you know what happens.

    • Robert, you are right, sorry about that. I will fix it once I get into the office so you can have it for reference, but it’s basically splitting the old HDMI overlay in two. Meanwhile, you should be able to see the changes from the pull-request that I have linked to. Let me know how it goes!

  9. Hi Elias,

    When attempting to compile the cape-boneblack-hdmi-00A0.dts to its .dtbo I get the following errors.
    ERROR (phandle-references): Reference to non-existant node or label

    and so I cannot go any further at present. Incidentally, would it be useful in the final version to call the video section of the cape -hdmi-video- like the -hdmi-audio- to save confusion with the existing combined video & audio version.

    • Robert, I’m not sure why you are unable to compile. What image are you using? What command are you using for compiling? I’ve updated the page so the HDMI audio should point to the right file.

      • Eliaz, I am running the latest download BBB 3.8.13. May 27.
        Copied descriptor files into boot and the overlay into /lib/firmware and then rebooted.
        Compile command is -
        dtc -I dts -O dtb -o cape-boneblack-hdmi-00A0.dtbo cape-boneblack-hdmi-00A0.dts

        I have tried it a few times to eliminate typos and it always gives the same errors. Thanks for the audio file – I will now try compiling this one.

  10. Thanks . I was able to enable the spi0 and spi1 on my BBB using files from michaels post. and the procedures form this tutorial.

    on a side note: copying the am335x-bone.dtb and am335x-boneblack.dtb to /boot did not bork my BBB…whew…

    again. thanks

  11. Elias, I tried with both the new compiled HDMI files and I still get a picture on the screen which is a start but the HDMIA will not load. It is detected in slot 6 as a virtual cape but fails to unflatten (expand) as shown in dmesg

    slot #6: dtbo ‘cape-boneblack-hdmi-audio-00A0.dtbo’ loaded; converting to live tree
    slot #6: Failed to unflatten
    loader: failed to load slot-6 BB-BONELT-HDMIA:00A0 (prio 1)

    I have tried this on both DVI monitors (where the audio would not be used) and on full HDMI TV that supports audio. This is not too critical at the moment since the idea of the split virtual cape is to get rid of the HDMI audio but I thought it was worth seeing if it would work if needed and it does not appear to. Perhaps I need to enable it somehow.

    The next problem I have that you might be able to help with is that the Audio Cape is detected as

    slot #0: ‘BeagleBone AUDIO CAPE,00A1,Beagleboardtoys,BB-BONE-AUDI-01′
    slot #0: Requesting part number/version based ‘BB-BONE-AUDI-01-00A1.dtbo
    failed to load firmware ‘BB-BONE-AUDI-01-00A1.dtbo’
    loader: failed to load slot-0 BB-BONE-AUDI-01:00A1 (prio 0)

    but the only firmware I can see is version 00A0. I have searched for an 00A1 version of firmware without luck and I assume that I cannot just rename or recompile it with the new name. Any idea where I might find 00A1.

    • I think you need to bug the creaters of the audio cape about the changes to the device tree overlay or even better, fix it youself ! Not sure why the HDMI audio does not flatten..

  12. I have setup SPI on a beaglebone white using this cut and paste procedure. I can see the SPI signals on the hardware pins. However the MISO and MOSI signals on my hardware are swapped compared to the driver.

    KERNEL/drivers/spi/spi-omap2-mcspi.c has an option “ti,pindir-d0-out-d1-in” which should swap these pins.

    I have added this to my spi1_0 entry but it has no effect.

    spi1_0 {

    Is there something else I need to do to allow this option to be active?

  13. It would be nice if you broke down the compile line for the reader. I’ve found tutorials on dtc but I haven’t see the @ used.
    dtc -O dtb -o BB-SPI1-01-00A0.dtbo -b 0 -@ BB-SPI1-01-00A0.dts

    dtc Device tree compiler command
    -O dtb The -O flag specifies the output format—in this case, the device tree blob binary (dtb).
    -o BB-SPI1-01-00A0.dtbo The -o flag names the output file (in this case BB-SPI1-01-00A0.dtbo) The dtbo is an Device Tree Object.
    -b 0 Specifies the physical boot CPU in the multicore case.
    -@ ???
    BB-SPI1-01-00A0.dts —The input file

  14. Hi Elias,

    i had a similar issue with my Audio Cape, it had wrong EEPROM contents (from the DVI and Audio Cape).

    00A0 and 00A1 is not a hardware change, “Only PCB is changed in this revision. No design changes are made”

    It’s enough to load the EEPROM contents, change the revision from A1 to A0 and it should work. For that you need the bonescript eeprom.js.

    (assumed audio cape slot 0)
    sudo cat /sys/bus/i2c/drivers/at24/1-0054/eeprom > my.dump

    nodejs ~/node_modules/bonescript/eeprom.js -r cape:my.dump my.json

    -> change in my.json revision number with texteditor

    nodejs ~/node_modules/bonescript/eeprom.js -w my.json my.json my.eeprom

    -> check eeprom

    hexdump -C my.eeprom
    -> if this looks similar to
    hexdump -C my.dump
    (except revision changed), you are good to go to write back to the EEPROM

    cat my.eeprom > /sys/bus/i2c/drivers/at24/1-0054/eeprom
    -> for this to work, you need to ground TP1 on the audio cape.

    in demsg
    [ 1.672833] bone-capemgr bone_capemgr.9: slot #0: dtbo ‘BB-BONE-AUDI-01-00A0.dtbo’ loaded; converting to live tree

    aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: EVM [DA830 EVM], device 0: AIC3X tlv320aic3x-hifi-0 []
    Subdevices: 0/1
    Subdevice #0: subdevice #0

    I hope this helps, i had to invest a lot of time to find out.


  15. Hi Elias, this article’s being extremely useful to me.
    However I’m having an issue, every time I reboot my BB I need to run again the command
    $ echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots

    Is there any way to store this information permanently?

    • Yes, there is. You can add an argument on the kernel command line. It is located in the file /media/BEAGLEBONE/uEnv.txt
      You shoudl have optargs=quiet or something, just add:

      • Thanks for replying.

        Accessing /media/BEAGLE_BONE leads me to an empty directory, however I can open uEnv.txt thru Windows using the USB cable. Does that do the same effect?

        So, my file is now:
        optargs=run_hardware_tests quiet
        capemgr.extra_override=echo spi0 > /sys/devices/bone_capemgr.*/slot

        (I’m using SPI0) But it still didn’t work. I tried using quotes aroud “echo … slot” as well, but no success either.

        • Searching more I figured out that what I tried before was plain stupid :P

          So I changed to “capemgr.extra_override=spi0pinmux:00A0″
          as I declared on the .dts file:
          /* identification */
          part-number = “spi0pinmux”;
          /* version */
          version = “00A0″;

          Yet, no luck :(

          • That is the (right) way to do it. I have not enabled anything from the kernel command, only disabled. You might have to have it declared in the am33xx-boneblack.dts file for it to work. I’ve been thinking of making a post about it, just haven’t gotten around to it yet..

  16. Guilherme, am335x-bone.dtb in /boot/ is for BB white.
    Do you know how to compile them? I have not done it with a standalone compiler, only through the kernel build system..

    • No, my Linux knowledge is very shallow (I don’t even know how to compile the kernel).
      I still have a lot to read, search and dig.

  17. Hi Elias,
    I tried to connect directly MISO and MOSI. And I can see the CK and the output with an osci, but Im not getting anything in the input (using spidev-test).

    So based in other dts files I changed the line
    0×190 0×13 /* P9_31 = mcasp0_aclkx.spi1_sclk , OUTPUT_PULLUP | MODE3 */
    0×190 0×33 /* P9_31 = mcasp0_aclkx.spi1_sclk , OUTPUT_PULLUP | MODE3 */

    and it works, this is strange since the CK should be an output. Any clue? Does the input it work fine for you?

      • Hi Elias

        Would you be able to change your blog to reflect that the sclk pin should be an input? I know it didn’t make much sense to me, but if it isn’t set to being an input, then the SPI will only be able to send data and not recieve data, regardless of the voltages on the MISO pin.

        This is consistent with the advice on http://elinux.org/BeagleBone_Black_Enable_SPIDEV
        It may just save someone hours of software debugging troubles!

        But thanks for the great blog otherwise, it certainly helped get me started

  18. I edited my uEnv file like this and it worked:

    optargs=run_hardware_tests quiet capemgr.enable_partno=BB-SPI0-ENABLE

    Before, I didn’t realize it should be all in the same line. Now I am trying to repeat the same procedure with Ubuntu.
    The DT stuff work fine, but the uEnv is not working. It doesn’t load on boot. Any ideas?

  19. Good news: I got everything working on the Ubuntu as well with the BB white.

    Bad news: today I got a couple of BBB to play with and I’m getting some conflicts (I think so) with SPI and HDMI. Check this, starting at 1.3 seconds: http://pastebin.com/WJmCWrAv

  20. Pingback: First steps into devicetree… | nickwideas

  21. Hi,

    I need to move my software from beaglebone white to beaglebone black, my goal is to use the SPI1 exactly like it was working on beaglebone white.

    -I’m working with debian available at url : http://www.armhf.com/index.php/boards/beaglebone-black/#wheezy
    -If I follow instruction to use SPI1 available at the following url:
    the spi1 data0, data1, clock is ok, but the chip select don’t move :)
    -If I try to use the spi0, every think is working well.
    -If I use the sample provided by this website, the chip select is working well on Pin P9_42, but it’s not by goal…

    I had removed file “cape-boneblack-hdmi-00A0.dtb”0 and I have added option “capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN” in uEnv.txt, but I have no idea what I need to do to have P8_28 chip select working well.

    (F.Y.I I have recompiled file am335x-boneblack.dtb provided by Gerd, but without improvement)
    Best Regards,

  22. Hi Elias,

    I tried, to activate SPI1, following your guide, but when I type
    echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots
    I get the message:
    echo:write error: File exists
    But still there is no /dev/SPI1/ folder.
    I am quite new to Linux and BBB and got no idea, how to fix this.
    Could you please help me?

    • Rafael, the first thing you should do is check the kernel messages:
      Look for a more descriptive error of why it did not work.
      Secondly, that error might be due to the fact that there is a conflict between one or more
      of the pins. As have been discussed here, the audio portion of the HDMI
      is in conflict, so you might have to disable the cape overlay with the HDMI+Audio.
      For testing, try to cat the cape manager:
      cat /sys/devices/bone_capemgr.*/slots
      find the number with the HDMI cape, and write:
      echo - /sys/devices/bone_capemgr.*/slots
      Then try again. This will remove the overlay for the HDMI framer, but it might work for testing.

      • Elias, dmesg shows no errors at all for
        echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots
        When I enter
        echo -5 > /sys/devices/bone_capemgr.*/slots
        (5 is the number for the HDMI cape) the window closes. dsmg shows the following error:

        unable to handle kernel NULL pointer dereference at virtual address 0000001b pgd = de770000
        *pgd=9e635831, *pte=00000000, *ppte=00000000
        Internal error: OOps: 17 [#1] SMP THUMB2
        Module linked in: fuse ip_table g_multi libcomposite rfcomm ircomm_tty ircomm irda ipv6 hidp bluetooth rfkill autofs4
        CPU: 0 Not tainted (3.8.13#1)
        PC is at omap_device_idöe+0xc/0x3a
        LR is at _od_runtime_suspend+0×15/0×18

        Then some flags, registers, and a lot hex-numbers.
        If I then start a new Terminal and enter
        cat /sys/devices/bone_capemgr.*/slots
        it produces a freeze where the terminal doesn’t even react when i press ^C. After a reboot the HDMI entry is still there.

          • I’ve got to correct myself. dmesg shows errors:
            (“bone-capemgr bone_capemgr.8:” is written at the beginning of every line, so i replaced it with the sign ‘%’ to save space)

            %part_number ‘BB-SPI1-01′, version ‘N/A’
            %slot #8: generic override
            %bone: Using override eeprom data at slot 9
            %slot #8: ‘Override Board name, 00A0, Override Manuf, BB-SPI1-01
            %slot #8: Requesting part number/version based ‘BB-SPI1-01-00A0.dtbo
            %slot #8: Requesting firmware ‘BB-SPI1-00A0.dtbo’ for board-name ‘Override Board Name’ version ’00A0′
            %slot #8: dtbo ‘BB-SPI1-01-00A0.dtbo’ loaded; converting to live tree
            %slot #8: BB-SPI1-01 conflict P9.31 (#5:BB-BONELT-HDMI)
            %slot #8: Failed verification

          • Elias, you were right with the HDMI framer. I disabled it, by writing: optargs=quiet capemgr.disable_partno=BB-BONELT-HDMI capemgr.enable_partno=BB-BONELT-HDMI
            in the uEnv.txt file, and everything is working now.
            Thank you very much for your great work with this guide.

  23. Hi, this was a great copy-paste tutorial.
    I was able to set up the SPI communication using 74HC595N (8 bit shift register). However, while sending a hex string (or a binary string), my LSB is always delayed and needs two simultaneous commands to set. Any idea about what’s happening?

  24. Hi,

    I am using both CAN0 and CAN1 on my BBB, so I cannot use I2C2 (since it uses same pins as dcan0), essentially disabling my capes. Is there any way to get SPI working without using capes?

    By reading the file am33xx.dts, I understand SPI comes under OCP. So we should be able to use it like other peripherals such as dcan. But I have no idea how to use it.
    Does anyone have a clue how it works?


    • Hm.. that’s a tricky one. I2C2 must be enabled during boot in order to probe for capes, but after that is done, I see no reason to keep it enabled. Have you tried making a cape overlay that disables it?
      You might be able to disable i2c2 by setting status to “disabled” instead of “ok”.. I’ve not tried this, but it might work .

      • Thanks for your quick reply Elias,

        Yes, I have tried disabling the i2c2 in the overlay. When I boot, I can no longer see /sys/devices/bone_capemgr.*/slots directory.

        according to the reference manual for BBB (section 8.2.2, page 96)

        “The EEPROMs on each expansion board are connected to I2C2 on connector P9 pins 19 and 20. For this reason I2C2 must always be left connected and should not be changed by SW to remove it from the expansion header pin mux settings. If this is done, then the
        system will be unable to detect the capes”

        Can there be any other workaround for using 2 CAN and 2 SPI at the same time? I am interested in knowing if SPI can work without Cape.

        • Don’t disable I2C2 on start-up, instead do it after the board has booted by making a device tree overlay and enabling it manually.
          Something like:
          fragment@1 {
          target = < &i2c2>;
          __overlay__ {
          status = “disabled”;

          Not sure if it will work, but it’s worth a shot. If it does not work I think your best bet is to look in the kernel source code.

  25. Hey everyone,
    I want just to give a tip: when defining the CLK pin as output, you will only be able to write data out of the spi module, if you want to be able to write an read define the CLK pin as input.

  26. This is my first time using SPI and I don’t have a device connected on the other side but I should still be able to see something on the DO and SCLK pins with an oscilloscope right? I’ve tried this tutorial, the elinux.org tutorial and the Adafruit tutorial for both SPI0 and SPI1 with no success. Do I just have a bad bone?

  27. I tried the suggestions but received the following -

    echo BB-SPI1-01 > /sys/devices/bone_capemgr.*/slots
    -bash: echo: write error: File exists

    Current permissions are -
    -rw-r–r– 1 root root 4096 Sep 19 11:18 /sys/devices/bone_capemgr.9/slots

    How can I resolve this?



  28. I’m trying to get an ADC to work with the BBB over SPI and am having trouble getting it to work properly. Are these instructions not supposed to work without diabling the HDMI?

  29. I am working on BBB . In order to boot from Sd card i removed MLO from the eMMC . if i insert SD card it not booting and also four user leds are not blinking…
    What is the problem..

    And also I want to enble spi interface on beaglebone black. The above mentioned work should be done on the BBB after booting or on the host machine..?

    • Varka, do not remove the MLO from the eMMC. Instead, hold down the “boot” button on the BBB when you apply power. It’s the button located on the HDMI-port side.

      It should definitely not be done on your host machine. Do it on the BBB after booting.

  30. hai…

    I wrote the driver for cc2520…And i am interfacing it to the
    Beaglebone. cc2520 initialisation is fine means if i send the SNOP strobe over
    the spi the reply is 0×80.. I am able to see the data on MISO in oscilloscope
    but in my driver code i am not able get the data which is there on MISO pin..

    I am displaying the code below..

    cc2520_get_status(struct cc2520_private *priv, u8 *status)
    struct spi_message msg;
    struct spi_transfer xfer = {
    .len = 1,
    .tx_buf = buf,
    .rx-buf = buf,

    spi_message_add_tail(&xfer, &msg);
    buf[0] = CC2520_CMD_SNOP;

    ret = spi_sync(spi , &msg);
    *status = buf[0];


    I am always getting the status as zero but in CRO it is showing as 0×80.

    Is the spi_sync() API is correct or which is better .. where might be the

  31. I have followed the instructions and still seem to be having problems getting the SPI working. Could some please confirm the following, to ensure my setup is okay

    I have the following spi devices:

    When I look at the pin groups:
    cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pingroups

    group: spi1_pins_s0
    pin 100 (44e10990)
    pin 101 (44e10994)
    pin 102 (44e10998)
    pin 103 (44e1099c)

    I have a loop back on pin 29 & 30 (spi1) and 18 & 21 (spi0)

    I have the spi test code, but still getting 0xff any support or advice would be highly appreciated.

  32. I’ve been trying to get SPI0 working on my BBB (rev A6) using ubuntu – 12.0.4 (kernel 3.8.13-bone30) ; I’ve tried this on the latest Angstrom as well and haven’t managed to get this working. My main issue is I get no SPI_clock signal on P9_22 pin looking with a logic analyzer.
    Here is what I have tried /checked
    1) added “capemgr.enable_partno=BB-SPIDEV0″ to the “uEnv.txt” file in “/boot/uboot”. This is the right uEnv.txt file in the fat portion of boot.
    2) verified the spi drivers were added. “ls -al /dev/spi*” shows the two spidev1.0 and spidev1.1 files.
    3) “cat /sys/devices/bone_capemgr.9/slots” shows it being loaded and the same with dmesg.

    I’ve tried the same with SPI1 and I get the same result. In the case of SPI1 i disabled the HDMI as needed. But I have no idea why in both cases overlaying with SPIDEV I get no clock signal.. Am I missing something.
    Btw I can toggle the other pins for the SPI; just need to see the clock.

  33. I have been trying to get SPI running on BeagleBone Black with default Angstrom linux. I followed all the above steps. But instead of a square wave clock on Pin P9_31(SPI CCLK) , I am getting a sine wave type clock. I am not sure what is the problem. How can I get a proper clock so that I can interface external ADC on SPI with BeagleBone Black

  34. I am not clear on 2 things:

    1) when I try to get the distutils, I get a “unknown package error (Angstrom 3.8.6); without it , I can’t run the installer for the python package.

    2)once that I enable SPI, can I use it with C/C++?

    Awesome guide BTW!

  35. Hello!
    Great tutorial! I am a newbie in the matter of circuits… Can you help me with something? It’s the first time I’m running python scripts. I have done everything you said in the tutorial, but… how do I see if the SPI interface is actually working? I have connected the pins P9_29 with P9_30 and run the python script. How do I see if it is working?
    Pretty thanks!

  36. thanks Eias, nice tutorial..i want to use this application in to program a NOR flash spi based interface. The data will be a U-boot file content. After copying U-Boot file into NOR flash theh i need to read check checksum. Is it possible with this ur provided method? if yes then how i can use read spi function and write / sector write / bulk write like functions ///pls let me know…\

  37. Hi,
    Nice tutorial, how i can see the functions like bulk write/erase/sector write eg:
    spi.writesector(sector_no,databuffer)? and spi.read(sector_no,databuffer) like functions.

  38. Dear Elias,

    First of all thank, your post help the new people get start with BBB.

    Please can you explane more about SPI code in pynthon ??



  39. I have installed the DTC in BeagleBoneBlack running angstrom linux(3.8.13 kernel).. While compiling, I am getting the following error.Can u help me with this?
    Error: BB-SPI1-01-00A0.dts:67.2-68.1 syntax error

  40. Hi All,

    I know a Device Tree is a data structure which keeps a track of all the devices under a board and it tells the kernel how to map it. But still couldn’t get a clear picture, why do we need Device tree. What kind of problem they resolve?

  41. @Elias
    I am using LCD7 cape from 4D Systems with BBB . I am not able to use SPI0 as well as SPI1. I am getting file verify error when we activate the virtual cape for SPI. Pins P9_30 (SPI1_D1) and P9_21 (SPI0_D0) & P9_22(SPI0_SCLK) are used by the LCD cape.. What work around can I do in the devcie tree overlay file (BB-BONE-LCD7-01-00A0.dtbo) to make the SPI work along with the LCD display??

  42. Pingback: How to use SPI of BBB | WindStudio

  43. Hi,

    I enabled SPI0 in uEnv
    end tried the spitest.c with success
    but If I try to use python nothing works.

    pingroups shows
    group: spi0_pins_s0
    pin 84 (44e10950)
    pin 85 (44e10954)
    pin 86 (44e10958)
    pin 87 (44e1095c)

    root@beaglebone:/home/adtran# ./spidev_test /dev/spidev1.0
    spi mode: 0
    bits per word: 8
    max speed: 1500000 Hz (1500 KHz)

    40 00 00 00 00 95
    F0 0D

    But my python test script (loop 18-21 patched)
    doesnt work. Who can I debug deeper ? Or where is my fault ?

    from Adafruit_BBIO.SPI import SPI
    import pprint as pp

    spi = SPI(0,0)
    spi.mode = 0
    spi.msh = 1500000
    spi.bpw = 16
    print spi.xfer2([0x80,0x50])

    -> output [[...]]

    And also I’m not able to use a variable for the result
    print data
    raises a fault also…

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>