Skip to main content
Graduate II
January 21, 2024
Solved

HAL_UART_Receive_IT not working

  • January 21, 2024
  • 2 replies
  • 5902 views

Hi all i'm implementing a serial communication between my evaluation board and my PC

i managed to send data from my board and read it via PuTTY.

but when i run HAL_UART_Receive_IT and send messages via PuTTY it doesnt trigger the

"HAL_UART_RxCpltCallback" Function

im using NUCLEO H743ZI2

and USART3 baud rate: 115200
Interrupt is enabled for USART3

This is my code (just the important stuff):

Thanks! :)

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 char str[100];
 strcpy(str, "hi hi\n\r");
 HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 1000);
}

int main(void)
{
 char str[100];
 strcpy(str, "hello hello\n\r");
 HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 1000);

 HAL_UART_Receive_IT(&huart3, rx_data, 6);

 while (1){}
}
    This topic has been closed for replies.
    Best answer by TDK

    If you get HAL_TIMEOUT, then data isn't coming in on the RX line. This isn't something that can be fixed by code. Look at the pins involved, ensure you're hooking things up in the appropriate manner. Look at the board schematic, ensure the pin isn't being used by something else and is actually connected to the header you're using for access. Get a logic analyzer and look at signals on the pins.

    2 replies

    Super User
    January 21, 2024

    Get blocking mode up and running first. Can you receive any characters at all? See if HAL_UART_Receive returns HAL_OK along with the expected data.

    Note that calling a blocking function (HAL_UART_Transmit) within an interrupt can cause issues.

    shahaf321Author
    Graduate II
    January 22, 2024

    yea i did try the blocking one but didnt manage to get it working either, i tried a diffrent terminal as well

    these were my steps for "HAL_UART_Receive" (no interrupt)

    i keep getting timeout

    * disabled USART3 Interrupt

    code:

    int main(void)
    {
     uint8_t rx_buffer[10];
     HAL_StatusTypeDef status;
     while (1)
     {
     status = HAL_UART_Receive(&huart3, rx_buffer, sizeof(rx_buffer), 1000);
     if (status == HAL_OK)
     {
     send_message("ok\n\r");
     }
     else if (status == HAL_TIMEOUT)
     {
     send_message(".");
     }
     else
     {
     send_message("ERR");
     }
    
     }
    }
    TDKAnswer
    Super User
    January 22, 2024

    If you get HAL_TIMEOUT, then data isn't coming in on the RX line. This isn't something that can be fixed by code. Look at the pins involved, ensure you're hooking things up in the appropriate manner. Look at the board schematic, ensure the pin isn't being used by something else and is actually connected to the header you're using for access. Get a logic analyzer and look at signals on the pins.

    Super User
    January 22, 2024

    Also, avoid the receiver overrun! If it occurs it will block further receive until cleared off..