Syncronous/Asyncronous SPI??

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
formica
Posts: 11
Joined: Thu May 31, 2012 12:46 am

Syncronous/Asyncronous SPI??

Post by formica »

Dear all,
I'm a little bit confused about the SPI API. Reading the documentation there are some function used for a syncronous communication and others for asyncronous one.
I know that that the SPI protocol has a dedicate clock line so it is intrinsically syncronous.
So, what does it means ASYNCRONOUS in this case?

I'm trying to establish a monodirectional communication between two microcontrollers (STM32F103RBT6) using spi. This is my idea: the first one (master) generates the clock while the second one (the slave) use this clock to read the data. The two MOSI pins should be connected together (the clock pins as well).
Is it correct?
Which api functions should I use in this case in both micro?

Thanks in advance
Roberto
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Syncronous/Asyncronous SPI??

Post by Giovanni »

Hi Roberto,

Synchronous/asynchronous is about the behavior of the SPI functions and does not affect the way the data is transferred, for example:

spiStartSend() - Asynchronous function, it starts a transmission and returns immediately, the transfer continues in background, a (optional) callback is invoked when the transfer is finished.

spiSend() - Synchronous function, it starts a transmission and returns when the operation has been completed, it waits inside.

Read that as blocking/non-blocking.

About the SPI driver, it is master-only, you need custom code on the slave side.

Giovanni
Raul
Posts: 43
Joined: Thu Aug 13, 2015 5:15 pm
Has thanked: 3 times
Been thanked: 1 time

Re: Syncronous/Asyncronous SPI??

Post by Raul »

Hi all,

If a thread calls spiSend(), presumably the wait for completion would make it transition into a sleeping state while the DMA transfer takes place, and if then it were another thread in a ready state will this one start executing?

If so, what would it happen when the DMA transfer is completed and the second thread is still executing, the SPI caller will be resumed once the second thread sleeps/stops?

Raul
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Syncronous/Asyncronous SPI??

Post by Giovanni »

Hi,

This is correct, in general drivers never do "busy waiting" and behave nicely with other threads. The exception is when you see a function with "Polled" inside, those are meant to do polling, for example gptPolledDelay().

Giovanni
Post Reply