Hello , I’m new here and I’m sorry if what i’m gonna ask for is trivial
is just that i’m still an amateur .
I need to make an SPI semaphore for Arduino Mega microcontroller using freeRTOS library , there are two tasks that are using SPI communication at the same time and i need to prevent that.
Please help me for creating this type of semaphore to using it inside my tasks.
Thanks
Sounds like all you need to do is create a semaphore (or maybe better a mutex) and use it to protect your accesses to the SPI library, i.e. before calling the library, take the semaphore/mutex and when done release it.
I’m sorry can you give me an example through some code,.
I’m not used to this type of programming.
Basic outline.
As a global variable have a mutex handle
SemaphoreHandle_t spiMutex;
In Main, before starting FreeRTOS, create the mutex
spiMutex = xSemaphoreCreateMutex();
when ever you want to do a SPI operation
if(xSemaphoreTake(spiMutex, portMAX_DELAY) {
// in here you can do your spa transaction using whatever calls you need
xSemaphoreGive(spiMutex);
}
I’m very thankful to you