AVR USART Recieve Buffer

I’m trying to figure out the byte size of the ATMega168 USART receive buffer, i.e. how many bytes can I send to it without actually reading them from the buffer before they start getting dropped.

Ideally someone could point me to where in the data sheet this information is, I haven’t been able to find it. I suppose I could also determine it experimentally, but I feel like this is an important piece of information that should be up in the bullet points of the USART section.


Hi, Adam.

On page 187 of the datasheet (18.9.1 USART I/O Data Register n- UDRn), it says:

“The receive buffer consists of a two-level FIFO. The FIFO will change its state whenever the receive buffer is accessed.”

Also, on page 181 (18.6.4 Receive Error Flags), it says:

“A Data OverRun occurs when the receive buffer is full (two characters), it is a new character waiting in the Receive Shift Register, and a new start bit is detected.”

I seem to vaguely remember someone else telling me that they tested it and found out the USART can hold three bytes before it starts losing data, which seems to correspond to the poorly worded last quote: two characters in the buffer and one waiting in the receive shift register.

- Ben

Poorly worded indeed! You would think they would put the important stuff like this up front in bold. Like the certain register bits that you clear by writing 1 to them, gets me every time.


Hahahaha! Sorry, had to laugh. In the same weekend I watched Shrek the Third and wrote some SPI interface code to this neat little dual DAC. I swear some of the wording read like the scene where Pinoccio is doing his best not to lie by using double and triple (and quadruple) negatives.

Adam, you’ve probably already seen this, but if you’re looking for UART code with a larger buffer, there’s a lot of interrupt-driven UART code out there with ring buffers. The buffer size is up to the user. The AVR303 application note is an SPI to UART bridge for the STK500. It’s got a pretty nice set of routines for talking to the onboard UART. Been a while since I looked at it, though, so I don’t know if you’d have to tweak it to talk to the 168 or 644.