Reading over SPI with Beaglebone Black as Slave

Im trying to use the Beaglebone Black as a slave device and read from the arduino over SPI.

Im confused as to why I am just getting 255 repeated over and over on the terminal as an output.
My thought is that there is some kind of a memory leak or buffer overflow. I just can not figure out what
I’m doing wrong. Is one supposed to set cs as input? even with it set to output I have the same issue.

I have my dts file set as:


/ {
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 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 /
0x154 0x30 /
spi0_d0, INPUT_PULLUP | MODE0 /
0x158 0x10 /
spi0_d1, OUTPUT_PULLUP | MODE0 /
0x15c 0x30 /
spi0_cs0, INPUT_PULLUP | MODE0 */


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”;

My Arduino is wired up like so:

P9.22 SPI0_CLK - Orange - 0x150 0x30 → Arduino Due 110 SCLK
P9.21 SPI0_D0 - Green - 0x154 0x30 → Arduino Due 109 MOSI
P9.18 SPI0_D1 - White - 0x158 0x10 → 108 MISO
P9.17 SP0_CS0 - Black - 0x15C 0x30 —> Pin 10 Set as Slave Select

Python File:
import spidev
import time
spi = spidev.SpiDev(),0)
while True:
resp = spi.readbytes(1)
print resp[0]

I am running BBB SPI as slave but using the opposite direction for the data pins:

0x150 0x30 /* spi0_sclk.spi0_sclk, INPUT_PULLUP | MODE0 /
0x154 0x10 /
spi0_d0.spi0_d0, OUTPUT_PULLUP | MODE0 /
0x158 0x30 /
spi0_d1.spi0_d1, INPUT_PULLUP | MODE0 /
0x15c 0x30 /
spi0_cs0.spi0_cs0, INPUT_PULLUP | MODE0 */

I think your way can work fine too, it just requires setting up the right values in the SPI control registers.

But to make mine work as slave, I had to use mmap to directly access the SPI hardware registers. I can do that from user-space because the protocol I designed for my SPI hardware has no realtime requirements that would require interrupts. (The packets in both directions always fit in the FIFOs, and run in a half-duplex command/response mode.)

I don’t think any Linux SPI drivers support slave mode, and there is even an explanation available from Linus Torvalds if you search the web. If you need interrupts for more demanding performance, you will have to write your own driver.

Hello Guy,

I’m also trying to have BBB on a SPI bus as slave. Is it possible for you to share your code/protocol?


Any luck on this? I have the same issue.