How to use two SPI busses with CB1 on Manta M8P

Hi all around,

I’m in need to use two SPI busses since I want do use ADXL345 and ADS1220 on one toolhead.

Since it is not valid to place an adxl345 directly on the same SPI bus as other devices I want to wire two independent SPI busses to the CB1 on my Manta M8P.

According to the GPIO pinout of the CB1 there is only The SPI1 Bus wired to the 40-pins, which i currently use for the ADXL. I’ve configured it as follows:

[adxl345]
axes_map: x,y,z
cs_pin: cb1:gpio200
spi_bus: spidev1.1

I’ve seen that pins sometimes can have alternate functions, so is it possible to use other pins for that purpose?

And if it is possible, how to configure them properly?

Beside that, I’ve seen the Manta M8P provides a seperate 8-pin connector called SPI. Since I did not manage to get that working with the ADXL and then headed over to the 40-pin-gpio, I’m unsure if i can use that … and same question as above:
How to configure that properly?

Edit:

I’m using Armbian on my CB1:

OS: Armbian (24.8.1) aarch64 
Host: BigTreeTech CB1 
Kernel: 6.6.44-current-sunxi64 
Uptime: 3 mins 
Packages: 523 (dpkg) 
Shell: bash 5.2.15 
Terminal: /dev/pts/2 
CPU: (4) @ 1.512GHz 
Memory: 163MiB / 918MiB

and edited the overlays in /boot/armbianEnv.txt to:

overlays=spidev1_1 spidev1_2

An ls /dev/spi* gives me now:

/dev/spidev1.1	/dev/spidev1.2

So I’m hopeful to get the 8-pin connector on the M8P working - further investigation is needed to make it come true…

That’s not quite accurate. Kevin indicated that you should read the ADXL345 documentation to avoid and if you look there you’ll see:

Regardless, you’re not indicating what main controller board you’re using and what is wired to it - there may be some opportunities there, especially with the EXP1/EXP2 connectors (if you don’t have anything attached to them) for connecting one of the devices - I have attached an ADXL345 to the SPI pins on EXP2 and run from there.

2 Likes

Hi mykepredko,

thank you for your reply and for the clarification. That is a quite valuable information if it ever comes to design an actual PCB for my toolhead. So far I’m just juggling with the Chinese breakout boards for ADXL and ADS and a flying wiring around my toolhead.

I think it might be better to follow the way of separation both devices at the moment, since i already had to make a bunch of consessions here and it seems to make the whole thing less wonky than having an OR-Gate tangling around. :slight_smile:

Or what was your Question aiming at?

I don’t use the EXP1/EXP2 for anything. But as far as i can figure out here the tft35 would use spidev1.1. Correct me if I’m wrong but that would be connected to EXP1/EXP2?

Anyway I’m already using spidev1.1 for connecting the ADXL via the GPIO, so it might not be a solution to connect there?

The EXP2 connector provides SPI CS, MISO, MOSI and SCK lines for whatever peripheral it’s attached to - this is really designed for a UC1701 based UI board but if you’re not using it, it is a separate SPI port that you can use.

You’ll have to dig into the M8P’s schematic and its MCU’s datasheet to see if it is a properly wired (for Klipper) SPI port but, at the very least, you have software SPI pins you can work with. BTT is uneven as to whether or not the MCU’s SPI1 or SPI2 pins, that are defaulted to by Klipper, are used.

I agree that, at this point, you should separate your SPI devices and use separate SPI ports/pins for each device but it would be helpful for you to list out what are the devices you want to use and what ports you feel you have available.

1 Like

Hm,

according to this document:
BIGTREETECH MANTA M8P V1.1-SCH.pdf (3.2 MB)

The EXP2s SPI is connected to pins 50-53 of the STM32G0B1VET6 and it seems they are meant for an SD-card reader:

