Page 1 of 1

SPI API in case of multiple slaves

Posted: Thu Oct 24, 2013 2:38 am
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.

Re: SPI API in case of multiple slaves

Posted: Thu Oct 24, 2013 8:20 am
by Giovanni
Hi,

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

Giovanni

Re: SPI API in case of multiple slaves

Posted: Thu Oct 24, 2013 12:09 pm
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.

Re: SPI API in case of multiple slaves

Posted: Thu Oct 24, 2013 12:23 pm
by Giovanni
You have to look at the driver state machine diagram.

Image

Giovanni