Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
beaglebone-spidev-test

Loopback

/boot/uEnv.txt

uname_r=4.4.39-ti-r79
cmdline=coherent_pool=1M quiet cape_universal=enable
cape_enable=bone_capemgr.enable_partno=cape-universala

config-pin

for i in 17 18 19 20 21 22 28 29 30 31 42; 
do echo config-pin P9.$i spi;
done
config-pin P9.17 spi
config-pin P9.18 spi
config-pin P9.19 spi
config-pin P9.20 spi
config-pin P9.21 spi
config-pin P9.22 spi
config-pin P9.28 spi
config-pin P9.29 spi
config-pin P9.30 spi
config-pin P9.31 spi
config-pin P9.42 spi

spidev_test:

Source: https://raw.githubusercontent.com/torvalds/linux/master/tools/spi/spidev_test.c

debian@beaglebone:~/spi$ sudo ./spidev_test --device /dev/spidev1.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 
debian@beaglebone:~/spi$ sudo ./spidev_test --device /dev/spidev1.1
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 
debian@beaglebone:~/spi$ sudo ./spidev_test --device /dev/spidev2.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 
debian@beaglebone:~/spi$ sudo ./spidev_test --device /dev/spidev2.1
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 

Adafruit_BBIO SPI test

test-spi.py

from Adafruit_BBIO.SPI import SPI

# From Adafruit Learning System:
# https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/spi     
#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

spi = SPI(0,0) 
print spi.xfer2([32, 11, 110, 22, 220]) 
spi.close() 

output

debian@beaglebone:~/spi$ sudo python test-spi.py 
[32, 11, 110, 22, 220]

strace

debian@beaglebone:~/spi$ sudo strace -e open -f python ./test-spi.py 2>&1 |grep /dev/spidev
open("/dev/spidev1.0", O_RDWR|O_LARGEFILE) = 3
@Bradleyking4

This comment has been minimized.

Copy link

commented Apr 18, 2018

in the latest kernel 4.4.12

for i in 17 18 19 20 21 22 28 29 30 31 42;
do echo config-pin P9.$i spi;
done
no longer works.

for spidev1.0
config-pin P9.17 spi_cs
config-pin P9_18 spi
config-pin P9_21 spi
config-pin P9.22 spi_sclk

for spidev2.0
config-pin P9.31 spi_sclk
config-pin P9.28 spi_cs
config-pin P9.30 spi
config-pin P9.29 spi

@VarunPwr

This comment has been minimized.

Copy link

commented Oct 16, 2018

I tried the above steps but did not work in my case. Here is the log :
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
Could you help me?

@psarvesh

This comment has been minimized.

Copy link

commented Feb 22, 2019

@VarunPwr I think you might have solved this already. But if not, you can add the --verbose option to see the TX/RX buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.