Skip to main content
Associate II
October 29, 2023
Question

HAL_UART_RxCpltCallback not being called for USART1 and USART1_IRQHandler has no data

  • October 29, 2023
  • 3 replies
  • 9566 views

Hello,

I have an STM32L476G Evaluation board, and I'm trying to use USART1 to generate an interrupt on receiving characters. On the evaluation board, this is connected to the RS232 port, which I have a module, I transmit data to get a response back. I've hooked up a salae logic analyser and can see when I send the data, the response is being sent back.

2023-10-29 07_24_32-Logic 2 [Logic Pro 16 - Connected] [Session 2].png

From CubeMX I have enabled the USART1, with global interrupts, as well as in the project manager tab, I have selected in the advanced settings register callback for USART and UART.

In the code I write the line below, to receive and interrupt every character:

HAL_UART_Receive_IT(&huart1, rx_buffer, 1);

 

 

Then I transmit the string code I write the line below, to receive and interrupt every character:

while(HAL_UART_Transmit_IT(&huart1, atc, 4) != HAL_OK);

HAL_Delay(1000);

 

The function below gets called, however, HAL_UART_RxCpltCallback(UART_HandleType *huart) never gets called.

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 */
/* USER CODE END USART1_IRQn 1 */
}

 

When I debug and put a breakpoint in the USART_IRQHandler(void) function, there is no data in the buffer.

 

What is the problem with what I am doing and why is the data not being stored in the buffer? I am generating an interrupt as the USART_IRQHandler(void) is causing the breakpoint to stop, but there is no data in the buffer.

This topic has been closed for replies.

3 replies

KnarfB
Super User
October 29, 2023

Selecting "register callback" means, that you have to write code registering your own functions. The traditional way is not selecting that in which case you have to implement your own HAL_UART_RxCpltCallback (what yo did).

If you still encounter issues, step into HAL_UART_IRQHandler and let the code show you what's going on.

hth

KnarfB

JSC4Author
Associate II
October 29, 2023

@KnarfB Ok so I've unset register callback for the usart/uart. Still not data is being shown in the buffer, and the HAL_UART_RxCpltCallback is not called. In the HAL_UART_IRQHandler this if statement gets skipped.

JSC4_0-1698581488203.png
The return of the function happens here:
JSC4_1-1698581545472.png

I attached the _hal_uart.c for reference.

KnarfB
Super User
October 29, 2023

is rx_buffer a global variable? The pRxBufPtr variable in your above dump has advanced one char position, so something was received?

HAL handler should call UART_RxISR_8BIT which in turn calls your callback. Check error bits.

hth

KnarfB

JSC4Author
Associate II
October 29, 2023

Adding some debug of the TX buffer being populated with the "AT\r", but the RX buffer has a count of one, but the data is always zero. 

JSC4_0-1698580184662.png

 

Tesla DeLorean
Guru
October 29, 2023

Shouldn't be using the while() loops for the transmit, the IT function will return immediately. 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JSC4Author
Associate II
October 29, 2023

@Tesla DeLorean Ok that's fine, I've stopped doing that and still the interrupt gets triggered and no data shows when I debug