cancel
Showing results for 
Search instead for 
Did you mean: 

how to clear the receive buffer of HAL_UART_Receive_IT

TGill.4
Associate II

I'm using the HAL_UART_Receive_IT function on stm32f303re to recieve

data. After each use I want to delete the content of the receive buffer

so that the next data that will arrive will start at the first index of

the array. Is there a function to delete the content of the receive

buffer of the function HAL_UART_Receive_IT(&huart, buffer,

sizeofbuffer)?

6 REPLIES 6

I don't understand the question: HAL_UART_Receive_IT() always starts to receive from the first index of array.

JW

TGill.4
Associate II

unfortunately or maybe I'm wrong, but this is not the case and I could see it by using this function twice in a row. the second time the new data was recorded after the previous ones. I would say that it behaved like a ringbuffer.

unfortunately or maybe I'm wrong, but this is not the case and I could see it by using this function twice in a row. the second time the new data was recorded after the previous ones. I would say that it behaved like a ringbuffer.

maybe youre just receiving UART too fast so sometimes youre getting more than one "data" in your buffer?

we dont need to firmware by ourselves, lets talk

But then you don't use it as intended.

You are supposed to receive *exactly* the number of bytes (or halfwords) specified by the Size parameter (which you've called "sizeofbuffer"). Only after that are you supposed to call HAL_UART_Receive_IT() again. You are also supposed to check the return value from HAL_UART_Receive_IT().

If you wish to stop this before you've received all the bytes you've specified, you are supposed to call HAL_UART_AbortReceive_IT() and then wait until the respective callback confirming that the abort is complete, is called.

You've read the manual, haven't you?

If Cube/HAL functions don't fit your purpose, well, simply don't use them and program normally.

JW

Well you have ALL the source code.. debug it

It's not supposed to loop, it is supposed to restart, but content will fill in the background, over multiple IRQHandler calls.

Should be volatile, should be copied to a secondary buffer for processing.

It doesn't NUL terminate, so no use string functions is implicitly supported.

memset the buffer to zero, or some pattern, before re-submission so you can see what changes.

Check for error/failure cases.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..