
143
ATmega8A [DATASHEET]
8159E–AVR–02/2013
Note:
The assembly code example returns the UCSRC value in r16.
Reading the UBRRH contents is not an atomic operation and therefore it can be read as an ordinary register, as
long as the previous instruction did not access the register location.
20.10 Register Description
20.10.1
UDR– USART I/O Data Register
The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the same I/O address
referred to as USART Data Register or UDR. The Transmit Data Buffer Register (TXB) will be the destination for
data written to the UDR Register location. Reading the UDR Register location will return the contents of the
Receive Data Buffer Register (RXB).
For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to zero by the
Receiver.
The transmit buffer can only be written when the UDRE Flag in the UCSRA Register is set. Data written to UDR
when the UDRE Flag is not set, will be ignored by the USART Transmitter. When data is written to the transmit buf-
fer, and the Transmitter is enabled, the Transmitter will load the data into the Transmit Shift Register when the Shift
Register is empty. Then the data will be serially transmitted on the TxD pin.
The receive buffer consists of a two level FIFO. The FIFO will change its state whenever the receive buffer is
accessed. Due to this behavior of the receive buffer, do not use Read-Modify-Write instructions (SBI and CBI) on
this location. Be careful when using bit test instructions (SBIC and SBIS), since these also will change the state of
the FIFO.
USART_ReadUCSRC:
; Read UCSRC
in
r16,UBRRH
in
r16,UCSRC
ret
unsigned char
USART_ReadUCSRC( void )
{
unsigned char
ucsrc;
/* Read UCSRC */
ucsrc = UBRRH;
ucsrc = UCSRC;
return ucsrc;
}
Bit
7
6
543
21
0
RXB[7:0]
UDR (Read)
TXB[7:0]
UDR (Write)
Read/Write
R/WR/W
Initial Value
0