- •Features
- •Pin Configurations
- •Overview
- •Block Diagram
- •Pin Descriptions
- •Port A (PA7..PA0)
- •Port B (PB7..PB0)
- •Port C (PC7..PC0)
- •Port D (PD7..PD0)
- •Port E (PE7..PE0)
- •Port F (PF7..PF0)
- •Port G (PG4..PG0)
- •RESET
- •XTAL1
- •XTAL2
- •AVCC
- •AREF
- •AVR CPU Core
- •Introduction
- •Architectural Overview
- •Status Register
- •Stack Pointer
- •Interrupt Response Time
- •SRAM Data Memory
- •Data Memory Access Times
- •EEPROM Data Memory
- •EEPROM Read/Write Access
- •I/O Memory
- •Overview
- •ATmega103 Compatibility
- •Address Latch Requirements
- •Pull-up and Bus-keeper
- •Timing
- •XMEM Register Description
- •Using all 64KB Locations of External Memory
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Crystal Oscillator
- •External RC Oscillator
- •External Clock
- •Timer/Counter Oscillator
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Standby Mode
- •Extended Standby Mode
- •Analog to Digital Converter
- •Analog Comparator
- •Brown-out Detector
- •Internal Voltage Reference
- •Watchdog Timer
- •Port Pins
- •System Control and Reset
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Watchdog Timer
- •Timed Sequences for Changing the Configuration of the Watch Dog Timer
- •Safety Level 0
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O-Ports
- •Introduction
- •Configuring the Pin
- •Reading the Pin Value
- •Alternate Port Functions
- •Alternate Functions of Port A
- •Alternate Functions of Port B
- •Alternate Functions of Port C
- •Alternate Functions of Port D
- •Alternate Functions of Port E
- •Alternate Functions of Port F
- •Alternate Functions of Port G
- •Port A Data Register – PORTA
- •Port B Data Register – PORTB
- •Port C Data Register – PORTC
- •Port D Data Register – PORTD
- •Port E Data Register – PORTE
- •Port F Data Register – PORTF
- •Port G Data Register – PORTG
- •External Interrupts
- •8-bit Timer/Counter0 with PWM and Asynchronous Operation
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Timer/Counter Prescaler
- •16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3)
- •Overview
- •Registers
- •Definitions
- •Compatibility
- •Counter Unit
- •Input Capture Unit
- •Input Capture Trigger Source
- •Noise Canceler
- •Using the Input Capture Unit
- •Output Compare Units
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •16-bit Timer/Counter Register Description
- •Internal Clock Source
- •Prescaler Reset
- •External Clock Source
- •8-bit Timer/Counter2 with PWM
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Overview
- •Description
- •Timing Example
- •Slave Mode
- •Master Mode
- •SPI Control Register – SPCR
- •SPI Status Register – SPSR
- •SPI Data Register – SPDR
- •Data Modes
- •USART
- •Dual USART
- •Overview
- •AVR USART vs. AVR UART – Compatibility
- •Clock Generation
- •External Clock
- •Synchronous Clock Operation
- •Frame Formats
- •Parity Bit Calculation
- •USART Initialization
- •Sending Frames with 5 to 8 Data Bit
- •Sending Frames with 9 Data Bit
- •Parity Generator
- •Disabling the Transmitter
- •Receiving Frames with 5 to 8 Data Bits
- •Receiving Frames with 9 Data Bits
- •Receiver Error Flags
- •Parity Checker
- •Disabling the Receiver
- •Flushing the Receive Buffer
- •Asynchronous Data Recovery
- •Using MPCM
- •Two-wire Serial Interface
- •Features
- •TWI Terminology
- •Electrical Interconnection
- •Transferring Bits
- •START and STOP Conditions
- •Address Packet Format
- •Data Packet Format
- •Multi-master Bus Systems, Arbitration and Synchronization
- •Overview of the TWI Module
- •Scl and SDA Pins
- •Bit Rate Generator Unit
- •Bus Interface Unit
- •Address Match Unit
- •Control Unit
- •TWI Register Description
- •TWI Bit Rate Register – TWBR
- •TWI Control Register – TWCR
- •TWI Status Register – TWSR
- •TWI Data Register – TWDR
- •Using the TWI
- •Transmission Modes
- •Master Transmitter Mode
- •Master Receiver Mode
- •Slave Receiver Mode
- •Slave Transmitter Mode
- •Miscellaneous States
- •Analog Comparator
- •Analog Comparator Multiplexed Input
- •Analog to Digital Converter
- •Features
- •Operation
- •Starting a Conversion
- •Differential Gain Channels
- •ADC Input Channels
- •ADC Voltage Reference
- •ADC Noise Canceler
- •Analog Input Circuitry
- •ADC Accuracy Definitions
- •ADC Conversion Result
- •ADLAR = 0:
- •ADLAR = 1:
- •Features
- •Overview
- •Test Access Port – TAP
- •TAP Controller
- •PRIVATE0; $8
- •PRIVATE1; $9
- •PRIVATE2; $A
- •PRIVATE3; $B
- •Bibliography
- •Features
- •System Overview
- •Data Registers
- •Bypass Register
- •Device Identification Register
- •Reset Register
- •Boundary-scan Chain
- •EXTEST; $0
- •IDCODE; $1
- •SAMPLE_PRELOAD; $2
- •AVR_RESET; $C
- •BYPASS; $F
- •Boundary-scan Chain
- •Scanning the Digital Port Pins
- •Scanning the RESET Pin
- •Scanning the Clock Pins
- •Scanning the ADC
- •Boot Loader Features
- •Application Section
- •Boot Loader Section – BLS
- •Boot Loader Lock Bits
- •Performing a Page Write
- •Using the SPM Interrupt
- •Setting the Boot Loader Lock Bits by SPM
- •Reading the Fuse and Lock Bits from Software
- •Preventing Flash Corruption
- •Simple Assembly Code Example for a Boot Loader
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Signal Names
- •Parallel Programming
- •Enter Programming Mode
- •Chip Erase
- •Programming the Flash
- •Programming the EEPROM
- •Reading the Flash
- •Reading the EEPROM
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Serial Downloading
- •Data Polling Flash
- •Data Polling EEPROM
- •AVR_RESET ($C)
- •PROG_ENABLE ($4)
- •PROG_COMMANDS ($5)
- •PROG_PAGELOAD ($6)
- •PROG_PAGEREAD ($7)
- •Data Registers
- •Reset Register
- •Programming Enable Register
- •Virtual Flash Page Read Register
- •Programming Algorithm
- •Entering Programming Mode
- •Leaving Programming Mode
- •Performing Chip Erase
- •Programming the Flash
- •Reading the Flash
- •Programming the EEPROM
- •Reading the EEPROM
- •Programming the Fuses
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •External Clock Drive Waveforms
- •External Clock Drive
- •2-wire Serial Interface Characteristics
- •ADC Characteristics - Preliminary Data
- •External Data Memory Timing
- •Ordering Information
- •Packaging Information
Alternate Functions of Port E The Port E pins with alternate functions are shown in Table 39.
Table 39. Port E Pins Alternate Functions
Port Pin |
Alternate Function |
|
|
|
|
PE7 |
INT7/IC3(1) (External Interrupt7 Input or Timer/Counter3 Input Capture Trigger) |
|
PE6 |
INT6/ T3(1) (External Interrupt6 Input or Timer/Counter3 Clock Input) |
|
PE5 |
INT5/OC3C(1) (External Interrupt5 Input or Output Compare and PWM Output C for |
|
Timer/Counter3) |
||
|
||
|
|
|
PE4 |
INT4/OC3B(1) (External Interrupt4 Input or Output Compare and PWM Output B for |
|
Timer/Counter3) |
||
|
||
|
|
|
PE3 |
AIN1/OC3A (1) (Analog Comparator Negative Input or Output Compare and PWM |
|
Output A for Timer/Counter3) |
||
|
||
|
|
|
PE2 |
AIN0/XCK0(1) (Analog Comparator Positive Input or USART0 external clock |
|
input/output) |
||
|
||
|
|
|
PE1 |
PDO/TXD0 (Programming Data Output or UART0 Transmit Pin) |
|
|
|
|
PE0 |
PDI/RXD0 (Programming Data Input or UART0 Receive Pin) |
|
|
|
Note: 1. IC3, T3, OC3C, OC3B, OC3B, OC3A, and XCK0 not applicable in ATmega103 compatibility mode.
• INT7/IC3 - Port E, Bit 7
INT7, External Interrupt source 7: The PE7 pin can serve as an external interrupt source.
IC3 - Input Capture Pin3: The PE7 pin can act as an input capture pin for
Timer/Counter3.
• INT6/T3 - Port E, Bit 6
INT6, External Interrupt source 6: The PE6 pin can serve as an external interrupt source.
T3, Timer/Counter3 counter source.
• INT5/OC3C - Port E, Bit 5
INT5, External Interrupt source 5: The PE5 pin can serve as an external interrupt source.
OC3C, Output Compare matchC output: The PE5 pin can serve as an external output for the Timer/Counter3 output compareC. The pin has to be configured as an output (DDE5 set “one”) to serve this function. The OC3C pin is also the output pin for the PWM mode timer function.
• INT4/OC3B - Port E, Bit 4
INT4, External Interrupt source 4: The PE4 pin can serve as an external interrupt source.
OC3B, Output Compare matchB output: The PE4 pin can serve as an external output for the Timer/Counter3 output compareB. The pin has to be configured as an output (DDE4 set (one)) to serve this function. The OC3B pin is also the output pin for the PWM mode timer function.
• AIN1/OC3A - Port E, Bit 3
AIN1 - Analog Comparator Negative Input. This pin is directly connected to the negative input of the analog comparator.
76 ATmega128(L)
2467B–09/01
ATmega128(L)
OC3A, Output Compare matchA output: The PE3 pin can serve as an external output for the Timer/Counter3 output compareA. The pin has to be configured as an output (DDE3 set “one”) to serve this function. The OC3A pin is also the output pin for the PWM mode timer function.
• AIN0/XCK0 - Port E, Bit 2
AIN0 - Analog Comparator Positive Input. This pin is directly connected to the positive input of the analog comparator.
XCK0, USART0 external clock. The Data Direction Register (DDE2) controls whether the clock is output (DDE2 set) or input (DDE2 cleared). The XCK0 pin is active only when the USART0 operates in synchronous mode.
• PDO/TXD0 - Port E, Bit 1
PDO, Serial Programming Data Output. During Serial Program Downloading, this pin is used as data output line for the ATmega128.
TXD0, UART0 Transmit Pin.
• PDI/RXD0 - Port E, Bit 0
PDI, Serial Programming Data Input. During Serial Program Downloading, this pin is used as data input line for the ATmega128.
RXD0, USART0 Receive Pin. Receive Data (Data input pin for the USART0). When the USART0 receiver is enabled this pin is configured as an input regardless of the value of DDRE0. When the USART0 forces this pin to be an input, a logical one in PORTE0 will turn on the internal pull-up.
Table 40 and Table 41 relates the alternate functions of Port E to the overriding signals shown in Figure 32 on page 66.
Table 40. Overriding Signals for Alternate Functions PE7..PE4
Signal |
|
|
|
|
Name |
PE7/INT7/IC3 |
PE6/INT6/T3 |
PE5/INT5/OC3C |
PE4/INT4/OC3B |
|
|
|
|
|
PUOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
PUOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
PVOE |
0 |
0 |
OC3C ENABLE |
OC3B ENABLE |
|
|
|
|
|
PVOV |
0 |
0 |
OC3C |
OC3B |
|
|
|
|
|
DIEOE |
INT7 ENABLE |
INT6 ENABLE |
INT5 ENABLE |
INT4 ENABLE |
|
|
|
|
|
DIEOV |
1 |
1 |
1 |
1 |
|
|
|
|
|
DI |
INT7 INPUT/IC3 |
INT7 INPUT/T3 |
INT5 INPUT |
INT4 INPUT |
|
INPUT |
INPUT |
|
|
|
|
|
|
|
AIO |
– |
– |
– |
– |
|
|
|
|
|
77
2467B–09/01
Table 41. Overriding Signals for Alternate Functions in PE3..PE0
Signal Name |
PE3/AIN1/OC3A |
PE2/AIN0/XCK0 |
PE1/PDO/TXD0 |
PE0/PDI/RXD0 |
||
|
|
|
|
|
||
PUOE |
0 |
0 |
TXEN0 |
RXEN0 |
||
|
|
|
|
|
|
|
PUOV |
0 |
0 |
0 |
PORTE0 • |
|
|
PUD |
||||||
|
|
|
|
|
||
DDOE |
0 |
0 |
TXEN0 |
RXEN0 |
||
|
|
|
|
|
|
|
DDOV |
0 |
0 |
1 |
0 |
|
|
|
|
|
|
|
|
|
PVOE |
OC3B ENABLE |
UMSEL0 |
TXEN0 |
0 |
|
|
|
|
|
|
|
|
|
PVOV |
OC3B |
XCK0 OUTPUT |
TXD0 |
0 |
|
|
|
|
|
|
|
|
|
DIEOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
DIEOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
||
DI |
0 |
XCK0 INPUT |
– |
RXD0 |
||
|
|
|
|
|
||
AIO |
AIN1 INPUT |
AIN0 INPUT |
– |
– |
||
|
|
|
|
|
|
|
Alternate Functions of Port F The Port F has an alternate function as analog input for the ADC as shown in Table 42. If some Port F pins are configured as outputs, it is essential that these do not switch when a conversion is in progress. This might corrupt the result of the conversion. In ATmega103 compatibility mode Port F is input only. If the JTAG interface is enabled, the pull-up resistors on pins PF7(TDI), PF5(TMS) and PF4(TCK) will be activated even if a reset occurs.
Table 42. Port F Pins Alternate Functions
Port Pin |
Alternate Function |
|
|
PF7 |
ADC7/TDI (ADC input channel 7 or JTAG Test Data Input) |
|
|
PF6 |
ADC6/TDO (ADC input channel 6 or JTAG Test Data Output) |
|
|
PF5 |
ADC5/TMS (ADC input channel 5 or JTAG Test Mode Select) |
|
|
PF4 |
ADC4/TCK (ADC input channel 4 or JTAG Test ClocK) |
|
|
PF3 |
ADC3 (ADC input channel 3) |
|
|
PF2 |
ADC2 (ADC input channel 2) |
|
|
PF1 |
ADC1 (ADC input channel 1) |
|
|
PF0 |
ADC0 (ADC input channel 0) |
|
|
• TDI, ADC7 - Port F, Bit 7
ADC7, Analog to Digital Converter, Channel 7.
TDI, JTAG Test Data In: Serial input data to be shifted in to the Instruction Register or Data Register (scan chains). When the JTAG interface is enabled, this pin can not be used as an I/O pin.
• TCK, ADC6 - Port F, Bit 6
ADC6, Analog to Digital Converter, Channel 6.
TDO, JTAG Test Data Out: Serial output data from Instruction register or Data Register.
When the JTAG interface is enabled, this pin can not be used as an I/O pin.
78 ATmega128(L)
2467B–09/01
ATmega128(L)
• TMS, ADC5 - Port F, Bit 5
ADC5, Analog to Digital Converter, Channel 5.
TMS, JTAG Test Mode Select: This pin is used for navigating through the TAP-controller state machine. When the JTAG interface is enabled, this pin can not be used as an I/O pin.
• TDO, ADC4 - Port F, Bit 4
ADC4, Analog to Digital Converter, Channel 4.
TCK, JTAG Test Clock: JTAG operation is synchronous to TCK. When the JTAG interface is enabled, this pin can not be used as an I/O pin.
• ADC3 - ADC0 - Port F, Bit 3..0
Analog to Digital Converter, Channel 3..0.
Table 43. Overriding Signals for Alternate Functions in PF7..PF4
Signal |
|
|
|
|
Name |
PF7/ADC7/TDI |
PF6/ADC6/TDO |
PF5/ADC5/TMS |
PF4/ADC4/TCK |
|
|
|
|
|
PUOE |
JTAGEN |
JTAGEN |
JTAGEN |
JTAGEN |
|
|
|
|
|
PUOV |
1 |
0 |
1 |
1 |
|
|
|
|
|
DDOE |
JTAGEN |
JTAGEN |
JTAGEN |
JTAGEN |
|
|
|
|
|
DDOV |
0 |
SHIFT_IR + |
0 |
0 |
|
|
SHIFT_DR |
|
|
|
|
|
|
|
PVOE |
0 |
JTAGEN |
0 |
0 |
|
|
|
|
|
PVOV |
0 |
TDO |
0 |
0 |
|
|
|
|
|
DIEOE |
JTAGEN |
JTAGEN |
JTAGEN |
JTAGEN |
|
|
|
|
|
DIEOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DI |
– |
– |
– |
– |
|
|
|
|
|
AIO |
TDI/ADC7 INPUT |
ADC6 INPUT |
TMS/ADC5 |
TCKADC4 INPUT |
|
|
|
INPUT |
|
|
|
|
|
|
Table 44. Overriding Signals for Alternate Functions in PF3..PF0
Signal Name |
PF3/ADC3 |
PF2/ADC2 |
PF1/ADC1 |
PF0/ADC0 |
|
|
|
|
|
PUOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
PUOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
PVOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
PVOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DIEOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DIEOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DI |
– |
– |
– |
– |
|
|
|
|
|
AIO |
ADC3 INPUT |
ADC2 INPUT |
ADC1 INPUT |
ADC0 INPUT |
|
|
|
|
|
79
2467B–09/01