SPI

  • Operation confirmed with our
    • ODROID-XU4 on 4.14.40 kernel.
    • ODROID-C1+ on 3.10.107 kernel.
    • ODROID-C2 on 3.14.79 kernel.
    • ODROID-N2 on 4.9.141 kernel.

This guide lets you know that how to make the SPI feature ready and that how to test the SPI feature including loopback test.

The SPI feature can be simply enabled by loading a module.

ODROID-XU4

Load the modules with the following commands.

root@odroid:~# modprobe spidev
root@odroid:~# modprobe spi_s3c64xx

And you can check if the module loaded.

root@odroid:~# lsmod | grep spi
spidev                 20480  0
spi_s3c64xx            20480  0

And the device file /dev/spidev1.0 has been created as well.

root@odroid:~# ls /dev/spidev*
/dev/spidev1.0

ODROID-C1+

Load the modules with the following commands.

root@odroid:~# modprobe spidev
root@odroid:~# modprobe spicc

And you can check if the module loaded.

root@odroid:~# lsmod | grep spi
spicc                   8279  0
spidev                  5442  0

And the device file /dev/spidev0.0 has been created as well.

root@odroid:~# ls /dev/spidev*
/dev/spidev0.0

ODROID-C2

Load the modules with the following commands.

root@odroid64:~# modprobe spidev
root@odroid64:~# modprobe spi_gpio
root@odroid64:~# modprobe spi_bitbang

And you can check if the module loaded.

root@odroid64:~# lsmod | grep spi
spi_gpio                6778  0
spi_bitbang             4063  1 spi_gpio
spidev                  6475  0

And the device file /dev/spidev0.0 has been created as well.

root@odroid64:~# ls /dev/spidev*
/dev/spidev0.0

ODROID-N2

Enable the modules using device-tree-compiler.

root@odroid:~# apt install device-tree-compiler

Change the status to okay of the SPI nodes on the device tree.

# SPICC0
root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/spi@13000 status okay
 
# SPIDEV0
root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/spi@13000/spidev@0 status okay

Check if it changed.

# SPICC0
root@odroid:~# fdtget /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/spi@13000 status
okay
 
# SPIDEV0
root@odroid:~# fdtget /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/spi@13000/spidev@0 status
okay

Then reboot to apply the changes.

Then you can check if the modules loaded.

root@odroid:~# lsmod | grep spi
spidev                 20480  0
spi_meson_spicc        20480  0

Check the /dev/spidev0.0 file out as the below.

root@odroid:~# ls /dev/spidev*
/dev/spidev0.0
  • You can use the wild card character(*) when you select spidev file, but be careful with using that due to the unexpected situation on your board.
  • This guide uses the wild card to give you the unified simple instruction for those 3 boards.

Preparation

Download a source code and compile.

root@odroid:~# wget http://dn.odroid.com/Accessory/examples/spidev_test.c
root@odroid:~# gcc -o spidev_test spidev_test.c

The help of the test utility.

# There's no option to show the help on this file.
# It shows if you enter this command with invalid arguments.
# So the '--help' option will show the help.
root@odroid:~# ./spidev_test --help
./spidev_test: unrecognized option '--help'
Usage: ./spidev_test [-DsbdlHOLC3]
  -D --device   device to use (default /dev/spidev1.1)
  -s --speed    max speed (Hz)
  -d --delay    delay (usec)
  -b --bpw      bits per word 
  -l --loop     loopback
  -H --cpha     clock phase
  -O --cpol     clock polarity
  -L --lsb      least significant bit first
  -C --cs-high  chip select active high
  -3 --3wire    SI/SO signals shared

Loopback test

Even though you haven't any SPI hardware device, you can test if the SPI feature works with a jump cable.

Before testing, make sure that a jump cable is connected between SPI MOSI and MISO pin directly.

  • XU4: Connect between pin #7 and #9 at CON10 pin header.
  • XU4 with Shifter Shield/C1+/C2: Connect between pin #19 and #21

Please refer to each wiki page about expansion connectors.

Run to test.
The spidev number is different by which board you use.

  • XU4: /dev/spidev1.0
  • C1+/C2: /dev/spidev0.0
  • N2: /dev/spidev0.0
# XU4
root@odroid:~# ./spidev_test -D /dev/spidev1.0
 
# C1+
root@odroid:~# ./spidev_test -D /dev/spidev0.0
 
# C2
root@odroid64:~# ./spidev_test -D /dev/spidev0.0
 
# N2
root@odroid:~# ./spidev_test -D /dev/spidev0.0

These results should be the same.

root@odroid:~# ./spidev_test -D /dev/spidev*
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
 
01 02 03 04 


If the module isn't loaded and/or spidev file isn't created, it results like the below.

root@odroid:~# ./spidev_test -D /dev/spidev*
can't open device: No such file or directory
Aborted

If the jump cable isn't connected well, it results like the below.

root@odroid:~# ./spidev_test -D /dev/spidev*
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
 
FF FF FF FF 

Various tests

Bits per word

8 bits

1MHz max speed and 8 bits per word.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 8
spi mode: 0
bits per word: 8
max speed: 1000000 Hz (1000 KHz)

SPIDEV-8bits-1Mhz

16 bits

1MHz max speed and 16 bits per word.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 16
spi mode: 0
bits per word: 16
max speed: 1000000 Hz (1000 KHz)

SPIDEV-16bits-1Mhz

32 bits

1MHz max speed and 32 bits per word.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 32
spi mode: 0
bits per word: 32
max speed: 1000000 Hz (1000 KHz)

SPIDEV-32bits-1Mhz

SPI mode

Mode 0

1MHz max speed, 32 bits per word and SPI mode 0.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 32
spi mode: 0
bits per word: 32
max speed: 1000000 Hz (1000 KHz)

SPIDEV-32bits-mode-0

Mode 1

1MHz max speed, 32 bits per word and SPI mode 1.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 32 -H
spi mode: 1
bits per word: 32
max speed: 1000000 Hz (1000 KHz)

SPIDEV-32bits-mode-1

Mode 2

1MHz max speed, 32 bits per word and SPI mode 2.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 32 -O
spi mode: 2
bits per word: 32
max speed: 1000000 Hz (1000 KHz)

SPIDEV-32bits-mode-2

Mode 3

1MHz max speed, 32 bits per word and SPI mode 3.

root@odroid:~# ./spidev_test -D /dev/spidev* -s 1000000 -b 32 -H -O
spi mode: 3
bits per word: 32
max speed: 1000000 Hz (1000 KHz)

SPIDEV-32bits-mode-3

2018/05/21 16:56 · joshua