2015-07-07 12:47 AM
Hello,
I want STM32 with GSM board each sec communicate. in Main.cint 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 #interrupt2015-07-07 05:35 AM
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.
2015-07-07 07:45 AM
2015-07-07 08:26 AM
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.2015-07-07 08:39 AM
Alright , it makes sense.
Thank you.