
- •Features
- •Pin Configuration
- •Description
- •Block Diagram
- •Pin Descriptions
- •Port A (PA7..PA0)
- •Port B (PB7..PB0)
- •Port C (PC7..PC0)
- •Port D (PD7..PD0)
- •Port E (PE2..PE0)
- •RESET
- •XTAL1
- •XTAL2
- •Crystal Oscillator
- •EEPROM Data Memory
- •SRAM Data Memory
- •I/O Direct
- •Data Direct
- •Data Indirect with Displacement
- •Data Indirect
- •l/O Memory
- •Status Register – SREG
- •Stack Pointer – SP
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Interrupt Handling
- •Interrupt Response Time
- •External Interrupts
- •Sleep Modes
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Timer/Counters
- •Timer Counter0 – TCNT0
- •Timer/Counter2 – TCNT2
- •Timer/Counter1
- •Timer/Counter1 in PWM Mode
- •Watchdog Timer
- •SS Pin Functionality
- •Data Modes
- •SPI Control Register – SPCR
- •SPI Status Register – SPSR
- •SPI Data Register – SPDR
- •UARTs
- •Data Transmission
- •Data Reception
- •UART Control
- •Baud Rate Generator
- •Analog Comparator
- •Interface to External Memory
- •I/O Ports
- •Port A
- •Port A Data Register – PORTA
- •Port A as General Digital I/O
- •Port A Schematics
- •Port B
- •Port B Data Register – PORTB
- •Port B as General Digital I/O
- •Port B Schematics
- •Port C
- •Port C Data Register – PORTC
- •Port C as General Digital I/O
- •Port C Schematics
- •Port D
- •Port D Data Register – PORTD
- •Port D as General Digital I/O
- •Alternate Functions of Port D
- •Port D Schematics
- •Port E
- •Port E Data Register – PORTE
- •Port E as General Digital I/O
- •Alternate Functions of Port E
- •Port E Schematics
- •Boot Loader Support
- •Setting the Boot Loader Lock Bits by SPM
- •Performing Page Erase by SPM
- •Fill the Temporary Buffer
- •Perform a Page Write
- •Reading the Fuse and Lock Bits from Software
- •Fuse Bits
- •Signature Bytes
- •Parallel Programming
- •Signal Names
- •Enter Programming Mode
- •Chip Erase
- •Programming the Flash
- •Programming the EEPROM
- •Reading the Flash
- •Reading the EEPROM
- •Programming the Fuse Bits
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Serial Downloading
- •Data Polling Flash
- •Data Polling EEPROM
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •External Data Memory Timing
- •Ordering Information
- •Packaging Information

UART Control
UART0 I/O Data Register –
UDR0
UART1 I/O Data Register –
UDR1
UART0 Control and Status
Registers – UCSR0A
UART1 Control and Status
Registers – UCSR1A
For the slave MCUs, the mechanism appears slightly different for 8-bit and 9-bit reception mode. In 8-bit reception mode (CHR9n in UCSRnB cleared), the stop bit is one for an address byte and zero for a data byte. In 9-bit reception mode (CHR9n in UCSRnB set), the ninth bit is one for an address byte and zero for a data byte, whereas the stop bit is always high.
The following procedure should be used to exchange data in Multi-processor Communication Mode:
1.All slave MCUs are in Multi-processor Communication Mode (MPCMn in UCSRnA is set).
2.The master MCU sends an address byte and all slaves receive and read this byte. In the slave MCUs, the RXCn flag in UCSRnA will be set as normal.
3.Each slave MCU reads the UDRn register and determines if it has been selected. If so, it clears the MPCMn bit in UCSRnA; otherwise, it waits for the next address byte.
4.For each received data byte, the receiving MCU will set the receive complete flag (RXCn in UCSRnA). In 8-bit mode, the receiving MCU will also generate a framing error (FEn in UCSRnA set), since the stop bit is zero. The other slave MCUs, which still have the MPCMn bit set, will ignore the data byte. In this case, the UDRn register and the RXCn, FEn, or flags will not be affected.
5.After the last byte has been transferred, the process repeats from step 2.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
$0C ($2C) |
MSB |
|
|
|
|
|
|
LSB |
UDR0 |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
$03 ($23) |
MSB |
|
|
|
|
|
|
LSB |
UDR1 |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
The UDRn register is actually two physically separate registers sharing the same I/O address. When writing to the register, the UART Transmit Data register is written. When reading from UDRn, the UART Receive Data register is read.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
$0B ($2B) |
RXC0 |
TXC0 |
UDRE0 |
FE0 |
OR0 |
– |
U2X0 |
MPCM0 |
UCSR0A |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R |
R/W |
R |
R |
R |
R |
R/W |
R/W |
|
Initial Value |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
|
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
$02 ($22) |
RXC1 |
TXC1 |
UDRE1 |
FE1 |
OR1 |
– |
U2X1 |
MPCM1 |
UCSR1A |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R |
R/W |
R |
R |
R |
R |
R/W |
R/W |
|
Initial Value |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
|
72 ATmega161(L)
1228B–09/01

