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.


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.

  • \$\begingroup\$ If your MCU has dedicated hardware-based SPI controllers capable of transmitting at least one byte on its own at a time, then you should be able to achieve reasonable concurrency in operations. If it is a bit-banging controller, then it should be also possible, to a degree, depending on the SPI speed. But it will take writing some "cooperative multitasking" driver for this. \$\endgroup\$ – Ale..chenski Feb 13 '18 at 2:09
  • \$\begingroup\$ ok, if it would and i relied on using 2 SPI controllers (2 masters w/ multiple slaves), what would that look like in pseudo-codes? should this be manage by creating a custom library to work it out? Indeed bit-banging would be good but this solution alone is applicable on using 1 SPI controller so applying 2 SPI controller will be redundant. Though i have this setup where i like to control 30 relays, hub on 3 SPI-based i/o expanders (10 relays per i/o expander), 30 SPI-based distance sensor hub on a 3 "3-8 dmx" (10 per dmx) and 30 SPI-based temp sensor hub on a 3 "3-8 dmx" (10 per dmx) also. \$\endgroup\$ – Mheruian Feb 13 '18 at 2:52
  • \$\begingroup\$ 30 relays will be on SPI_1 and 60 sensors on SPI_2, using two SPI controller is better that using 1 SPI controller and using bit-banging if this would be the setup right?? I'm talking about process time here. \$\endgroup\$ – Mheruian Feb 13 '18 at 2:53

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.

  • \$\begingroup\$ Thanks :D i had edited my question to include the links of the board i'm talking about as well its microcontroller. if using 2 SPI controllers at the same time / simultaneously is possible, how would that work out in the programming side? \$\endgroup\$ – Mheruian Feb 13 '18 at 2:57
  • 1
    \$\begingroup\$ @Mheruian. You need separate software for each SPI port. One might be reading data while the other is writing data. If using DMA to move data in burst, you will need a small bit of software to manage that. \$\endgroup\$ – Sparky256 Feb 13 '18 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.