8-bit AVR Microcontrollers

Flushing the Receive Buffer

The receiver buffer FIFO will be flushed when the receiver is disabled, i.e., the buffer will be emptied of its contents. Unread data will be lost. If the buffer has to be flushed during normal operation, due to for instance an error condition, read the UDRn I/O location until the RXCn flag is cleared.

The following code shows how to flush the receive buffer of USART0.

Assembly Code Example

   in      r16, UCSR0A
   sbrs    r16, RXC
   in      r16, UDR0
   rjmp    USART_Flush

C Code Example

void USART_Flush( void )
   unsigned char dummy;
   while ( UCSR0A & (1<<RXC) ) dummy = UDR0;