atmega323l ATMEL Corporation, atmega323l Datasheet - Page 93

no-image

atmega323l

Manufacturer Part Number
atmega323l
Description
Atmega323 8-bit Avr Microcontroller With 32k Bytes Of In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet
Read Access
1457G–AVR–09/03
Doing a read access to the UBRRH or the UCSRC Register is a more complex opera-
tion. 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:
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
C Code Example
USART_ReadUCSRC:
unsigned char USART_ReadUCSRC( void )
{
}
; Save Global Interrupt Flag
in
; Disable interrupts
cli
; Read UCSRC
in
in
; Restore Global Interrupt Flag
out SREG,r17
ret
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;
1. The example code assumes that the part specific header file is included.
r16,UBRRH
r16,UCSRC
r17,SREG
(1)
(1)
ATmega323(L)
93

Related parts for atmega323l