
- •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 Locations of External Memory Smaller than 64 KB
- •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
- •Default Clock Source
- •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
- •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 Watchdog Timer
- •Safety Level 0
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O Ports
- •Introduction
- •Configuring the Pin
- •Reading the Pin Value
- •Unconnected pins
- •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
- •Register Description for I/O Ports
- •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
- •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
- •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 to Digital Converter
- •Features
- •Operation
- •Starting a Conversion
- •Differential Gain Channels
- •Changing Channel or Reference Selection
- •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
- •Programming Command 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
- •Two-wire Serial Interface Characteristics
- •ADC Characteristics – Preliminary Data
- •External Data Memory Timing
- •Ordering Information
- •Packaging Information
- •Errata
- •ATmega128 Rev. I
- •ATmega128 Rev. H
- •ATmega128 Rev. G
- •ATmega128 Rev. F
- •Datasheet Change Log for ATmega128
- •Changes from Rev. 2467J-12/03 to Rev. 2467K-03/04
- •Changes from Rev. 2467I-09/03 to Rev. 2467J-12/03
- •Changes from Rev. 2467H-02/03 to Rev. 2467I-09/03
- •Changes from Rev. 2467G-09/02 to Rev. 2467H-02/03
- •Changes from Rev. 2467F-09/02 to Rev. 2467G-09/02
- •Changes from Rev. 2467E-04/02 to Rev. 2467F-09/02
- •Changes from Rev. 2467D-03/02 to Rev. 2467E-04/02
- •Changes from Rev. 2467C-02/02 to Rev. 2467D-03/02
- •Changes from Rev. 2467B-09/01 to Rev. 2467C-02/02
- •Table of Contents

XMEM Register Description
MCU Control Register –
MCUCR
External Memory Control
Register A – XMCRA
2467K–AVR–04/04
ATmega128
Figure 16. External Data Memory Cycles with SRWn1 = 1 and SRWn0 = 1(1)
|
T1 |
T2 |
T3 |
T4 |
T5 |
T6 |
T7 |
System Clock (CLKCPU) |
|
|
|
|
|
|
|
ALE |
|
|
|
|
|
|
|
A15:8 |
Prev. addr. |
|
Address |
|
|
|
|
DA7:0 |
Prev. data |
Address XX |
Data |
|
|
|
Write |
|
|
|
|
||||
WR |
|
|
|
|
|
|
|
DA7:0 (XMBK = 0) |
Prev. data |
Address |
Data |
|
|
|
|
DA7:0 (XMBK = 1) |
Prev. data |
Address |
Data |
|
|
|
Read |
|
|
|
|
|
|
|
|
RD |
|
|
|
|
|
|
|
Note: 1. SRWn1 = SRW11 (upper sector) or SRW01 (lower sector), SRWn0 = SRW10 (upper sector) or SRW00 (lower sector).
The ALE pulse in period T7 is only present if the next instruction accesses the RAM (internal or external).
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
SRE |
SRW10 |
SE |
SM1 |
SM0 |
SM2 |
IVSEL |
IVCE |
MCUCR |
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 – SRE: External SRAM/XMEM Enable
Writing SRE to one enables the External Memory Interface.The pin functions AD7:0, A15:8, ALE, WR, and RD are activated as the alternate pin functions. The SRE bit overrides any pin direction settings in the respective data direction registers. Writing SRE to zero, disables the External Memory Interface and the normal pin and data direction settings are used.
• Bit 6 – SRW10: Wait-state Select Bit
For a detailed description in non-ATmega103 compatibility mode, see common description for the SRWn bits below (XMCRA description). In ATmega103 compatibility mode, writing SRW10 to one enables the wait-state and one extra cycle is added during read/write strobe as shown in Figure 14.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
– |
SRL2 |
SRL1 |
SRL0 |
SRW01 |
SRW00 |
SRW11 |
– |
XMCRA |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R |
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
R |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
• Bit 7 – Res: Reserved Bit
This is a reserved bit and will always read as zero. When writing to this address location, write this bit to zero for compatibility with future devices.
• Bit 6..4 – SRL2, SRL1, SRL0: Wait-state Sector Limit
29

