- •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
Pin Configurations
Overview
Figure 1. Pinout ATmega128
PEN RXD0/(PDI) PE0 (TXD0/PDO) PE1 (XCK0/AIN0) PE2 (OC3A/AIN1) PE3 (OC3B/INT4) PE4 (OC3C/INT5) PE5
(T3/INT6) PE6 (IC3/INT7) PE7
(SS) PB0
(SCK) PB1 (MOSI) PB2 (MISO) PB3 (OC0) PB4 (OC1A) PB5 (OC1B) PB6
AVCC
64 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 17
PB7(OC2/OC1C)
63 GND
TOSC2/PG3 18
AREF |
PF0 (ADC0) |
PF1 (ADC1) |
PF2 (ADC2) |
PF3 (ADC3) |
PF4 (ADC4/TCK) |
PF5 (ADC5/TMS) |
PF6 (ADC6/TDO) |
PF7 (ADC7/TDI) |
GND |
VCC |
PA0 (AD0) |
PA1 (AD1) |
62 |
61 |
60 |
59 |
58 |
57 |
56 |
55 |
54 |
53 |
52 |
51 |
50 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
|
TOSC1/1PG4 |
|
RESET |
VCC |
GND |
XTAL2 |
XTAL1 |
(SCL/INT0) PD0 |
(SDA/INT1) PD1 |
(RXD1/INT2) PD2 |
(TXD1/INT3) PD3 |
(IC1) PD4 |
(XCK1) PD5 |
(T1) PD6 |
|
|||||||||||||
|
|
|
|
|
(AD2)PA2
49 48 PA3 (AD3)
47 PA4 (AD4)
46 PA5 (AD5)
45 PA6 (AD6)
44 PA7 (AD7)
43 PG2(ALE)
42 PC7 (A15)
41 PC6 (A14)
40 PC5 (A13)
39 PC4 (A12)
38 PC3 (A11)
37 PC2 (A10)
36 PC1 (A9)
35 PC0 (A8)
34 PG1(RD)
33 PG0(WR) 32
PD7(T2)
The ATmega128 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega128 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.
2 ATmega128(L)
2467B–09/01
ATmega128(L)
Block Diagram
Figure 2. Block Diagram
|
|
|
PF0 - PF7 |
|
PA0 - PA7 |
|
|
|
PC0 - PC7 |
|
XTAL1 |
XTAL2 |
RESET |
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
VCC |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GND |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PORTF DRIVERS |
|
PORTA DRIVERS |
|
PORTC DRIVERS |
|
|
|||||
|
|
DATA REGISTER |
DATA DIR. |
DATA REGISTER |
DATA DIR. |
DATA REGISTER |
DATA DIR. |
|
|
|||||
|
|
|
PORTF |
REG. PORTF |
PORTA |
|
REG. PORTA |
PORTC |
|
REG. PORTC |
|
|
||
|
|
|
|
|
|
|
|
8-BIT DATA BUS |
|
|
|
|
|
|
AVCC |
|
|
|
|
|
|
|
|
CALIB. OSC |
|
|
|
|
|
|
|
|
|
|
|
|
INTERNAL |
|
|
|
|
|||
AGND |
|
|
|
ADC |
|
|
|
|
|
|
|
|
||
|
|
|
|
|
OSCILLATOR |
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
AREF |
|
|
|
|
|
|
|
|
OSCILLATOR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
JTAG TAP |
|
PROGRAM |
STACK |
|
WATCHDOG |
|
|
|
|
|
|
|
|
|
|
COUNTER |
POINTER |
|
|
TIMER |
|
|
|
|
|
|
|
|
|
|
|
|
|
OSCILLATOR |
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
ON-CHIP DEBUG |
PROGRAM |
SRAM |
|
MCU CONTROL |
TIMING AND |
|
|
|
|
||||
|
FLASH |
|
|
REGISTER |
CONTROL |
|
|
|
|
|||||
|
|
BOUNDARY- |
|
INSTRUCTION |
GENERAL |
|
|
TIMER/ |
|
|
|
|
|
|
|
|
SCAN |
|
|
|
|
|
|
|
|
|
|||
|
|
|
REGISTER |
|
COUNTERS |
|
|
|
|
|
|
|||
|
|
|
|
PURPOSE |
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REGISTERS |
|
|
|
|
|
|
|
|
|
|
PROGRAMMING |
|
X |
|
|
|
|
|
|
|
|
|
||
PEN |
INSTRUCTION |
Y |
|
INTERRUPT |
|
|
|
|
|
|
||||
|
LOGIC |
|
|
|
|
|
|
|
|
|||||
|
|
|
DECODER |
Z |
|
|
UNIT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
CONTROL |
ALU |
|
|
EEPROM |
|
|
|
|
|
|
|
|
|
|
LINES |
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STATUS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REGISTER |
|
|
|
|
|
|
|
|
|
|
|
|
USART0 |
|
|
|
|
SPI |
|
USART1 |
|
2-WIRE SERIAL |
|
|
|
|
|
|
|
|
|
|
|
INTERFACE |
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANALOG COMPARATOR |
DATA REGISTER |
DATA DIR. |
DATA REGISTER |
DATA DIR. |
DATA REGISTER |
DATA DIR. |
DATA REG. |
|
DATA DIR. |
||||
|
+ - |
PORTE |
REG. PORTE |
PORTB |
REG. PORTB |
PORTD |
REG. PORTD |
PORTG |
|
REG. PORTG |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
PORTE DRIVERS |
PORTB DRIVERS |
|
|
PORTD DRIVERS |
|
PORTG DRIVERS |
|||||
|
|
|
PE0 - PE7 |
PB0 - PB7 |
|
|
PD0 - PD7 |
|
PG0 - PG4 |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
2467B–09/01 |
|
|
|
|
|
|
|
|
|
|
|
|
|
ATmega103 and
ATmega128
Compatibility
The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers.
The ATmega128 provides the following features: 128K bytes of In-System Programmable Flash with Read-While-Write capabilities, 4K bytes EEPROM, 4K bytes SRAM, 53 general-purpose I/O lines, 32 general purpose working registers, Real Time Counter (RTC), four flexible timer/counters with compare modes and PWM, 2 USARTs, a byte oriented 2-wire Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain, programmable Watchdog Timer with internal oscillator, an SPI serial port, IEEE std. 1149.1 compliant JTAG test interface, also used for accessing the On-chip Debug system and programming and six software selectable power saving modes. The Idle mode stops the CPU while allowing the SRAM, timer/counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset. In Power-save mode, the asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction Mode stops the CPU and all I/O modules except asynchronous timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low power consumption. In Extended Standby mode, both the main oscillator and the asynchronous timer continue to run.
The device is manufactured using Atmel’s high-density nonvolatile memory technology. The on-chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an on-chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega128 is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications.
The ATmega128 AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits.
The ATmega128 is a highly complex microcontroller where the number of I/O locations supersedes the 64 I/O location reserved in the AVR instruction set. To ensure backward compatibility with the ATmega103, all I/O locations present in ATmega103 have the same location in ATmega128. Most additional I/O locations are added in an Extended I/O space starting from $60 to $FF, (i.e., in the ATmega103 internal RAM space). These location can be reached by using LD/LDS/LDD and ST/STS/STD instruction only, not by using IN and OUT instruction. The relocation of the internal RAM space may still be a problem for ATmega103 users. Also, the increased number of interrupt vectors might be a problem if the code uses absolute addresses. To solve these problems, an ATmega103 compatibility mode can be selected by programming the fuse M103C. In this mode, none of the functions in the Extended I/O space are in use, so the internal RAM is located as in ATmega103. Also, the extended interrupt vectors are removed.
4 ATmega128(L)
2467B–09/01