ADXL345 on software SPI

Hello!

I have a trouble with work adxl345 on software SPI.
config:

[adxl345]
cs_pin: rpi:gpio16
spi_software_sclk_pin: rpi:gpio21
spi_software_mosi_pin: rpi:gpio20
spi_software_miso_pin: rpi:gpio19

console:

13:34:43 $ ACCELEROMETER_QUERY
13:34:45 !! No accelerometer measurements found
13:34:49 // Klipper state: Shutdown

log:
klippy.log (1.9 MB)

SPI0 is busy by 3,5 inch TFT screen and touchscreen.
hw SPI1 cannot be used because get the error “klipper can not change SPI mode”

Raspberry 3B+, Raspbian Bullseye Legacy Lite 64bit
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux

Has anyone run the accelerometer on soft-spi or hard-spi1?

PS: the adxl345 is works fine on spi0 - I checked it.

About this triuble.

If change config to this

[adxl345]
cs_pin: rpi:None
spi_software_sclk_pin: rpi:gpio21
spi_software_mosi_pin: rpi:gpio20
spi_software_miso_pin: rpi:gpio19

and drive CS pin on ADXL345 on ground? software SPI will work!. But only once:
23:46:43 $ ACCELEROMETER_QUERY
23:46:44 // accelerometer values (x, y, z): 9102.532530, 5048.463420, -2371.247970
23:46:48 $ ACCELEROMETER_QUERY
23:46:48 !! Invalid adxl345 id (got 0 vs e5).

in order for the ADXL345 to give values every time, you need to disconnect the CS pin from the ground, and connect it to the ground again before next measuring …

Try adding following line to /boot/config.txt

dtoverlay=spi1-1cs

The corresponding pins should be:

GPIO20 (Pin Header 38) – MOSI
GPIO19 (Pin Header 35) – MISO
GPIO21 (Pin Header 40) – SCLK
GPIO18 (Pin Header 12) – CS

Additionally, setting the SPI via:

spi_bus: spidev1.0

CS pin I would leave at none:

cs_pin: rpi:None

Im trying to add to /boot/config.txt` different variants:

dtoverlay=spi1-1cs
and
dtoverlay=spi1-1cs,cs0_pin=16

in console ls /dev/ i see spivev1.0, config:

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

but klipper falls with error on the start.

MCU ‘rpi’ error during config: Unable to set SPI mode

LOG:
klippy.log (213.1 KB)

Have you tried:

[adxl345]
spi_bus: spidev1.0
cs_pin = rpi:None
spi_software_sclk_pin = rpi:gpio21
spi_software_mosi_pin = rpi:gpio20
spi_software_miso_pin = rpi:gpio19

can not specify soft_spi and hard_spi at the same time.
With this configuration I get an error:

Option ‘spi_bus’ is not valid in section ‘adxl345’

No more stupid ideas, sorry.

I am running across the same error. Have you found a solution? I am currently using a Pi 3B+ as well, running MainsailOS

I’d recommend a RPi Pico. Cheap and painless.
See Raspberry Pi Pico + ADXL345: Portable resonance measurement

Unfortunately there is no solution yet.
The only thing I was able to identify is the difference in the speed of the SPI:
hard SPI - 5MHz
soft SPI - 750kHz

When you say “SPI0 is busy by 3,5 inch TFT screen and touchscreen.”

This is not true, SPI is a multi device port. You can plug as many devices into it as you like, all you need is individual CS pins. And CS pin can be any pin you like. So you can plug your accelerometer into the same port as what the TFT uses, and just define a separate CS pin.

Also, why aren’t your connecting the accelerometer into your printers board? Why connect it into the raspberry pi?

Why are you defining CS pin as none in the first place? Why not just connect the CS pin? It needs it to start and end the communication, that’s why you would constantly need to ground it and disconnect it.
If this is a linux issue, i would again recommend connecting the accelerometer directly to the printers board, this way you avoid these issues. And can define the CS pin freely.

  1. the clipper cannot work with accelerometers that are connected to CS1/CS2/CS3. it’s writen in the documentation.
  2. I didn’t find any information how to use CS2 or CS3 on raspberry.

There is no free hardSPI on the printer board

I wrote about this problem in the second post. Link from it:

But if you are using software SPI, why would you need free hardware SPI? Also, there are usually 3 SPI ports on the board. So there are definitely free ports, not that you would even need free ports.

I personally use the same SPI as my memory chip on the board, i just soldered one of the leads to the
chips feet. So you can defiantly share an SPI port. All you need to do, is define the CS pin. CS pins are not defined in klipper to specific SPI ports. Exactly because its a multi device port, and has no fixed CS pins.

In this post you can see the screenshot of klippers pin definitions, it only defines MISO, MOSI & SCK for the SPI ports.

Here is another example, i wired it into my SKR 1.3 board also:

Just to drive this point home, you can use stepper motor drivers in SPI mode. Do you think every driver has its own SPI port? Nope, they are all connected to one SPI port. And you just define separate CS pins in the config.