SPI API in case of multiple slaves

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

SPI API in case of multiple slaves

Post by russian »

With the whole "chip select" pin idea it seems like having multiple devices on the same bus is a big part of the SPI idea.

What I am having trouble with is finding an elegant way of using current SPI api in a configuration with two devices, say with different speeds. With current API, I would need to startSpi with one configuration, then stop it completely before using another device, re-start it with the new config, stop it again and so on. I guess in real life this happens relatively fast and there is nothing to worry about, but I wonder if we are missing an "spiConfigure" method?

This way "SPIConfig" should NOT be a parameter of "spiStart" - spiStart would only execute the general initialization (DMA etc) while only before using SPI in a particular device I would configure it and later re-configure for another device without stopping it completely.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI API in case of multiple slaves

Post by Giovanni »

Hi,

You don't need to call spiStop(), just call spiStart() again with a different configuration, spiStart() is exactly your spiConfigure().

Giovanni
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: SPI API in case of multiple slaves

Post by russian »

Giovanni wrote:Hi,

You don't need to call spiStop(), just call spiStart() again with a different configuration, spiStart() is exactly your spiConfigure().

Giovanni

Thank you Giovenni!

I have honestly tried to read the state check in the implementations but apparently I have failed to understand the logic.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI API in case of multiple slaves

Post by Giovanni »

You have to look at the driver state machine diagram.

Image

Giovanni
Post Reply