Skip to main content
stenasc
Associate III
November 14, 2014
Question

flush usart receive buffer

  • November 14, 2014
  • 3 replies
  • 678 views
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

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    November 14, 2014
    Posted on November 14, 2014 at 02:16

    Read the data register.

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

    stenasc
    stenascAuthor
    Associate III
    November 14, 2014
    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;

    }