cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 board USART IRQ

dman
Associate II
Posted on January 10, 2016 at 02:08

Hi everyone,

I am trying to connect a nucleo board to an ESP8266-01WiFi board using UART1, I've used the STM32Cube to generate the project. I've added the NVIC and there is aUSART1_IRQHandler function generated. However, it does not seem to get called each time there is something in the DR register. Also I've noticed that the function get stuck after it receives the first item. This is my while inside the main.c

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while
(1)
{
HAL_UART_Transmit(&huart1,ap_command,
sizeof
(ap_command),2000);
__HAL_UART_FLUSH_DRREGISTER(&huart1);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
hal_states = HAL_UART_GetState(&huart1); 
HAL_Delay(1000);
}
/* USER CODE END 3 */

This is my IRQ function

/**
* @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 
*/
void
USART1_IRQHandler(
void
)
{
/* USER CODE BEGIN USART1_IRQn 0 */
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
if
(HAL_UART_Receive(&huart1,rx_buffer,BUFFER_SIZE,500) != HAL_OK)
{
hal_state = HAL_UART_GetState(&huart1);
} 
/* USER CODE END USART1_IRQn 1 */
}

So every 1s I should have the IRQ called but it aint. Any advice much appreciated
3 REPLIES 3
Amel NASRI
ST Employee
Posted on January 13, 2016 at 17:08

Hi narsutis.dainius,

USART1_IRQHandler should be used to manage USART transfers in interrupt mode.

With the calls of HAL_UART_Transmit and HAL_UART_Receive, you are using polling mode.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

dman
Associate II
Posted on January 19, 2016 at 21:39

Hi,

So I should remove the IRQ handler and just do a HAL_UART_Receive for each character in main. Am I getting this right?

Thanks

dman
Associate II
Posted on January 19, 2016 at 22:29

Nevermind, I;ve decided to ditch the STM32L0 + HAL libraries and just use my spare STM32F4 + std periph