50 PB11/SPI2_MOSI,TIM2_CH4, USART3_RX, I2C2_SDA,ADC_IN15
51 SPI2_NSS/FDCAN2_RX,ADC_IN16/PB12
52 SPI2_SCK,TIM1_CH1N, FDCAN2_TX,I2C2_SCL/PB13PIU13052
53 SPI2_MISO/TIM15_CH1, I2C2_SDA/PB14 PIU13053

That makes me think this refers in the end to /dev/spidev2.x but I really don’t know.

I also discovered the 8-pin connector called SPI (P6) being connected to:

30 PIU13030 PA5/SPI1_SCK/I2S1_CK,USART6_RX, USART3_TX,ADC12_IN5
31 PIU13031 PA6/SPI1_MISO/TIM3_CH1,TIM16_CH1,I2C2_SDA,I2C3_SDA/ADC_IN6
32 PIU13032 PA7/SPI1_MOSI/TIM3_CH2,I2C2_SCL,I2C3_SCL/ADC_IN7
33 PIU13033 PC4/USART3_TX, USART1_TX, TIM2_CH1_ETR, FDCAN1_RX/ADC_IN17

This SPI bus seems to be connected to the stepper drivers also, so I think, it is not a good idea to wire the ADXL here due to its behavior with other devices. But the ADS1220 might be possible?

At the moment the ADXL is NOT connected to the STM32, but connected to the 40-pin-GPIO connector of the CB1

19 PH7 	GPIO231, SPI1_MOSI
21 PH8 	GPIO232, SPI1_MISO
23 PH6 	GPIO230, SPI1_CLK 
26 PG8 	GPIO200, CS

I have it up and running there. So, according to ‘never touch a running system’ I’d keep it there. It is running on the seperate MCU

[mcu cb1]
serial: /tmp/klipper_host_mcu

so it is out of reach of other SPI devices.

Uw, this is a strange thing to me … connecting a wire to software sounds a bit like science-fiction. But I assume I can tell the software to accept hardware pins intended for other purposes to act as SPI bus pins?

Well this is the point to reveal that I’m not an educated electronics technician nor software progamer. So I have to admit, the above dug out Information doesn’t help me any further.

  • Steppers (X,Y,Z*3,E)
  • Fans (coldend, partcooling*2, MCU)
  • heaters (hotend, bed)
  • temperature sensors (hotend, bed, MCU, chamber)
  • LED Stripe (maybe a second one to visualise the state of the machine as a kind of traffic Light, later on)
  • ADXL345 for resonance metering
  • ADS1220 for Z-endstop via strain gauges/load-cells

Clean and compact. No display / touch screen. No CAN bus / I2C Bus. Only control element should be an ‘emergency stop button’ I didn’t manage to implement from first day. :sunglasses:

Edit:

At the moment I’m convinced the EXP2 connector proposed by mykepredko seems to be the best choice…

…question is, how to implement it? How to figure out which micro-controller bus name has to be configured?

Sadly the Klipper configuration reference isn’t helpful on this topic:

#spi_speed:
#   The SPI speed (in hz) to use when communicating with the device.
#   The default depends on the type of device.
#spi_bus:
#   If the micro-controller supports multiple SPI busses then one may
#   specify the micro-controller bus name here. The default depends on
#   the type of micro-controller.
#spi_software_sclk_pin:
#spi_software_mosi_pin:
#spi_software_miso_pin:
#   Specify the above parameters to use "software based SPI". This
#   mode does not require micro-controller hardware support (typically
#   any general purpose pins may be used). The default is to not use
#   "software spi".

Lots to go through here.

Those pins are the defaults for the SPI2 hardware port. In your printer.cfg you would be able to just specify SPI2.

Looking at the schematic (Manta M8P V1.1), these pins ONLY go to EXP2 - they do not go to the “MCU-CARD” (that’s the SPI1 pins discussed below).

That’s using on the 40pin rPi connector.

That is the default for SPI1

What are the stepper drivers that you’re using. If you’re not using the TMC2130/TMC2160 (ie TMC2208 or TMC2209) then you’re fine.

