cancel
Showing results for 
Search instead for 
Did you mean: 

G491 HAL_UART_RECEIVE issue

massimoGiacobbe
Associate II

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?
 
 
9 REPLIES 9
Andrew Neil
Evangelist III

@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

 

 

SofLit
ST Employee

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 .

 

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.

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

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

 

Maybe your HAL timebase is wrong or not working?

Does HAL_Delay() work correctly?

I tried, HAL_Delay() works correctly

Attach your project and a drawing of how you connect both boards to which connector and pins

If you find my answers useful, click the accept button so that way others can see the solution.

I have attached the ioc and the main (the only code i've written that wasn't generated by cubeMX is the code i wrote in the post).
The data is being sent by another board and i have already checked the signal integrity with an oscilloscope.
Again, the problem is specific to the G491 mcu, i have tried 2 different firmwares on 2 different g491 and it doesn't work on either, I have tried to do the same thing on a F401 and it works, so the signal and the connections are not the problem.

Karl Yamashita
Lead II

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

If you find my answers useful, click the accept button so that way others can see the solution.