Electronic – About Microcontroller having many SPI controllers

serialspi

I would like to ask if anyone had an experience of using more than 1 SPI controller/channel on a project? I had this pyboard where it has up to 3 SPI controllers though i think only 2 SPI controllers can be used. This is different from the traditional multiple SPI slave scheme which is applied on 1 SPI controller only.

I had this setup where 1st SPI controller (SPI_1) will talk to a SPI-based relay hub and the 2nd SPI controller (SPI_2) will talk to multiple SPI-based sensors. Now my question is, can this two SPI controller operate simultaneously or at the time, SPI_1 will turn on & off relay(s) while SPI_2 will read sensor values. These two generate serial clocks different from one another right? Can this be achieve? also how would this be applied on the programming side?

I had many experiences on SPI using arduino boards but i haven't yet try using two different SPI drivers at the same time since arduino boards does only have 1 SPI driver.

EDIT:

http://www.st.com/content/ccc/resource/technical/document/datasheet/ef/92/76/6d/bb/c2/4f/f7/DM00037051.pdf/files/DM00037051.pdf/jcr:content/translations/en.DM00037051.pdf is the microcontroller used by the pyboard v1.1.

https://docs.micropython.org/en/latest/pyboard/pyboard/quickref.html#general-board-control is the board i'm going to use.

Best Answer

You didn't mention a specific microcontroller but in general, yes: a microcontroller with more than one SPI controller can utilize the controllers simultaneously to the extent it is able.

Remember that many microcontrollers are single-core and can only execute a single instruction at any one time, but with DMA more parallelism can be achieved. For instance, you could instruct the DMA engine to shift out a large portion of data via one SPI controller and the immediately after initiate SPI communications on another SPI controller.

So while you will likely not be able to run the SPI controllers exactly simultaneously, for your needs they will be effectively simultaneous. If you have highly time-sensitive peripherals where SPI operations on multiple SPI busses must be coordinated at exactly the same instant, the an FPGA is typically used to implement multiple SPI controllers that are capable of operating entirely in parallel. But if you're writing a couple bytes to a relay controller on one buss and reading a few bytes from a sensor on a different buss, I assume you're OK if these transactions happen a few microseconds apart.