Simplest way to set pin to activate on low on the host

Basic Information:

Printer Model: Frankenstein’s monster
MCU / Printerboard: Manta m8p / CB1
klippy.log (64.8 KB)

Describe your issue:
Ok, I have been going around in circles for some time now. I am just trying to set a GPIO pin to activate on low for the ADXL345.

All PINS in CB1 / manta that have that characteristic are already in use, so that is my best bet why I can’t make the accelerometer work. So I plugged it into the CB1 directly, connected to pin 26 of the CB1 GPIO200 and using spi1.2 bus, which is what I have left to use.

Now GPIO200 seems to be properly acquired by klipper:
line 200: unnamed "klipper" output active-high [used]

Problem is active-high, and adxl345 is active-low according to the data-sheet. Yes I got to read the entire data sheet to get here. So bad this thing is documented on CB1 side and SPI of manta m8p v1.1 simply doesn’t work and I suspect it’s because I have other stuff plugged to spi1 interface (namely tft35spi and something else). They take 1.0, 1.1, and now I am trying to use 1.2.

spi0 seems to have no pin available on CB1 and I don’t really know if there is one in manta board. Again, documentation not very good to clarify that.

I ended up trying to recompile klipper with setting gpio from menuconfig !GPIO200, but when I run make, it can’t find it. in printer.cfg I have no problems pointing to it:

[adxl345]
cs_pin: host: gpiochip0/gpio200
spi_bus: spidev1.2

So on the host (CB1) I want to make line200 to activate on low, to see if this finally fixes this problem. But got stuck there. Saw the python file to set inital pins, but maybe my brain is already liquified chasing this issue that I can’t seem to simply change this initial pin config.

Appreciate if anyone can share how I can do this in the simplest manner so I can spare what’s left of my brain.

Cheers!

Have you tried inverting the CS pin from Klipper?
Something like:

cs_pin: !host:gpiochip0/gpio200

Or is it a tri-states thing?

I actually tried that. Doesn’t seem to like the syntax when the host is specified. This is actually something I am curious about as well.

So I don’t really know if that would work

You’re right, CS can’t be inverted.
I’m not sure about your diagnostic, Klipper already pulls the CS pins low when addressing the adxl. So unless the GPIO port somehow invert the pin, it should work.

Maybe there is another issue? Signal quality is quite finicky on SPI bus, long wires are often an issue.

The pins are what they are. I checked them via gpioinfo command. They are customised for BTT CB1, all the rest is set as high as default, unless specified otherwise (can see that on klipper source code).

I already verified it works fine in an arduino uno. Both I2C and SPI modes. Took me less than half an hour to get it to work.

This m8p + CB1 was the biggest mistake I made. Can’t rely on well documented sources because it’s a custom image from BTT where things are not the way they are if it was a rpi. Which makes things a bit more tricky.

Through gpioinfo command I also see the other Spi on the bus correctly set as activated on low. And for some reason sharing the bus with other devices is quite finicky on this setup.

So, to validate my theory, all I need is to set one of the GPIO pins that are free to activate on low. Then it will be according to spec.

Fact that BTT simply ignore all the people having the same issue, doesn’t help. Their Github is more like a discourse managed by the community.