cancel
Showing results for 
Search instead for 
Did you mean: 

The problem in semaphore or mutex usage

Param sivan
Associate II

Hi,

STM32f429II

In my project , I have connected three number of peripherals in a single SPI line.

1) Audio driver

2) SD card

3) EEPROM

Also I am using these functionalities in different task by using semaphore. In tasks, I had checked the SPI availability before going to use. For rapid touch operation, it produces the touch sound by writes the value to audio driver and save the changes into the EEPROM. But some time these operation will be confilted and audio chip goes to infinite mute condition.

Which is the best method to use a single resource in different tasks? Is there any example?

Thanks in advance.

Code :

SemaSPI3 = xSemaphoreCreateMutex();
 
 
 
uint8_t SetSPIBusy (void)
 
{  
 
 if(xSemaphoreTake(SemaSPI3, (TickType_t)100) == pdTRUE)
 
 {
 
  SPIBusy = TRUE;
 
  return TRUE;
 
 }
 
 else
 
 {
 
  return FALSE;
 
 }
 
   
 
}
 
 
 
void ClearSPIBusy (void)
 
{
 
 SPIBusy = FALSE;
 
  xSemaphoreGive(SemaSPI3);
 
}
 
 
 
//************************************* In task 
 
 if(SetSPIBusy();)
 
 {   
 
  HAL_GPIO_WritePin(Audio_CS_GPIO_Port, Audio_CS_Pin, GPIO_PIN_RESET);
 
   
 
  status = HAL_SPI_Transmit(&hspi3,(uint8_t*)pTxData,Size,Timeout);  // trasmit the data to driver
 
   
 
  HAL_GPIO_WritePin(Audio_CS_GPIO_Port, Audio_CS_Pin, GPIO_PIN_SET); 
 
   
 
  ClearSPIBusy(); 
 
 }  

Thanks,

Param.

0 REPLIES 0