Skip to main content
Visitor II
May 8, 2024
Question

G491 HAL_UART_RECEIVE issue

  • May 8, 2024
  • 3 replies
  • 2600 views

I am developing a project in which I need to read data that is sent on the UART.
Since it was not working i tried to write a new firmware that only reads from UART, with the following code:

/* USER CODE BEGIN 2 */
volatile HAL_StatusTypeDef huart3RxStat;
uint8_t PWR_Received_data[10];
uint16_t received_bytes;
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
huart3RxStat=HAL_UART_Receive(&huart2,PWR_Received_data, 10, 1000); //for debug
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}



Even with the simplest code i can think of the result is still the same:
The UART only reads one byte and then stops, going into timeout before the time actually expires
(i also tried setting timeout to 10000 to make sure and it goes instantly to timeout)

I then tried testing the same code on a F401 nucleo board and another g491, and it only works
oon the F401.

 
What could be the issue?
 
 
    This topic has been closed for replies.

    3 replies

    Super User
    May 8, 2024

    @massimoGiacobbe wrote:
    going into timeout before the time actually expires

    How do you determine that?

    What is sending the data?

     

    Please use this button to properly post source code:

    AndrewNeil_0-1715185456483.png

     

     

    Visitor II
    May 8, 2024

    Thanks for the info about the code, I'll use it in the future.
    The data is being sent from another board at 200 Hz, 10bytes per packet.
    When i wrote this code on the F401 nucleo it was received with no problem, while i tried on 2 different g491 and it didn't work on wither board. I checked the signal integrity with an oscilloscope both at the input pin at the board and right before the mcu's pin and it was ok.

    Regarding the timeout, i tried putting in 10000 as timeout value (i saw it being suggested in another post), but when i execute with the debugger it instantly returns Hal_timeout as status.

    When i tried to receive the data using HAL_UART_Receive_IT the status it returned was always HAL_BUSY, but otherwise the issue was the same

     

    Super User
    May 8, 2024

    Maybe your HAL timebase is wrong or not working?

    Does HAL_Delay() work correctly?

    Technical Moderator
    May 8, 2024

    Hello,

    while (1)
    {
    huart3RxStat=HAL_UART_Receive(&huart2,PWR_Received_data, 10, 1000); //for debug
    /* USER CODE END WHILE */
    
    /* USER CODE BEGIN 3 */
    }

     This is something asynchronous vs sending data. How do you send data? You can lose data if you're not starting the reception before sending data by the sender .

     

    Visitor II
    May 8, 2024

    Sorry, i misclicked on accept as a solution and don't know how to revert.

    The data is being sent from another board at 200 Hz, 10bytes per packet.
    When i wrote this code on the F401 nucleo it was received with no problem, while i tried on 2 different g491 and it didn't work on wither board. I checked the signal integrity with an oscilloscope both at the input pin at the board and right before the mcu's pin and it was ok.

    What happens is that it only updates the first byte of the buffer and then goes into timeout

    Graduate II
    May 9, 2024

    Curious on why you're using UART2 which is the VCP? Show a diagram on how your two boards are connected.