2022-12-12 02:57 AM
Hi, I'm building a system where a STM32 MCU needs to be connected to 5 sensors in SPI.
The sensors are 5 chip MAX31856 or similar.
My doubt is, can I connect 5 sensors to a single SPI line of the MCU? Are there any limits on how many sensors can be connected on a single SPI line? I need some type of buffer? Is better use multiple SPI line of the MCU?
Thanks in advance.
2022-12-12 05:30 AM
There are quite a few chips that claim to be spi-compatible, but are compatible in different ways.
The simplest approach is if they all put their MISO = SDO pin high-impedance (also known as tri-state) when they are not selected i.e. their SSEL pin is high.
Then you can have a separate GPIO signal on your stm32 for each SSEL, and make sure that each of these GPIOs is high apart from the one you currently want to communicate with.
MAX31856 seems ok in this respect.
But the HAL libraries might assume that you can only use a specific pin for SSEL - not just any GPIO. If that's the case, tell HAL not to manage SSEL and do that manually before/after HAL calls.
Disclaimer: I do not like the stm32 HAL libraries.
I strongly recommend you read the appropriate section of the Reference Manual for your stm32.
2022-12-12 05:38 AM
Yes yes, I had already foreseen not being able to use the HAL libraries and to manually manage the CS pin before reading or writing on the SPI line.
My doubts are mainly from a hardware point of view, i.e. does the MCU, or rather the MCU MOSI and SCK pins, have enough strength to drive 5 devices?
2022-12-12 05:47 AM
If all chips handle chip select ok , count is unlimited...
In practice count make higher capacity on line and limit speed down. Too distance and pcb quality usw...
Then you need write question how many on for example 45MHz speed ... but five is ok.
2022-12-12 05:53 AM
In my application I can also go very slow, I have to transfer from each slave something like 24 bits every 2 or 3 seconds, so I can also use clocks in the order of kHz.
Just educationally, how do I know how much capacity I can connect to a pin of the MCU for a certain clock speed, without damaging the pin and to ensure the integrity of the signals?
Which datasheet parameter should I look for?
2022-12-12 05:55 AM
It is an analog question. What is the capacitance of each SPI bus line versus the max bitrate? Sensors can be far... 10 meters SPI at 24MHz probably won't even work with a single sensor.... So the answer would be that on the digital side, you can put as many sensors as you have separate NSS. Beware that drone makers get annoying bus glitches when using sensors that switch to I2C slave mode when their NSS is deselected....