Setting SPI configs [RPI3B]

Hi,

i'm currently trying to use use the DWS3000 via SPI on my raspberry pi 3B with the latest openwrt snapshot.

I installed the follwoing packets:

$ opkg list-installed *spi*
kmod-spi-bcm2835 - 5.4.124-1
kmod-spi-bitbang - 5.4.124-1
kmod-spi-dev - 5.4.124-1
kmod-spi-gpio - 5.4.124-1
spi-tools - 0.8.6-1
spidev-test - 5.4.124-5.4.124

and edit the boot config

$ cat /boot/config.txt 
[...]
# OpenWrt config
include distroconfig.txt

[all]
# Place your custom settings here.
dtparam=i2c1=on
dtparam=spi=on
dtparam=i2s=on

I am able to see them in the device tree and their current settings

$ ll /dev/spi*
crw-------    1 root     root      153,   0 Jul 28 08:57 /dev/spidev0.0
crw-------    1 root     root      153,   1 Jul 28 08:57 /dev/spidev0.1

$ spi-config -d /dev/spidev0.0 -q
/dev/spidev0.0: mode=0, lsb=0, bits=8, speed=125000000, spiready=0
$ spi-config -d /dev/spidev0.1 -q
/dev/spidev0.1: mode=0, lsb=0, bits=8, speed=125000000, spiready=0

I also did a loopback test and connected MOSI and MISO pins.

$ ./spidev_test -D /dev/spidev0.0 -s 450000
spi mode: 4
bits per word: 8
max speed: 450000 Hz (450 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

But what does not work is to set the config of SPI devices. I am only able to set the mode but not the speed.

$spi-config -d /dev/spidev0.0 -q
/dev/spidev0.0: mode=0, lsb=0, bits=8, speed=125000000, spiready=0
$ spi-config -d /dev/spidev0.0 -s 450000 -m 3
$ spi-config -d /dev/spidev0.0 -q
/dev/spidev0.0: mode=3, lsb=0, bits=8, speed=125000000, spiready=0

I'm new to SPI. Am I doing something wrong here ?

I also read about kmod-spi-gpio-custom but couldn't install it, because the package isn't in the default repository and I thought that I can change the other parameter via spi-config if I use the default GPIO pins.

Thanks for your help! :slight_smile:

1 Like

I found my error in this README.

My SPI resets the speed after the file descripter is closed.
While it is open it, works as excepted.

root@openwrt:~# spi-config -d /dev/spidev0.0 -q
/dev/spidev0.0: mode=0, lsb=0, bits=8, speed=125000000, spiready=0

root@openwrt:~# spi-config -d /dev/spidev0.0 -s 450000 -m 0 -w&
root@openwrt:~# spi-config -d /dev/spidev0.0 -q
/dev/spidev0.0: mode=0, lsb=0, bits=8, speed=450000, spiready=0

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.