ATmega161(L)
• Bit 7 – RXC0/RXC1: UART Receive Complete
This bit is set (one) when a received character is transferred from the Receiver Shift register to UDRn. The bit is set regardless of any detected framing errors. When the RXCIEn bit in UCSRnB is set, the UART Receive Complete interrupt will be executed when RXCn is set (one). RXCn is cleared by reading UDRn. When interrupt-driven data reception is used, the UART Receive Complete Interrupt routine must read UDRn in order to clear RXCn; otherwise, a new interrupt will occur once the interrupt routine terminates.
• Bit 6 – TXC0/TXC1: UART Transmit Complete
This bit is set (one) when the entire character (including the stop bit) in the Transmit shift register has been shifted out and no new data has been written to UDRn. This flag is especially useful in half-duplex communications interfaces, where a transmitting application must enter receive mode and free the communications bus immediately after completing the transmission.
When the TXCIEn bit in UCSRnB is set, setting of TXCn causes the UART Transmit Complete interrupt to be executed. TXCn is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, the TXCn bit is cleared (zero) by writing a logical “1” to the bit.
• Bit 5 – UDRE0/UDRE1: UART Data Register Empty
This bit is set (one) when a character written to UDRn is transferred to the Transmit shift register. Setting of this bit indicates that the transmitter is ready to receive a new character for transmission.
When the UDRIEn bit in UCSRnB is set, the UART Transmit Complete interrupt will be executed as long as UDREn is set and the global interrupt enable bit in SREG is set. UDREn is cleared by writing UDRn. When interrupt-driven data transmittal is used, the UART Data Register Empty Interrupt routine must write UDRn in order to clear UDREn, otherwise a new interrupt will occur once the interrupt routine terminates.
UDREn is set (one) during reset to indicate that the transmitter is ready.
• Bit 4 – FE0/FE1: Framing Error
This bit is set if a Framing Error condition is detected, i.e., when the stop bit of an incoming character is zero.
The FEn bit is cleared when the stop bit of received data is one.
• Bit 3 – OR0/OR1: OverRun
This bit is set if an Overrun condition is detected, i.e., when a character already present in the UDRn register is not read before the next character has been shifted into the Receiver Shift register. The ORn bit is buffered, which means that it will be set once the valid data still in UDRn is read.
The ORn bit is cleared (zero) when data is received and transferred to UDRn.
• Bit 2 – Res: Reserved Bit
This bit is reserved bit in the ATmega161 and will always read as zero.
• Bit 1 – U2X0/U2X1: Double the UART Transmission Speed
When this bit is set (one), the UART speed will be doubled. This means that a bit will be transmitted/received in 8 CPU clock periods instead of 16 CPU clock periods. For a detailed description, see “Double-speed Transmission” on page 77.
73
1228B–09/01

UART0 Control and Status
Registers – UCSR0B
UART1 Control and Status
Registers – UCSR1B
• Bit 0 – MPCM0/MPCM1: Multi-processor Communication Mode
This bit is used to enter Multi-processor Communication Mode. The bit is set when the slave MCU waits for an address byte to be received. When the MCU has been addressed, the MCU switches off the MPCMn bit and starts data reception.
For a detailed description, see “Multi-processor Communication Mode”.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
$0A ($2A) |
RXCIE0 |
TXCIE0 |
UDRIE0 |
RXEN0 |
TXEN0 |
CHR90 |
RXB80 |
TXB80 |
UCSR0B |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
|
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
$01 ($21) |
RXCIE1 |
TXCIE1 |
UDRIE1 |
RXEN1 |
TXEN1 |
CHR91 |
RXB81 |
TXB81 |
UCSR1B |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
|
• Bit 7 – RXCIE0/RXCIE1: RX Complete Interrupt Enable
When this bit is set (one), a setting of the RXCn bit in UCSRnA will cause the Receive Complete interrupt routine to be executed, provided that global interrupts are enabled.
• Bit 6 – TXCIE0/TXCIE1: TX Complete Interrupt Enable
When this bit is set (one), a setting of the TXCn bit in UCSRnA will cause the Transmit Complete interrupt routine to be executed, provided that global interrupts are enabled.
• Bit 5 – UDRIE0/UDREI1: UART Data Register Empty Interrupt Enable
When this bit is set (one), a setting of the UDREn bit in UCSRnA will cause the UART Data Register Empty interrupt routine to be executed, provided that global interrupts are enabled.
• Bit 4 – RXEN0/RXEN1: Receiver Enable
This bit enables the UART receiver when set (one). When the receiver is disabled, the TXCn, ORn and FEn status flags cannot become set. If these flags are set, turning off RXEN does not cause them to be cleared.
• Bit 3 – TXEN0/TXEN1: Transmitter Enable
This bit enables the UART transmitter when set (one). When disabling the transmitter while transmitting a character, the transmitter is not disabled before the character in the shift register plus any following character in UDRn has been completely transmitted.
• Bit 2 – CHR90/CHR91: 9-bit Characters
When this bit is set (one), transmitted and received characters are nine bits long, plus start and stop bits. The ninth bit is read and written by using the RXB8n and TXB8 bits in UCSRnB, respectively. The ninth data bit can be used as an extra stop bit or a parity bit.
• Bit 1 – RXB80/RXB81: Receive Data Bit 8
When CHR9n is set (one), RXB8n is the ninth data bit of the received character.
• Bit 0 – TXB80/TXB81: Transmit Data Bit 8
When CHR9n is set (one), TXB8n is the ninth data bit in the character to be transmitted.
74 ATmega161(L)
1228B–09/01