How to synchronise multiple SPI interupts

Rrobinet
Posts: 29
Joined: Wed Aug 16, 2017 7:05 am

How to synchronise multiple SPI interupts

Postby Rrobinet » Wed Nov 21, 2018 4:15 pm

Hi,

I read a lot of discussions about SPI interrupts (or ESP32 external interrupts in general), and I wonder if there are guide lines to use multiple sensors with SPI interface working with interrupts.
Practically I use the RFM69 transceiver which generates an interrupts when a RF frame is received. With the current (official) library SPI transfer handling is done in the Interrupt routine itself, which is causing a variety of crashes.
As I understand the OS is also using SPI to access the Memory.
So I did rework this library as the RMF69X (see github) by limiting the SPI interrupt to the setting of a flag and handle the SPI transfer as a normal routine, which looks to be OK (but I didn't really made some extensive tests).
Some people using it claims that in some cases there is a clash with the memory access.
So I am looking for a flag such a "SPI has interrupt" or "SPI has transaction" variables (like ones of the Arduino library), or any form of synchronization method between several asynchronous SPI access and the one used by the OS, to improve the RFM69X library.
Any ideas or explanations are welcome
Thanks in advance
Robert

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: How to synchronise multiple SPI interupts

Postby ESP_Sprite » Thu Nov 22, 2018 2:21 am

The way to do this is to use the features of FreeRTOS. Create a semaphore and a separate thread for SPI handling. In the thread, wait for the semaphore to be set. In the interrupt, set the semaphore. The RTOS will make sure your thread is not ran when it doesn't need to be.

Wrt spi-to-access-memory: The ESP32 has 4 SPI peripherals. The first two are used for memory accesses, and as such unavailable to the SPI driver. This means that when you use the SPI driver, you don't need to worry about interfering with memory accesses.

Rrobinet
Posts: 29
Joined: Wed Aug 16, 2017 7:05 am

Re: How to synchronise multiple SPI interupts

Postby Rrobinet » Sat Nov 24, 2018 9:58 am

Thank-you for your answer.
I don't plan to dig into the FreeRTOS code which e is above my capacities. However I think I understand the way I will be able to implement the semaphore technique that you have mentioned.
Robert

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 264 guests