It is possible to configure different wait-states for different External Memory addresses. The external memory address space can be divided in two sectors that have separate wait-state bits. The SRL2, SRL1, and SRL0 bits select the split of the sectors, see Table 3 and Figure 11. By default, the SRL2, SRL1, and SRL0 bits are set to zero and the entire external memory address space is treated as one sector. When the entire SRAM address space is configured as one sector, the wait-states are configured by the SRW11 and SRW10 bits.
Table 3. Sector limits with different settings of SRL2..0
SRL2 |
SRL1 |
SRL0 |
Sector Limits |
|
|
|
|
0 |
0 |
0 |
Lower sector = N/A |
|
|
|
Upper sector = 0x1100 - 0xFFFF |
|
|
|
|
0 |
0 |
1 |
Lower sector = 0x1100 - 0x1FFF |
|
|
|
Upper sector = 0x2000 - 0xFFFF |
|
|
|
|
0 |
1 |
0 |
Lower sector = 0x1100 - 0x3FFF |
|
|
|
Upper sector = 0x4000 - 0xFFFF |
|
|
|
|
0 |
1 |
1 |
Lower sector = 0x1100 - 0x5FFF |
|
|
|
Upper sector = 0x6000 - 0xFFFF |
|
|
|
|
1 |
0 |
0 |
Lower sector = 0x1100 - 0x7FFF |
|
|
|
Upper sector = 0x8000 - 0xFFFF |
|
|
|
|
1 |
0 |
1 |
Lower sector = 0x1100 - 0x9FFF |
|
|
|
Upper sector = 0xA000 - 0xFFFF |
|
|
|
|
1 |
1 |
0 |
Lower sector = 0x1100 - 0xBFFF |
|
|
|
Upper sector = 0xC000 - 0xFFFF |
|
|
|
|
1 |
1 |
1 |
Lower sector = 0x1100 - 0xDFFF |
|
|
|
Upper sector = 0xE000 - 0xFFFF |
|
|
|
|
•Bit 1 and Bit 6 MCUCR – SRW11, SRW10: Wait-state Select Bits for Upper Sector
The SRW11 and SRW10 bits control the number of wait-states for the upper sector of the external memory address space, see Table 4.
• Bit 3..2 – SRW01, SRW00: Wait-state Select Bits for Lower Sector
The SRW01 and SRW00 bits control the number of wait-states for the lower sector of the external memory address space, see Table 4.
Table 4. Wait States(1)
SRWn1 |
SRWn0 |
Wait States |
|
|
|
0 |
0 |
No wait-states |
|
|
|
0 |
1 |
Wait one cycle during read/write strobe |
|
|
|
1 |
0 |
Wait two cycles during read/write strobe |
|
|
|
1 |
1 |
Wait two cycles during read/write and wait one cycle before driving out |
|
|
new address |
|
|
|
Note: 1. |
n = 0 or 1 |
(lower/upper sector). |
|
For further details of the timing and wait-states of the External Memory Interface, see |
|
|
Figures 13 through Figures 16 for how the setting of the SRW bits affects the timing. |
• Bit 0 – Res: Reserved Bit
This is a reserved bit and will always read as zero. When writing to this address location, write this bit to zero for compatibility with future devices.
30 ATmega128
2467K–AVR–04/04

