ADXL345 Raspberry pi4 multi SPI

I finally had some luck getting two ADXL345’s detected at once on a single Raspi. A Raspberry Pi 4B to be specific.

The issues seems to be that SPI0 and SPI1 are “special” and also kind of dumb on the Raspi. SPI 0 & 1 use a separate (legacy I think) controller versus 2-6 which were added to the latter Pi’s. SPI 0 & 1 can be enabled at the same time, but SPI 1 doesn’t support the necessary signaling mode that Klipper needs, so it fails if you try to use it.

SPI 0 works, but enabling it is a trap. If SPI 0 is enabled, SPI’s 2-6 don’t work properly. I’d originally tried combinations of SPI 0 & 1 (fails) as well as 0 & 5 (fails differently). 5 uses the same pins as 1, so that was convenient (no rewiring), but 5 fails if 0 is enabled.

I finally hooked my two ADXL345’s to SPI 5 and 6, and that works! It seems Klipper has a problem finding those though, so I also needed some symlinks to pretend they’re really 0 and 1. So all in, I have:

config.txt:

dtparam=spi=off
dtoverlay=spi5-1cs
dtoverlay=spi6-1cs

printer.cfg:

[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345 hotend]
cs_pin: rpi:None
spi_bus: spidev0.0

[adxl345 bed]
cs_pin: rpi:None
spi_bus: spidev1.0

[resonance_tester]
accel_chip_x: adxl345 hotend
accel_chip_y: adxl345 bed

And I had to create symlinks in /dev (re-created each time by klipper’s init script) so I have:

pi@octopi:~$ ls -l /dev/spidev*
lrwxrwxrwx 1 root root     14 Sep 14 06:55 /dev/spidev0.0 -> /dev/spidev5.0
lrwxrwxrwx 1 root root     14 Sep 14 06:55 /dev/spidev1.0 -> /dev/spidev6.0
crw------- 1 root root 153, 0 Jul 20 07:39 /dev/spidev5.0
crw------- 1 root root 153, 1 Jul 20 07:39 /dev/spidev6.0

If I just put 5 & 6 directly in printer.cfg, startup of the raspberry mcu device fails. I’m printing at the moment unfortunately, so I can’t reproduce that error.

With the symlinks, all is happy. I can run resonance tests on either probe without rewiring or changing any configuration.

2 Likes