
- •Features
- •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
- •Resources
- •Data Retention
- •Capacitive touch sensing
- •AVR CPU Core
- •Introduction
- •Status Register
- •Stack Pointer
- •I/O Memory
- •Overview
- •Timing
- •Using all Locations of External Memory Smaller than 64 Kbyte
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Crystal Oscillator
- •External Clock
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Standby Mode
- •Analog Comparator
- •Brown-out Detector
- •Watchdog Timer
- •Port Pins
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •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
- •Register Description for I/O Ports
- •8-bit Timer/Counter0 with PWM and Asynchronous Operation
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Normal Mode
- •Fast PWM Mode
- •8-bit Timer/Counter Register Description
- •Overview
- •Registers
- •Definitions
- •Compatibility
- •Counter Unit
- •Input Capture Unit
- •Noise Canceler
- •Force Output Compare
- •Normal Mode
- •Fast 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
- •Normal Mode
- •Fast PWM Mode
- •8-bit Timer/Counter Register Description
- •Output Compare Modulator (OCM1C2)
- •Overview
- •Description
- •Timing Example
- •Slave Mode
- •Master Mode
- •Data Modes
- •USART
- •Dual USART
- •Overview
- •AVR USART vs. AVR UART – Compatibility
- •Clock Generation
- •External Clock
- •Frame Formats
- •Parity Bit Calculation
- •Parity Generator
- •Receiver Error Flags
- •Parity Checker
- •Disabling the Receiver
- •Using MPCM
- •Features
- •TWI Terminology
- •Transferring Bits
- •Address Packet Format
- •Data Packet Format
- •Overview of the TWI Module
- •Scl and SDA Pins
- •Bus Interface Unit
- •Address Match Unit
- •Control Unit
- •Using the TWI
- •Master Receiver Mode
- •Slave Receiver Mode
- •Miscellaneous States
- •Analog Comparator
- •Analog to Digital Converter
- •Features
- •Operation
- •Changing Channel or Reference Selection
- •ADC Input Channels
- •Analog Input Circuitry
- •Features
- •Overview
- •TAP Controller
- •PRIVATE0; $8
- •PRIVATE1; $9
- •PRIVATE2; $A
- •PRIVATE3; $B
- •Bibliography
- •Features
- •System Overview
- •Data Registers
- •Bypass Register
- •Reset Register
- •EXTEST; $0
- •IDCODE; $1
- •AVR_RESET; $C
- •BYPASS; $F
- •Scanning the ADC
- •ATmega128 Boundary-scan Order
- •Application Section
- •Programming Time for Flash when Using SPM
- •Simple Assembly Code Example for a Boot Loader
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Signal Names
- •Chip Erase
- •Reading the Flash
- •Reading the EEPROM
- •Data Polling Flash
- •Data Polling EEPROM
- •AVR_RESET ($C)
- •PROG_ENABLE ($4)
- •Data Registers
- •Reset Register
- •Programming Enable Register
- •Programming Command Register
- •Virtual Flash Page Read Register
- •Performing Chip Erase
- •Reading the Flash
- •Reading the EEPROM
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •Speed Grades
- •External Clock Drive Waveforms
- •External Clock Drive
- •Two-wire Serial Interface Characteristics
- •ADC Characteristics
- •External Data Memory Timing
- •Idle Supply Current
- •Pin Pull-up
- •Pin Driver Strength
- •Register Summary
- •Instruction Set Summary
- •Ordering Information
- •Packaging Information
- •Errata
- •ATmega128 Rev. F to M

