cancel
Showing results for 
Search instead for 
Did you mean: 

UART receive in interrupt mode (HAL_UART_Receive_IT)

Valentin Gros
Associate III

Hello,

Target : NUCLEO-L432KC board

IDE : STM32Cube IDE

OS : Windows

I want to get information from a GPS chip with an UART communication (TX/RX). It works when I use non-interrupt mode with HAL_UART_Receive function form HAL library.

However I want to optimize the code using the function HAL_UART_Receive_IT from HAL library. For now it is not working.

My UART configuration is here :

0690X000009jzH4QAI.png

I only added this code to the generated main.c :

/* USER CODE BEGIN 0 */

uint8_t rx_buff[20];

/* USER CODE END 0 */

and

 /* USER CODE BEGIN 2 */

 HAL_UART_Receive_IT (&huart1, rx_buff, 20);

 /* USER CODE END 2 */

and

/* USER CODE BEGIN 4 */

void HAL_UART_RxCplt_Callback(UART_HandleTypeDef * huart)

{

__NOP();

}

void HAL_UART_TxCplt_Callback(UART_HandleTypeDef * huart)

{

__NOP();

}

/* USER CODE END 4 */

Then I compiled the code, and I expected to see parts of the data form the GPS in my rx_buff variable. But there is no data in this variable according to the "live expression" debugging tool.

0690X000009jzJFQAY.png

Do you have any idea why it doesn't work ?

Best regards,

Valentin Gros

10 REPLIES 10

Hello umesh_patil,

Thanks for your help.

  • I'm not totally sure I understood but I added this code in the callback function :

/* USER CODE BEGIN 4 */

void HAL_UART_RxCplt_Callback(UART_HandleTypeDef * huart)

{

int i;

// I copy the buffer in an other variable (tab int)

for(i = 0; i<20;i++){

tabInt[i] = rx_buff[i];

}

}

Here I copy my rx buffer in an another table of integers. Both rx_buff and tabInt stay empty.