cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Interrupt for UART communication

astree
Associate II
Posted on July 07, 2015 at 09:47

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);
}

Instm32f0xx_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, #uart #timer #interrupt
4 REPLIES 4
Posted on July 07, 2015 at 14:35

I'm not sure sending strings to a GSM Modem at 1 Hz is a good plan. Sending multiple characters in an interrupt, that will use multiple other interrupts, also problematic.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
astree
Associate II
Posted on July 07, 2015 at 16:45

Thank you for your advises. Do you mean I should not expect sending data with regular delay anymore? Or there is a way to do so?

Posted on July 07, 2015 at 17:26

Aren't there some AT commands that have network timeouts in the order of several minutes? In these situations poking the modem every second is a bit counter productive.

You'd probably want a state machine, or sequencer, to send command, and get responses, serially, then move to the next command, or send one after a delay.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
astree
Associate II
Posted on July 07, 2015 at 17:39

Alright , it makes sense.

Thank you.