cancel
Showing results for 
Search instead for 
Did you mean: 

flush usart receive buffer

stenasc
Senior
Posted on November 14, 2014 at 01:07

Hello,

I need a way to flush the usart2 receive buffer . Will the following line do the trick or is it necessary to do something with the received rubbish bytes?

// If buffer contains garbage, do nothing

while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET);

Kind Regards

Bob

3 REPLIES 3
Posted on November 14, 2014 at 02:16

Read the data register.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on November 14, 2014 at 10:51

stenasc
Senior
Posted on November 14, 2014 at 10:54

Hi Clive,

Thanks for the reply. I don't have a lot of memory left in order to create a thrash buffer so would this suffice....?

If I do nothing as in my original suggestion, will the data not be clocked out eventually as in a fifo or must you actually read the data out to clear it....kinda basic question already which I've probably answered, but just need clarification.

Bob

.

char rubbish[10];

int counter = 0;

while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET){

rubbish[counter++] = USART1->RDR;

if (counter == 9)

counter = 0;

}