No worries, I’d agree with that.

It’s called “bit-banging” and a) very well understood and b) well implemented in Klipper.

But, what it appears to me is that you won’t need to use it.

Not what I was asking for - what I was asking about was the SPI devices you want to attach and which ones you want to use.

So, from what I understand, you have three SPI ports available:

  • SPI1 which is the 8 pin connector on the M8P AND used for the motor connectors AND the SD Card socket (as noted above)
  • SPI2 which is coming through the EXP2 connector
  • rPi SPI /dev/spidev1.1 SPI port (which has your ADXL345 already on it)

That leaves the two SPI ports on the M8P for your use. If you are using SPI1 in any way (communicating with SPI TMC Stepper Drivers or using an SD Card for firmware updates) then I’d recommend staying away from it.

Now, above, you mention something about a TFT3.5 which uses an SPI interface -is this still an option?

As noted above, it’s simply SPI2

spi_bus: spi2

I agree that the Klipper reference isn’t really helpful - I suspect that it has to do with the fact that main controller board designers are pretty willy-nilly when it comes to how SPI ports and pins are wired. However, it doesn’t look like the Manta M8P designer wasn’t too bad in selecting the SPI pins.

So, I think we’re in agreement that the SPI2 port would be best to wire the ADS1220.

2 Likes

@mykepredko Thanks a lot!

I use the TMC2209

ok, so

would have been sufficient, right?

better having three and two needed than vice versa.
:sunglasses:

So I’ll heat up my soldering iron and start rewiring my printhead.
:upside_down_face:

I’ve to redesign the cable carrier and widen the cable bushing, since i want to change one ribbon cable for the ADXL with two round, shielded cables for ADXL and ADS to improve signal quality - maybe i use a third one for the fans to reduce interferences from PWM there. The stepper of the feeder has one already.

So please be a little patient with me. It’ll take a few days, before I come up with the finished message, but I’ll definitely do.
:innocent:

And again: Thank you for your help!

Edit:

I assume i can remove /dev/spidev1.2 from

All good except:

Why do you feel a ribbon cable isn’t good enough and what kind of cables are you using?

I’m asking this because unless you know exactly what you are doing, you’re not going to improve signal quality and there’s a good chance you’ll make it worse.

Start with a ribbon cable, they’re fairly small and easy to work with. Make sure you have a single ground and power supply going to your boards with no way that they will be connected/shorted together. Don’t do extra work until you know you have a problem.

If you have any questions, please ask.

No problem, I’m interested in seeing what you produce.

1 Like

On the one hand that results out of the discussion here (There you also can see some pictures, what I’m breeding here).

On the other hand that will result in a much stiffer cable whip, not hanging loose. I already had cable breakage because of bending the cable whip in another printer. Since I replaced the ribbon cables with round cables, the movement of the cable whip looks much smoother with wider radii and better distributed torsion along the whole length.

To be honest, the latter issue is more important to me and the first came up as a by-product just using shielded cables after the decision for round cable was already made.

I decided to use two cable types:

  • for SPI bus: Cat5e 4 pair AWG 26 (flexible)
  • for Stepper and Fans: LIYCY TP 2 x 2 x 0.25 mm² (flexible)

I have that. You think about inductive coils? And yes, the cable shields get connected to Protective Earth (PE) - on one side only.
:wink:

I’ve planned the cabling for my printhead a bit more in detail. For anybody interested i show it here (heater and thermal sensor not shown).

overview.pdf (384.9 KB)

@mykepredko I’d like to ask you to have a look, just to make sure I haven’t made a major mistake. Thanks in advance.

That is what I was expecting from what you said above.

From the schematic perspective, the wiring is fine. Power looks good.

Previously you wrote,

and while I did question your use of this, I should have been more explicit to say that by using twisted pair cable in this way, you’re going to get poorer signal quality than from a straight ribbon cable (or even just loose wires).