ATmega128
Two-wire Serial Interface Characteristics
Table 133 describes the requirements for devices connected to the Two-wire Serial Bus. The ATmega128 Two-wire Serial Interface meets or exceeds these requirements under the noted conditions.
Timing symbols refer to Figure 154.
Table 133. Two-wire Serial Bus Requirements
Symbol |
Parameter |
|
|
|
Condition |
|
Min |
|
Max |
Units |
|||
|
|
|
|
|
|
|
|
|
|
|
|
||
VIL |
Input Low-voltage |
|
|
|
|
|
|
-0.5 |
|
0.3 VCC |
|
||
VIH |
Input High-voltage |
|
|
|
|
|
|
0.7 VCC |
VCC + 0.5 |
V |
|||
|
|
(1) |
Hysteresis of Schmitt Trigger Inputs |
|
|
|
|
(2) |
– |
||||
|
|
|
|
|
|
|
|||||||
Vhys |
|
|
|
0.05 VCC |
|
||||||||
V |
(1) |
Output Low-voltage |
|
|
|
3mA sink current |
0 |
|
0.4 |
|
|||
|
OL |
|
|
|
|
|
|
|
|
|
|
|
|
t |
(1) |
Rise Time for both SDA and SCL |
|
|
|
20 + 0.1C |
(3)(2) |
300 |
|
||||
|
r |
|
|
|
|
|
|
|
|
|
b |
|
|
t |
of |
(1) |
Output Fall Time from V |
IHmin |
to V |
ILmax |
10pF < C < 400pF(3) |
20 + 0.1C |
(3)(2) |
250 |
ns |
||
|
|
|
|
|
b |
|
|
b |
|
|
|||
tSP(1) |
Spikes Suppressed by Input Filter |
|
|
|
0 |
|
50(2) |
|
|||||
Ii |
|
Input Current each I/O Pin |
|
|
0.1 VCC < Vi < 0.9 VCC |
-10 |
|
10 |
µA |
||||
C |
(1) |
Capacitance for each I/O Pin |
|
|
|
|
– |
|
10 |
pF |
|||
|
i |
|
|
|
|
|
|
|
|
|
|
|
|
f |
SCL |
SCL Clock Frequency |
|
|
|
f |
(4) > max(16f |
, 250kHz)(5) |
0 |
|
400 |
kHz |
|
|
|
|
|
|
|
CK |
SCL |
|
|
|
|
||
|
|
|
|
|
|
|
fSCL ≤ 100kHz |
|
VCC – 0.4V |
1000ns |
Ω |
||
|
|
|
|
|
|
|
|
|
|
---------------------------- |
------------------- |
||
Rp |
Value of Pull-up resistor |
|
|
|
|
|
|
3mA |
|
Cb |
|
||
|
|
|
fSCL > 100kHz |
|
VCC – 0.4V |
300ns |
Ω |
||||||
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
---------------------------- |
--------------- |
||
|
|
|
|
|
|
|
|
|
|
3mA |
|
Cb |
|
tHD;STA |
Hold Time (repeated) START Condition |
fSCL ≤ 100kHz |
|
4.0 |
|
– |
|
||||||
|
|
|
|
|
|
|
|||||||
fSCL > 100kHz |
|
0.6 |
|
– |
|
||||||||
|
|
|
|
|
|
|
|
|
|
||||
tLOW |
Low Period of the SCL Clock |
|
fSCL ≤ 100kHz |
|
4.7 |
|
– |
|
|||||
|
fSCL > 100kHz |
|
1.3 |
|
– |
|
|||||||
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tHIGH |
High period of the SCL clock |
|
|
fSCL ≤ 100kHz |
|
4.0 |
|
– |
µs |
||||
|
|
fSCL > 100kHz |
|
0.6 |
|
– |
|||||||
|
|
|
|
|
|
|
|
|
|
||||
tSU;STA |
Set-up time for a repeated START condition |
fSCL ≤ 100kHz |
|
4.7 |
|
– |
|
||||||
|
|
|
|
|
|
|
|||||||
fSCL > 100kHz |
|
0.6 |
|
– |
|
||||||||
|
|
|
|
|
|
|
|
|
|
||||
tHD;DAT |
Data hold time |
|
|
|
fSCL ≤ 100kHz |
|
0 |
|
3.45 |
|
|||
|
|
|
fSCL > 100kHz |
|
0 |
|
0.9 |
|
|||||
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tSU;DAT |
Data setup time |
|
|
|
fSCL ≤ 100kHz |
|
250 |
|
– |
ns |
|||
|
|
|
fSCL > 100kHz |
|
100 |
|
– |
||||||
|
|
|
|
|
|
|
|
|
|
||||
tSU;STO |
Setup time for STOP condition |
|
fSCL ≤ 100kHz |
|
4.0 |
|
– |
|
|||||
|
|
|
|
|
|
|
|
||||||
|
fSCL > 100kHz |
|
0.6 |
|
– |
µs |
|||||||
|
|
|
|
|
|
|
|
|
|||||
tBUF |
Bus free time between a STOP and START |
fSCL ≤ 100kHz |
|
4.7 |
|
– |
|||||||
|
|
|
|||||||||||
condition |
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
Notes: 1. |
In ATmega128, this parameter is characterized and not 100% tested. |
|
|
|
|
2.Required only for fSCL > 100kHz.
3.Cb = capacitance of one bus line in pF.
4.fCK = CPU clock frequency
322
2467X–AVR–06/11

