AnsweredAssumed Answered

Timer Interrupt for UART communication

Question asked by pwdusid on Jul 7, 2015
Latest reply on Jul 7, 2015 by pwdusid
Hello, 

I want STM32 with GSM board each sec communicate.
in Main.c
int main(void)
{
    HAL_Init ();
    SystemClock_Config ();   
    HARD_LED_Init(LED_GREEN);  
    Term_UART_Config();
    HARD_TIM_Init();
while (1)
  {
  }
 
}
 
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  Term_sending("AT+CMD\n");
}
In Term.c
void Term_sending(char *s){
  
  if(HAL_UART_Receive(&Term_huart, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 0xFFF) != HAL_OK)
  {
    Error_Handler(); 
  }
   
  if(Buffercmp((uint8_t*)aOKBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))
  {
    Error_Handler();
  }
  else{
    HARD_LED_Toggle(LED2);
  }
In stm32f0xx_hal_uart.c
Function called by HAL_UART_Receive
HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout) 
{
  uint32_t tickstart = HAL_GetTick();
 
  /* Wait until flag is set */
  if(Status == RESET)
  {   
    while(__HAL_UART_GET_FLAG(huart, Flag) == RESET)
    {
      /* Check for the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
        if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
        {
          /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
          __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
          __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
          __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
          __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
 
          huart->State = HAL_UART_STATE_READY;
 
          /* Process Unlocked */
          __HAL_UNLOCK(huart);
 
          return HAL_TIMEOUT;
        }
      }
    }
  }
  else

First time code pass then it is bugging in UART_WaitOnFlagUntilTimeout after all __HAL_UART_DISABLE_IT.
Is the way quite ok for enabling uart communication each 1 sec? Why the code does not execute correctly?

Best,


Outcomes