Use multiple SPIs on RPI (Raspberry Pi) 4B?

9 views (last 30 days)
Arish Yaseen
Arish Yaseen on 14 Apr 2022
Commented: Arish Yaseen on 14 Apr 2022
I am using a RPI 4B board to connect and use multiple SPI devices simultaneously. The RPI 4B board provides upto 6 SPI connections.
My question is that is it possible to switch between SPIs (for eg select SPI1, SPI2...) using MATLAB® Support Package for Raspberry Pi™?
I have already installed the "mathworks_raspbian_R21.1.0" image on the RPI and successfully booted the device. I am also able to connect to the device on the IP address. However, it only shows two CE {CE0, CE1} which I assume are only for SPI0 and there is no option to select SPI1 or others.
P.S. When connected to my RPI, the boardname is detected as "Raspberry Pi 2 Model B" instead of "Raspberry Pi 4 Model B", which I also don't understand why?

Answers (1)

Sylvain
Sylvain on 14 Apr 2022
Edited: Sylvain on 14 Apr 2022
Hi Arish,
I faced the same issue and found that the Raspberry Pi is limited with GPIOs. Hence I am using microcontrollers to handle the SPI buses and bridge back to the Rpi using i2c. This works like a charm but require you to program microcontrollers.
An alternative would be to use the GPIO as CS lines, but you won't have a lot of them available. You could use a multiplexer for the SPI0 and SPI1 using an i2c intergrated circuit.
I learned the hard way the limitation of the RPi, PWM frequency capped to 8 kHz, only few GPIOs, and timing might be an issue (models running below 0.1s time step require some care).
No idea about why Rpi 4 is detected as Rpi 2, I just figured out I have the same issue:
  1 Comment
Arish Yaseen
Arish Yaseen on 14 Apr 2022
Hey Sylvain,
Thanks alot for the response.
I understand the logic behind your approach but if we have atleast 4 SPI lines available at the same time of the RPI 4 board, it would have been easier to just switch between them rather than using a single line and an additional multiplexer.
My question is how can we select our RPI to communicate on SPI1 or SPIx rather than SPI0 (which is by default)?

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!