Datasheet

92
ATmega323(L)
1457E11/01
Read Access Doing a read access to the UBRRH or the UCSRC register is a more complex operation.
However, in most applications, it is rarely necessary to read any of these registers.
The read access is controlled by a timed sequence. Reading the I/O location once
returns the UBRRH register contents. If the register location was read in previous sys-
tem clock cycle, reading the register in the current clock cycle will return the UCSRC
contents. Note that the timed sequence for reading the UCSRC is an atomic operation.
Interrupts must therefore be disabled during the read operation.
The following code example shows how to read the UCSRC register contents.
Note: 1. The example code assumes that the part specific header file is included.
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.
Assembly Code Example
(1)
USART_ReadUCSRC:
; Save global interrupt flag
in r17,SREG
; Disable interrupts
cli
; Read UCSRC
in r16,UBRRH
in r16,UCSRC
; Restore global interrupt flag
out SREG,r17
ret
C Code Example
unsigned char USART_ReadUCSRC( void )
{
unsigned char sreg, ucsrc;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
_CLI();
/* Read UCSRC */
ucsrc = UBRRH;
ucsrc = UCSRC;
/* Restore global interrupt flag */
SREG = sreg;
return ucsrc;
}