ATmega128
5.This requirement applies to all Atmel® AVR® ATmega128 Two-wire Serial Interface operation. Other devices connected to the Two-wire Serial Bus need only obey the general fSCL requirement.
Figure 154. Two-wire Serial Bus Timing
|
|
|
|
|
|
|
|
|
|
|
tof |
|
tHIGH |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tr |
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||
SCL |
|
|
|
|
|
|
|
|
|
|
tLOW |
|
|
|
|
tLOW |
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tSU;STA |
|
|
|
|
|
|
|
|
tHD;STA |
|
tHD;DAT |
|
|
|
|
|
t |
|
|
|
|
|
|
||||||
SDA |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SU;DAT |
|
|
|
tSU;STO |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tBUF
SPI Timing
Characteristics
See Figure 155 and Figure 156 for details.
Table 134. SPI Timing Parameters
|
|
|
|
Description |
Mode |
Min |
Typ |
Max |
|
|||
|
|
|
|
|
|
|
|
|
|
|||
1 |
|
|
|
SCK period |
Master |
|
See Table 72 |
|
|
|||
|
|
|
|
|
|
|
|
|
||||
2 |
|
|
SCK high/low |
Master |
|
50% duty cycle |
|
|
||||
|
|
|
|
|
|
|
|
|
||||
3 |
|
|
Rise/Fall time |
Master |
|
3.6 |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
||
4 |
|
|
|
|
Setup |
Master |
|
10 |
|
|
||
|
|
|
|
|
|
|
|
|
|
|
||
5 |
|
|
|
|
Hold |
Master |
|
10 |
|
|
||
|
|
|
|
|
|
|
|
|
ns |
|||
6 |
|
|
|
Out to SCK |
Master |
|
0.5 • tsck |
|
||||
7 |
|
|
|
SCK to out |
Master |
|
10 |
|
|
|||
|
|
|
|
|
|
|
|
|||||
8 |
|
SCK to out high |
Master |
|
10 |
|
|
|||||
|
|
|
|
|
|
|
|
|
||||
9 |
|
|
SS low to out |
Slave |
|
15 |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|||
10 |
|
|
|
SCK period |
Slave |
4 • tck |
|
|
|
|||
11 |
|
SCK high/low(1) |
Slave |
2 • t |
|
|
|
|||||
|
|
|
|
|
|
|
|
|
ck |
|
|
|
12 |
|
|
Rise/Fall time |
Slave |
|
|
1.6 |
µs |
||||
|
|
|
|
|
|
|
|
|
|
|
||
13 |
|
|
|
|
Setup |
Slave |
10 |
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
||
14 |
|
|
|
|
Hold |
Slave |
10 |
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|||
15 |
|
|
|
SCK to out |
Slave |
|
15 |
|
ns |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
SCK to |
|
high |
Slave |
20 |
|
|
||||
|
SS |
|
|
|
||||||||
|
|
|
|
|
|
|
|
|
|
|||
17 |
|
|
|
high to tri-state |
Slave |
|
10 |
|
|
|||
|
SS |
|
|
|
||||||||
18 |
|
|
|
|
low to SCK |
Slave |
2 • tck |
|
|
|
||
|
|
SS |
|
|
|
|||||||
Note: |
1. In SPI Programming mode the minimum SCK high/low period is: |
|
|
-2 tCLCL for fCK < 12MHz
-3 tCLCL for fCK >12MHz
323
2467X–AVR–06/11

ATmega128
Figure 155. SPI Interface Timing Requirements (Master Mode)
SS
SCK (CPOL = 0)
SCK (CPOL = 1)
MISO
(Data Input)
MOSI
(Data Output)
6 |
|
|
1 |
|
|
2 |
2 |
4 |
5 |
|
3 |
|
MSB |
... |
LSB |
|
|
7 |
8 |
|
MSB |
... |
LSB |
Figure 156. SPI Interface Timing Requirements (Slave Mode)
SS
SCK (CPOL = 0)
SCK (CPOL = 1)
MOSI
(Data Input)
MISO
(Data Output)
18 |
|
|
|
|
9 |
|
|
10 |
16 |
|
|
|
|
|
|
|
11 |
11 |
|
13 |
14 |
|
|
12 |
|
MSB |
... |
LSB |
|
|
|
15 |
|
17 |
|
MSB |
... |
LSB |
X |
324
2467X–AVR–06/11

