I've been stuck in setting up the SPI communication in Linux and can't figure out any solution.

I working with a beagle bone black, which runs Linux. I have a piece of code that send data through the SPI bus if I connect MISO and MOSI pins I will receive the data that I have sent (so far so good).

The problem comes when I try to connect with the sensor I want to communicate with, everything I receive is zeros!

I am pretty sure that the problem comes from the SPI configuration in Ubuntu (since I already could communicate with the sensor, using SPI, using an Arduino for the purpose). But somehow, when I try to replicate the same very code to beaglebone I can't communicate!

In this link is an explanation of how to configure SPI on ubuntu: https://elinux.org/BeagleBone_Black_Enable_SPIDEV

I already followed the tutorial but the problem remains. Does anyone have some tip that must help me?

So, I already analyzed with the scope and I found that so intriguing, it's happening the follows:

  • In the cs pin and sck it's having oscillation. Nevertheless, in the MISO and MOSI pins there is any oscillation.

What's intriguing me the most is that if I connect MISO and MOSI I receive the sent data, but I cannot see any variation on these pins. Any idea what's happening here?

Here's my device tree:

/dts-v1/; /plugin/;

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

/* identification */
part-number = "spi0pinmux";

fragment@0 {
    target = <&am33xx_pinmux>;
    __overlay__ {
        spi0_pins_s0: spi0_pins_s0 {
            pinctrl-single,pins = <
              0x150 0x13  /* spi0_sclk, OUTPUT_PULLUP | MODE3 */
              0x154 0x13  /* spi0_d0, INPUT_PULLUP | MODE3 */
              0x158 0x33  /* spi0_d1, OUTPUT_PULLUP | MODE3 */
              0x15c 0x13  /* spi0_cs0, OUTPUT_PULLUP | MODE3 */

fragment@1 {
    target = <&spi0>;
    __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;

         status = "okay";
         pinctrl-names = "default";
         pinctrl-0 = <&spi0_pins_s0>;

         spidev@0 {
             spi-max-frequency = <24000000>;
             reg = <0>;
             compatible = "linux,spidev";


I am not quite sure about the definition of the OUTPUT_PULLUP and INPUT_PULLUP, I tried to follow the tutorial above the maximum possible. You can see the Beagle bone registers by searching for "Beagle bone registers" on google.

Thanks for your help,

  • 1
    \$\begingroup\$ problem statement in the title doesn't match the body. Are you getting FF's or 00's? \$\endgroup\$ – brhans Aug 30 '18 at 19:18
  • \$\begingroup\$ Sorry for the mistake. Yes, I receive only FF. Although I think that it's not the main issue since if I disconnect the sensor I continue receiving FF's (which means either the sensor is not sending data, or I am not processing it on the beaglebone's side. What's intriguing is that if I connect the MISO with MOSI I receive the sent data, which made me think that the SPI is working ... \$\endgroup\$ – Fred Gomes Aug 30 '18 at 19:20
  • \$\begingroup\$ I read your title as Firefox (the browser). Make it 0xFF instead. \$\endgroup\$ – Transistor Aug 30 '18 at 19:29
  • \$\begingroup\$ Are you using full duplex or half duplex? \$\endgroup\$ – Annie Aug 30 '18 at 19:29
  • \$\begingroup\$ I think SPI communication is full duplex. A send a byte and receive another one (bit by bit). For example, using Arduino I would do: int data = SPI.transfer("any byte"); and I would receive another byte in the MISO pin, the same in python. I am using this library in c++ exploringbeaglebone.com/API and it internally uses the spidev from Linux (which supposedly implements the SPI protocol) \$\endgroup\$ – Fred Gomes Aug 30 '18 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.