Skip to main content
TGill.4
Associate II
September 2, 2022
Question

how to clear the receive buffer of HAL_UART_Receive_IT

  • September 2, 2022
  • 3 replies
  • 10620 views

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)?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
September 2, 2022

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

JW

TGill.4
TGill.4Author
Associate II
September 2, 2022

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.

Tesla DeLorean
Guru
September 2, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
TGill.4
TGill.4Author
Associate II
September 2, 2022

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.

Javier1
Principal
September 2, 2022

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

hit me up in https://www.linkedin.com/in/javiermuñoz/
waclawek.jan
Super User
September 2, 2022

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