ATmega128
ADC Characteristics
Table 135. ADC Characteristics, Single Ended Channels
Symbol |
Parameter |
Condition |
Min(1) |
Typ(1) |
Max(1) |
Units |
|
Resolution |
Single Ended Conversion |
|
|
10 |
Bits |
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
|
VREF = 4V, VCC = 4V |
|
1.5 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
|
VREF = 4V, VCC = 4V |
|
3.25 |
|
|
|
Absolute Accuracy |
ADC clock = 1MHz |
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
|
(Including INL, DNL, Quantization Error, Gain |
|
|
|
|
|
|
VREF = 4V, VCC = 4V |
|
|
|
|
|
|
and Offset Error) |
|
1.5 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
||
|
|
|
|
|
|
|
|
|
Noise Reduction mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
|
VREF = 4V, VCC = 4V |
|
3.75 |
|
|
|
|
ADC clock = 1MHz |
|
|
|
|
|
|
|
|
|
LSB |
|
|
|
Noise Reduction mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
Integral Non-Linearity (INL) |
VREF = 4V, VCC = 4V |
|
0.75 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
Differential Non-Linearity (DNL) |
VREF = 4V, VCC = 4V |
|
0.5 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
Gain Error |
VREF = 4V, VCC = 4V |
|
1 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
Single Ended Conversion |
|
|
|
|
|
Offset error |
VREF = 4V, VCC = 4V |
|
1 |
|
|
|
|
ADC clock = 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
Clock Frequency |
|
50 |
|
1000 |
kHz |
|
|
|
|
|
|
|
|
Conversion Time |
|
13 |
|
260 |
µs |
|
|
|
|
|
|
|
AVCC |
Analog Supply Voltage |
|
VCC - 0.3(2) |
|
VCC + 0.3(3) |
|
VREF |
Reference Voltage |
|
2.0 |
|
AVCC |
V |
VIN |
Input Voltage |
|
GND |
|
VREF |
|
|
Input Bandwidth |
|
|
|
38.5 |
kHz |
|
|
|
|
|
|
|
VINT |
Internal Voltage Reference |
|
2.3 |
2.56 |
2.7 |
V |
RREF |
Reference Input Resistance |
|
|
32 |
|
kΩ |
RAIN |
Analog Input Resistance |
|
55 |
100 |
|
MΩ |
Notes: 1. Values are guidelines only.
2.Minimum for AVCC is 2.7V.
3.Maximum for AVCC is 5.5V
325
2467X–AVR–06/11

ATmega128
Table 136. ADC Characteristics, Differential Channels
Symbol |
Parameter |
Condition |
Min(1) |
Typ(1) |
Max(1) |
Units |
|
|
|
Gain = |
1x |
|
|
10 |
|
|
|
|
|
|
|
|
|
|
Resolution |
Gain = |
10x |
|
|
10 |
Bits |
|
|
|
|
|
|
|
|
|
|
Gain = 200x |
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 1x |
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
17 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 10x |
|
|
|
|
|
|
Absolute Accuracy |
VREF = 4V, VCC = 5V |
|
17 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 200x |
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
7 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
LSB |
|
|
|
|
|
|
|
|
|
|
|
Gain = 1x |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
1.5 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
Integral Non-Linearity (INL) |
|
|
|
|
|
|
|
Gain = 10x |
|
|
|
|
|
|
|
(Accuracy after Calibration for Offset and |
VREF = 4V, VCC = 5V |
|
2 |
|
|
|
|
Gain Error) |
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 200x |
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
5 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = |
1x |
|
1.5 |
|
|
|
|
|
|
|
|
|
|
|
Gain Error |
Gain = |
10x |
|
1.5 |
|
% |
|
|
|
|
|
|
|
|
|
|
Gain = 200x |
|
0.5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 1x |
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
2 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 10x |
|
|
|
|
|
|
Offset Error |
VREF = 4V, VCC = 5V |
|
3 |
|
LSB |
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gain = 200x |
|
|
|
|
|
|
|
VREF = 4V, VCC = 5V |
|
4 |
|
|
|
|
|
ADC clock = 50 - 200kHz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Clock Frequency |
|
|
50 |
|
200 |
kHz |
|
|
|
|
|
|
|
|
|
Conversion Time |
|
|
65 |
|
260 |
µs |
|
|
|
|
|
|
|
|
AVCC |
Analog Supply Voltage |
|
|
VCC - 0.3(2) |
|
VCC + 0.3(3) |
|
VREF |
Reference Voltage |
|
|
2.0 |
|
AVCC - 0.5 |
V |
VIN |
Input Voltage |
|
|
GND |
|
VCC |
|
|
|
|
|
||||
VDIFF |
Input Differential Voltage |
|
|
-VREF/Gain |
|
VREF/Gain |
|
|
ADC Conversion Output |
|
|
-511 |
|
511 |
LSB |
|
|
|
|
|
|
|
|
|
Input Bandwidth |
|
|
|
4 |
|
kHz |
|
|
|
|
|
|
|
|
326
2467X–AVR–06/11

ATmega128
Table 136. ADC Characteristics, Differential Channels (Continued)
Symbol |
Parameter |
Condition |
Min(1) |
Typ(1) |
Max(1) |
Units |
VINT |
Internal Voltage Reference |
|
2.3 |
2.56 |
2.7 |
V |
RREF |
Reference Input Resistance |
|
|
32 |
|
kΩ |
RAIN |
Analog Input Resistance |
|
55 |
100 |
|
MΩ |
Notes: 1. Values are guidelines only.
2.Minimum for AVCC is 2.7V.
3.Maximum for AVCC is 5.5V.
327
2467X–AVR–06/11