The issue is that by twisting signal lines together like this, you’re going to increase crosstalk between them. Normally when people use twisted pair, they put a ground line with each signal line which provides better signal integrity - IF THEY DO IT PROPERLY - Doing this would defeat the physical/mechanical advantages that you’re looking for in this case.

I just did a bit of research on this and the rule of thumb is that this is okay for up to 400kHz for a 0.5m length.

That feels a bit too conservative for me - for what you’re doing if you don’t exceed 2m cable lengths and data rates are less than 500kHz then things should be okay. That doesn’t mean that if you were to look at the signals at the ADS1220 or the ADXL345 boards you’ll have nice crisp edges and you will see the influence of the other line on the signal you’re observing.

To summarize, the basic approach is okay but I wouldn’t recommend wiring SPI signals this way. It should work but if there is a problem you can rewire it as you will not have damaged any of the circuitry in the printer.

I’m looking forward to hearing how things work out for you.

1 Like

Yes, that is why I put MOSI and MISO in different pairs. Might it be cleaner to put them together with 3V3 and DREADY and having CLK and CS together in the third pair? I’d like to keep 5V and GND together in one pair then, since this should become the reference-voltage for the bridge.

So, as usual, I’m close to the limit again:
I have 2m and the ADS will have spi_speed: 512000.

I’m quite happy if it becomes reliable to a sufficient degree.

Im very hopefull on this topic. :sunglasses:

I’ll keep you informed…

For the ADXL345, this would be okay. I’m not sure about the ADS1220 - if you’re looking for the cleanest power possible then keep +5V, +3V3 and GND away from lines that are wiggling.

Good luck!

1 Like

Just to show the new accommodation of the ADXL. This Part is the modified cable support on the printhead side and also holds the X-Endstop:


p.s.

I know this group is software related, and showing printer parts and building progress is not scope here. So, I won’t have a problem to stop that, just let me know.

2 Likes

Looks good.

I think of this group as devoted to 3D printers with a focus on Klipper. If you have something you’ve done that you’re proud of or may help somebody in the future, by all means post it here as you’ve done.

3 Likes

Okay then, here you are.

This is the lower part of the printhead chassis. I integrated four strain gauges and embedded them in the plastic to build load cells.


They are soldered to build a wheatstone bridge (hopefully I made it correct, the wires are thin as hairs).
I covered everything with an ABS-Acetone-solution for protection and avoidance of unwanted movement.

1 Like

Here you can see how both parts fit together, building the chassis of my printhead:

So, just soldered the bits together:

Glued the PCB now and decided to drown all those copperhairs in ABS-Acetone-solution. If this attempt fails everything goes to the waste bin anyway.

Now i’ll have to wait for everything to harden and cover the copperhairs from the backside also. That will take some time.

B.t.w.: If anybody plans to create a PCB regarding to this specific application: Just keep solder points for the bridge. By no means it is possible to use plug connectors here.

1 Like

18 posts were split to a new topic: Motor and controller issues

Seems to be case sensitive. Typing SPI2 throws:

Unknown spi_bus ‘SPI2’

Typing spi2 went trough.

As you might assume I was fiddling around with the machine today.

I redid the whole lighting…

…and cabling, combining together in one part for cable support and LED stripe.

But I can’t recommend this integration. I would happily split that again in a further edition, since it is a pain to get the LED Stripe and wiring for it in there (solderings are right in the middle of it).

On the other hand, I assembled the print head with the strain gauges inside.

Looks a little bit awful with all the wires. I like hidden wires.
The less I can see them, the better it becomes.

I managed to get everything up and running again, what was running before (Ah! E-stepper untested → tomorrow), including ADXL.

Bud did not manage to get the ADS runnig. Must be a wiring error, since the machine doesn’t start when i plug it in. But I’m not in the mood anymore → tomorrow also.

For testing that: Does there exist a testing command for ADCs like the ACCELEROMETER_QUERY for the ADXL? Just somethig to confirm it is found?

2 Likes