Hi, I’m a rookie and this is my first question here.
When I want to add a device to an SPI bus, how do I instantiate the needed CS (SS) pin in Klipper! I’m too stupid to find the right document
I guess the wiring should be like this
My question is, how do I instantiate this in Klipper.
@ dockterj and Sineos
You are absolutely right, I was sloppy! I beg your pardon and thanks for your answers. I changed the topic title.
I read a little further in the WWW.
My question were…
Point 1: How to add several SPI slaves to one RPi SPI bus (especially the CS_pins)
Point 2: Adding several SPI buses to one RPi
Point 1: I found this, which makes sense to me:
(3 slaves on one spi_bus) add to /boot/config.txt (or /boot/firmware/config.txt in some distros):
dtoverlay=spi6-3cs,cs0_pin=16,cs1_pin=26,cs1_pin=6 (GPIO pins can be different)
or Be careful, lines must be shorter than 98-character line length limit (previously 78) characters. If a line becomes to long you can use the equivalent long form:
On the same SPI bus you need to differentiate the devices via an own CS pin. MISO, MOSI, SCLK are shared. The active SPI device is chosen by pulling the CS pin high. This is done automatically by Klipper.
Above is the case, e.g. when you share a MAX board on the same SPI bus as your stepper drivers.
On the RPi it is a bit different.
Depending on the RPi Model, the SPI buses work differently. Information covered in here is focused on RPi4
RPi’s before 4: Only 1 true SPI controller (SPI0) and two SPI mini (SPI1 / SPI2)
RPI 4: 5 SPI masters (SPI0, SPI3, SPI4, SPI5, SPI6) and two SPI mini (SPI1 / SPI2)
SPI2 is not on the 40 pin header
CS is automatically detected by the Kernel. Use cs_pin: rpi:None otherwise strange things will happen and your dog will get abducted by aliens
RPi has multiple SPI buses, so best thing is to assign each device on an own bus
Example:
config.txt:
dtparam=spi=off #turn off default SPI to use multiple buses
dtoverlay=spi5-1cs
dtoverlay=spi6-1cs
I never had the need to chain multiple SPI on a RPi. I always used dedicated buses. Not sure how the CS auto-detection will behave when you have multiple devices on one bus.
Be brave and try it. Feedback if and how it is working would be appreciated.
Sorry, this would have to be answered by a developer. Just my experience and I think some reports are somewhere here as well. My wild guess is that SPI1 is a “mini SPI” port and whatever this means, Klipper does not like it.
SPI1 is an auxiliary peripheral that’s referred to as mini SPI. According to the BCM2835 documentation, using higher clock speeds on SPI1 requires additional CPU time compared to SPI0, caused by smaller FIFOs and no DMA support. It doesn’t support Mode1 or Mode3.