ATmega128
External Memory Control
Register B – XMCRB
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
XMBK |
– |
– |
– |
– |
XMM2 |
XMM1 |
XMM0 |
XMCRB |
|
|
|
|
|
|
|
|
|
|
Read/Write |
R/W |
R |
R |
R |
R |
R/W |
R/W |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
• Bit 7– XMBK: External Memory Bus-keeper Enable
Using all Locations of External Memory Smaller than 64 KB
2467K–AVR–04/04
Writing XMBK to one enables the bus keeper on the AD7:0 lines. When the bus keeper is enabled, AD7:0 will keep the last driven value on the lines even if the XMEM interface has tri-stated the lines. Writing XMBK to zero disables the bus keeper. XMBK is not qualified with SRE, so even if the XMEM interface is disabled, the bus keepers are still activated as long as XMBK is one.
• Bit 6..4 – Res: Reserved Bits
These are reserved bits and will always read as zero. When writing to this address location, write these bits to zero for compatibility with future devices.
• Bit 2..0 – XMM2, XMM1, XMM0: External Memory High Mask
When the External Memory is enabled, all Port C pins are default used for the high address byte. If the full 60KB address space is not required to access the External Memory, some, or all, Port C pins can be released for normal Port Pin function as described in Table 5. As described in “Using all 64KB Locations of External Memory” on page 33, it is possible to use the XMMn bits to access all 64KB locations of the External Memory.
Table 5. Port C Pins Released as Normal Port Pins when the External Memory is Enabled
XMM2 |
XMM1 |
XMM0 |
# Bits for External Memory Address |
Released Port Pins |
|
|
|
|
|
0 |
0 |
0 |
8 (Full 60 KB space) |
None |
|
|
|
|
|
0 |
0 |
1 |
7 |
PC7 |
|
|
|
|
|
0 |
1 |
0 |
6 |
PC7 - PC6 |
|
|
|
|
|
0 |
1 |
1 |
5 |
PC7 - PC5 |
|
|
|
|
|
1 |
0 |
0 |
4 |
PC7 - PC4 |
|
|
|
|
|
1 |
0 |
1 |
3 |
PC7 - PC3 |
|
|
|
|
|
1 |
1 |
0 |
2 |
PC7 - PC2 |
|
|
|
|
|
1 |
1 |
1 |
No Address high bits |
Full Port C |
|
|
|
|
|
Since the external memory is mapped after the internal memory as shown in Figure 11, the external memory is not addressed when addressing the first 4,352 bytes of data space. It may appear that the first 4,352 bytes of the external memory are inaccessible (external memory addresses 0x0000 to 0x10FF). However, when connecting an external memory smaller than 64 KB, for example 32 KB, these locations are easily accessed simply by addressing from address 0x8000 to 0x90FF. Since the External Memory Address bit A15 is not connected to the external memory, addresses 0x8000 to 0x90FF will appear as addresses 0x0000 to 0x10FF for the external memory. Addressing above address 0x90FF is not recommended, since this will address an external memory location that is already accessed by another (lower) address. To the Application software, the external 32 KB memory will appear as one linear 32 KB address space from 0x1100 to 0x90FF. This is illustrated in Figure 17. Memory configuration B refers to the ATmega103 compatibility mode, configuration A to the non-compatible mode.
31

When the device is set in ATmega103 compatibility mode, the internal address space is 4,096 bytes. This implies that the first 4,096 bytes of the external memory can be accessed at addresses 0x8000 to 0x8FFF. To the Application software, the external 32 KB memory will appear as one linear 32 KB address space from 0x1000 to 0x8FFF.
Figure 17. Address Map with 32 KB External Memory
|
|
Memory Configuration A |
|
|
|
Memory Configuration B |
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AVR Memory Map |
|
External 32K SRAM |
|
|
|
|
|
|
||
|
|
|
|
|
|
AVR Memory Map |
|
External 32K SRAM |
||||
0x0000 |
|
|
|
|
0x0000 |
|
0x0000 |
|
|
|
|
0x0000 |
|
Internal Memory |
|
|
|
|
Internal Memory |
|
|
||||
|
|
|
|
|
|
0x0FFF |
|
|
0x0FFF |
|||
|
|
|
|
|
|
|
|
|
|
|||
0x10FF |
|
|
|
0x10FF |
|
0x1000 |
|
|
|
0x1000 |
||
0x1100 |
|
|
0x1100 |
|
|
|
|
|
|
|
0x7FFF |
External |
|
|
0x7FFF |
0x7FFF |
External |
|||
|
|
|
|
|
|
0x7FFF |
|||
0x8000 |
Memory |
|
|
|
0x8000 |
Memory |
|||
0x90FF |
|
|
|
|
0x8FFF |
|
|
|
|
0x9100 |
|
|
|
|
0x9000 |
|
|
|
|
|
(Unused) |
|
|
|
|
(Unused) |
|||
0xFFFF |
|
|
|
|
0xFFFF |
|
|
|
|
|
|
|
|
|
|
|
|
32 ATmega128
2467K–AVR–04/04