– 135 Powe rful Instructions – Most Single Clock Cy cle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-Chip 2-cycle Multiplier
• High Endurance Non-volatile Memory Segments
– 64K/128K/256K Bytes of In-System Self-Programmable Flash
– 4K Bytes EEPROM
– 8K Bytes Internal SRAM
– Write/Erase Cycles:10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/ 100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits
• In-System Programming by On-chip Boot Program
• True Read-While-Write Operation
– Programming Lock for Software Security
Endurance: Up to 64K Bytes Optional External Memory Space
• JTAG (IEEE std. 1149.1 compliant) Interface
– Boundary-scan Capabilities According to the JTAG Standard
– Extensive On-chip Debug Support
– Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
– Four 16-bit Timer/Counter with Separate Prescaler, Compare- and Capture Mode
– Real Time Counter with Separate Oscillator
– Four 8-bit PWM Channels
– Six/Twelve PWM Channels with Programmable Resolution from 2 to 16 Bits
(ATmega1281/2561, ATmega640/1280/2560)
– Output Compare Modulator
– 8/16-channel, 10-bit ADC (ATmega1281/2561, ATmega640/1280/2560)
– Two/Four Programmable Serial USART (ATmega1281/2561,ATmega640/1280/2560)
– Master/Slave SPI Serial Interface
– Byte Oriented 2-wire Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Pr ogrammab l e Brown-out Detection
– Internal Calibrated Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Redu ction, Power-save, Power-down, Standby,
Note:The large center pad underneath the QFN/MLF package is made of metal and internally con-
nected to GND. It should be soldered or glued to the board to ensure good mechanical stability. If
the center pad is left unconnected, the package might loosen from the board.
Typical values contained in this datasheet are based on simulations and characterization of
other AVR microcontrollers manufactured on the same process technology. Min. and Max values will be available after the device is characterized.
4
2549LS–AVR–08/07
2.Overview
PB7..0
PF7..0
PH7..0
PL7..0
The ATmega640/1280/1281/2560/2561 is a lo w-power CMOS 8-bit microcontrol ler based on the
AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the
ATmega640/1280/1281/2560/2561 achieves t hroughputs appr oaching 1 MIPS per MHz allowing
the system designer to optimize power consumption versus processing speed.
2.1Block Diagram
Figure 2-1.Block Diagram
ATmega640/1280/1281/2560/2561
VCC
Power
RESET
GND
XTAL1
XTAL2
PA7..0
PG5..0PORT G (6)
Supervision
POR / BOD &
RESET
Watchdog
Timer
Watchdog
Oscillator
Oscillator
Circuits /
Clock
Generation
PORT A (8)
PORT F (8)
JTAG
EEPROM
XRAM
PK7..0
PORT K (8)
A/D
Converter
Internal
Bandgap reference
CPU
SRAMFLASH
PJ7..0
PORT J (8)
Analog
Comparator
16bit T/C 3
16bit T/C 5
16bit T/C 4
16bit T/C 1
PE7..0
PORT E (8)
USART 0
USART 3
USART 1
PC7..0PORT C (8)
2549LS–AVR–08/07
NOTE:
Shaded parts only available
in the 100-pin version.
Complete functionality for
the ADC, T/C4, and T/C5 only
available in the 100-pin version.
TWISPI
PORT D (8)
PD7..0
PORT B (8)
8bit T/C 08bit T/C 2
PORT H (8)
USART 2
PORT L (8)
5
ATmega640/1280/1281/2560/2561
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 ATmega640/1280/1281/2560/2561 provides the following features: 64K/ 128K/256K bytes of
In-System Programmable Flash with Read-While-Write capabilities, 4K bytes EEPROM, 8K
bytes SRAM, 54/86 general purpose I/O lines, 32 general purpose working registers, Real Time
Counter (RTC), six flexible Timer/Counters with compare modes and PWM, 4 USARTs, a byte
oriented 2-wire Serial Interface, a 16-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 Powersave 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 Onchip 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 ATmega640/1280/1281/2560/2561 is a powerful microcontroller that provides a highly
flexible and cost effective solution to many embedded control applications.
The ATmega640/1280/1281/2560/2561 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.
6
2549LS–AVR–08/07
ATmega640/1280/1281/2560/2561
2.2Comparison Between ATmega1281/2561 and ATmega640/1280/2560
Each device in the ATmega640/1280/1281/2560/2561 family differs only in memory size and
number of pins. Table 2-1 summarizes the different configurations for the six devices.
Port A is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port A output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port A pins are tri-stated when a reset co ndition becomes active,
even if the clock is not running.
ADC
Channels
Port A also serves the functions of various special features of the
ATmega640/1280/1281/2560/2561 as listed on page 78.
2.3.4Port B (PB7..PB0)
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port B output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port B pins are tri-stated when a reset co ndition becomes active,
even if the clock is not running.
Port B has better driving capabilities than the other ports.
Port B also serves the functions of various special features of the
ATmega640/1280/1281/2560/2561 as listed on page 79.
2.3.5Port C (PC7..PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port C output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up
2549LS–AVR–08/07
7
ATmega640/1280/1281/2560/2561
resistors are activated. The Port C pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port C also serves the functions of special features of the ATmega640/1280/1281/2560/2561 as
listed on page 82.
2.3.6Port D (PD7..PD0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port D output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port D pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port D also serves the functions of various special features of the
ATmega640/1280/1281/2560/2561 as listed on page 83.
2.3.7Port E (PE7..PE0)
Port E is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port E output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port E pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port E pins are tri-stated when a reset co ndition becomes active,
even if the clock is not running.
Port E also serves the functions of various special features of the
ATmega640/1280/1281/2560/2561 as listed on page 86.
2.3.8Port F (PF7..PF0)
Port F serves as analog inputs to the A/D Converter.
Port F also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins
can provide internal pull-up resistors (selected for each bit) . The Por t F outpu t buffers ha ve symmetrical drive characteristics with both high sink and source capability. As inputs, Port F pins
that are externally pulled low will source current if the pull-up resistors are activated. The Port F
pins are tri-stated when a res et cond ition beco mes a ctive, ev en if th e clock is not ru nning. 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.
Port F also serves the functions of the JTAG interface.
2.3.9Port G (PG5..PG0)
Port G is a 6-bit I/O port with internal pull-up resistors (selected for each bit). The Port G output
buffers have symmetrical drive characteristics with both high sink and source capability. As
inputs, Port G pins that are externally pulled low will source current if the pull-up resistors are
activated. The Port G pins are tri-stated when a reset condition becomes active, even if the clock
is not running.
Port G also serves the functions of various special features of the
ATmega640/1280/1281/2560/2561 as listed on page 90.
2.3.10Port H (PH7..PH0)
Port H is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port H output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port H pins that are externally pulled low will source current if the pull-up
8
2549LS–AVR–08/07
resistors are activated. The Port H pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port H also serves the functions of various special features of the ATmega640/1280/2560 as
listed on page 92.
2.3.11Port J (PJ7..PJ0)
Port J is a 8-bit bi-directional I/O port with internal pull-up re sistors (selected for each bit). The
Port J output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port J pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port J pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port J also serves the functions of various special features of the ATmega640/1280/2560 as
listed on page 95.
2.3.12Port K (PK7..PK0)
Port K serves as analog inputs to the A/D Converter.
Port K is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port K output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port K pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port K pins are tri-stated when a reset co ndition becomes active,
even if the clock is not running.
ATmega640/1280/1281/2560/2561
Port K also serves the functions of various special features of the ATmega640/1280/2560 as
listed on page 96.
2.3.13Port L (PL7..PL0)
Port L is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port L output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port L pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port L pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port L also serves the functions of various special features of the ATmega 640/1280/2560 as
listed on page 98.
2.3.14RESET
Reset input. A low level on this pin for longer than the minimum pulse length will generate a
reset, even if the clock is not running. The minimum pulse length is given in “System and Reset
Characteristics” on page 375. Shorter pulses are not guaranteed to generate a reset.
2.3.15XTAL1
Input to the inverting Oscillator amplifier and input to the internal clock operating circuit.
2.3.16XTAL2
Output from the inverting Oscillator amplifier.
2549LS–AVR–08/07
9
ATmega640/1280/1281/2560/2561
2.3.17AVCC
2.3.18AREF
3.Resources
4.Data Retention
AVCC is the supply voltage pin for Port F and the A/D Converter. It should be externally connected to V
through a low-pass filter.
This is the analog reference pin for the A/D Converter.
A comprehensive set of development tools and application notes, and datasheets are available
for download on http://www.atmel.com/avr.
Reliability Qualification results show that the projected data retention failure rate is much less
than 1 PPM over 20 years at 85°C or 100 years at 25°C.
, even if the ADC is not used. If the ADC is used, it should be connected to V
Notes:1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addre s ses
should never be written.
2. I/O registers within the address range $00 - $1F are directly bit-accessible using the SBI and CBI instru ctions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions.
3. Some of the status flags are cleared by writing a logical one to them. Note that the CBI and SBI instructions will operate on
all bits in the I/O register, writing a one back into any flag read as set, thus clearing the flag. The CBI and SBI instructions
work with registers 0x00 to 0x1F on ly.
4. When using the I/O specific commands IN and OUT , the I/O addresses $00 - $3F must be used. When addressing I/O registers as data space using LD and ST instructions, $20 must be added to these addresses. The
ATmega640/1280/1281/2560/2561 is a complex microcontroller with more peripheral units than can be supported within
the 64 location reserved in Opcode for the IN and OUT instructions. For the Extended I/O space from $60 - $1FF in SRAM,
only the ST/STS/STD and LD/LDS/LDD instructions can be used.
-----OCF0BOCF0ATOV0page 134
--PORTG5PORTG4PORTG3PORTG2PORTG1PORTG0page 102
2549LS–AVR–08/07
15
ATmega640/1280/1281/2560/2561
6.Instruction Set Summary
MnemonicsOperandsDescriptionOperationFlags#Clocks
ARITHMETIC AND LOGIC INSTRUCTIONS
ADDRd, RrAdd two RegistersRd ← Rd + RrZ,C,N,V,H1
ADCRd, RrAdd with Carry two RegistersRd ← Rd + Rr + CZ,C,N,V,H1
ADIWRdl,KAdd Immediate to WordRdh:Rdl ← Rdh:Rdl + KZ,C,N,V,S2
SUBRd, RrSubtract two RegistersRd ← Rd - RrZ,C,N,V,H1
SUBIRd, KSubtract Constant from Register Rd ← Rd - KZ,C,N,V,H1
SBCRd, RrSubtract with Carry two RegistersRd ← Rd - Rr - CZ,C,N,V,H1
SBCIRd, KSubtract with Carry Constant from Reg.Rd ← Rd - K - CZ,C,N,V,H1
SBIWRdl,KSubtract Immediate from WordRdh:Rdl ← Rdh:Rdl - KZ,C,N,V,S2
ANDRd, RrLogical AND RegistersRd ← Rd • RrZ,N,V1
ANDIRd, KLogical AND Register and Con s tantRd ← Rd • KZ,N,V1
ORRd, RrLogical OR RegistersRd ← Rd v RrZ,N,V1
ORIRd, KLogical OR Register and ConstantRd ← Rd v KZ,N,V1
EORRd, RrExclusive OR RegistersRd ← Rd ⊕ RrZ,N,V1
COMRdOne’s ComplementRd ← 0xFF − RdZ,C,N,V1
NEGRdTwo’s ComplementRd ← 0x00 − RdZ,C,N,V,H1
SBRRd,KSet Bit(s) in RegisterRd ← Rd v KZ,N,V1
CBRRd,KClear Bit(s) in RegisterRd ← Rd • (0xFF - K)Z,N,V1
INCRdIncrementRd ← Rd + 1Z,N,V1
DECRdDecrementRd ← Rd − 1 Z,N,V1
TSTRdTest for Zero or MinusRd ← Rd • Rd Z,N,V1
CLRRdClear RegisterRd ← Rd ⊕ RdZ,N,V1
SERRdSet RegisterRd ← 0xFFNone1
MULRd, RrMultiply UnsignedR1:R0 ← Rd x RrZ,C2
MULSRd, RrMultiply SignedR1:R0 ← Rd x RrZ,C2
MULSURd, RrMultiply Signed with UnsignedR1:R0 ← Rd x RrZ,C2
FMULRd, RrFractional Multiply UnsignedR1:R0 ← (Rd x Rr) << 1Z,C2
FMULSRd, RrFracti onal Multiply SignedR1:R0 ← (Rd x Rr) << 1Z,C2
FMULSURd, RrFractional Multiply Signed with UnsignedR1:R0 ← (Rd x Rr) << 1Z,C2
BRANCH INSTRUCTIONS
RJMPkRelative JumpPC ← PC + k + 1None2
IJMPIndirect Jump to (Z)PC ← Z None2
EIJMPExtended Indirect Jump to (Z)
JMPkDirect JumpPC ← kNone3
RCALLkRelative Subroutine Call PC ← PC + k + 1None4
ICALLIndirect Call to (Z)PC ← ZNone4
EICALLExtended Indirect Call to (Z)
CALLkDirect Subroutine Call PC ← kNone5
RETSubroutine ReturnPC ← STACKNone5
RETIInterrupt ReturnPC ← STACKI5
CPSERd,RrCompare, Skip if Equalif (Rd = Rr) PC ← PC + 2 or 3None1/2/3
CPRd,RrCompareRd − RrZ, N,V,C,H1
CPCRd,RrCo mpare with CarryRd − Rr − CZ, N,V,C,H1
CPIRd,KCom pare Register with ImmediateRd − KZ, N,V,C,H1
SBRCRr, bSkip if Bit in Register Clearedif (Rr(b)=0) PC ← PC + 2 or 3 None1/2/3
SBRSRr, bSkip if Bit in Register is Setif (Rr(b)=1) PC ← PC + 2 or 3None1/2/3
SBICP, bSkip if Bit in I/O Register Clearedif (P(b)=0) PC ← PC + 2 or 3 None1/2/3
SBISP, bSkip if Bit in I/O Register is Setif (P(b)=1) PC ← PC + 2 or 3None1/2/3
BRBSs, kBranch if Status Flag Setif (SREG(s) = 1) then PC←PC+k + 1None1/2
BRBCs, kBranch if Status Flag Clearedif (SREG(s) = 0) then PC←PC+k + 1None1/2
BREQ kBranch if Equal if (Z = 1) then PC ← PC + k + 1None1/ 2
BRNE kBranch if Not Equalif (Z = 0) then PC ← PC + k + 1None1/2
BRCS kBranch if Carry Setif (C = 1) then PC ← PC + k + 1None1/2
BRCC kBranch if Carry Clearedif (C = 0) then PC ← PC + k + 1None1/2
BRSH kBranch if Same or Higher if (C = 0) then PC ← PC + k + 1None1/2
BRLO kBranch if Lowerif (C = 1) then PC ← PC + k + 1None1/2
BRMI kBranch if Minusif (N = 1) then PC ← PC + k + 1None1/2
BRPL kBranch if Plus if (N = 0) then PC ← PC + k + 1None1/2
BRGE kBranch if Greater or Equal, Signedif (N ⊕ V= 0) then PC ← PC + k + 1Non e1/2
BRLT kBranch if Less Than Zero, Signedif (N ⊕ V= 1) then PC ← PC + k + 1None1/2
BRHS kBranch if Half Carry Flag Setif (H = 1) then PC ← PC + k + 1None1/2
BRHC kBranch if Half Carry Flag Clearedif (H = 0) then PC ← PC + k + 1None1/2
BRTS kBranch if T Flag Setif (T = 1) then PC ← PC + k + 1None1/2
BRTC kBranch if T Flag Clearedif (T = 0) then PC ← PC + k + 1None1/2
PC ←(EIND:Z)
PC ←(EIND:Z)
None2
None4
16
2549LS–AVR–08/07
ATmega640/1280/1281/2560/2561
MnemonicsOperandsDescriptionOperationFlags#Clocks
BRVS kBranch if Overflow Flag is Setif (V = 1) then PC ← PC + k + 1N one1/2
BRVC kBranch if Overflow Flag is Clearedif (V = 0) then PC ← PC + k + 1None1/2
BRIE kBranch if Interrupt Enabledif ( I = 1) then PC ← PC + k + 1None1/2
BRID kBranch if Interrupt Disabledif ( I = 0) then PC ← PC + k + 1None1/2
BIT AND BIT-TEST INSTRUCTIONS
SBIP,bSet Bit in I/O RegisterI/O(P,b) ← 1None2
CBIP,bClear Bit in I/O RegisterI/O(P,b) ← 0None2
LSLRdLogical Shift LeftRd(n+1) ← Rd(n), Rd(0) ← 0Z,C,N,V1
LSRRdLogical Shift RightRd(n) ← Rd(n+1), Rd(7) ← 0Z,C,N,V1
ROLRdRotate Left Through CarryRd(0)←C,Rd(n+1)← Rd(n),C←Rd(7)Z,C,N,V1
RORRdRotate Right Through CarryRd(7)←C,Rd(n)← Rd(n+1),C←Rd(0)Z,C,N,V1
ASRRdArithmetic Shift RightRd(n) ← Rd(n+1), n=0..6Z,C,N,V1
SWAPRdSwap NibblesRd(3..0)←Rd(7..4),Rd(7..4)←Rd(3..0)None1
BSETsFlag SetSREG(s) ← 1SREG(s)1
BCLRsFlag ClearSREG(s) ← 0 SREG(s)1
BSTRr, bBit Store from Register to TT ← Rr(b)T1
BLDRd, bBit load from T to RegisterRd(b) ← TNone1
SECSet CarryC ← 1C1
CLCClear CarryC ← 0 C1
SENSet Negative FlagN ← 1N1
CLNClear Negative FlagN ← 0 N1
SEZSet Zero FlagZ ← 1Z1
CLZClear Zero FlagZ ← 0 Z1
SEIGlobal Interrupt EnableI ← 1I1
CLIGlobal Interrupt DisableI ← 0 I1
SESSet Signed Test FlagS ← 1S1
CLSClear Signed Test FlagS ← 0 S1
SEVSet Twos Complement Overflow.V ← 1V1
CLVClear Twos Complement OverflowV ← 0 V1
SETSet T in SREGT ← 1T1
CLTClear T in SREGT ← 0 T1
SEHSet Half Carry Flag in SREGH ← 1H1
CLHClear Half Carry Flag in SREGH ← 0 H1
DATA TRANSFER INSTRUCTIONS
MOVRd, RrMove Between RegistersRd ← RrNone1
MOVWRd, RrCopy Register Word
LDIRd, KLoad ImmediateRd ← KNone1
LDRd, XLoad IndirectRd ← (X)None2
LDRd, X+Load Indirect and Post-Inc.Rd ← (X), X ← X + 1None2
LDRd, - XLoad Indirect and Pre-Dec.X ← X - 1, Rd ← (X)None2
LDRd, YLoad IndirectRd ← (Y)None2
LDRd, Y+Load Indirect and Post-Inc.Rd ← (Y), Y ← Y + 1None2
LDRd, - YLoad Indirect and Pre-Dec.Y ← Y - 1, Rd ← (Y)None2
LDDRd,Y+qLoad Indirect with DisplacementRd ← (Y + q)None2
LDRd, ZLoad Indirect Rd ← (Z)None2
LDRd, Z+Load Indirect and Post-Inc.Rd ← (Z), Z ← Z+1None2
LDRd, -ZLoad Indirect and Pre-Dec.Z ← Z - 1, Rd ← (Z)None2
LDDRd, Z+qLoad Indirect with DisplacementRd ← (Z + q)None2
LDSRd, kLoad Direc t from SRAMRd ← (k)None2
STX, RrStore Indirect(X) ← RrNone2
STX+, RrStore Indirect and Post-Inc.(X) ← Rr, X ← X + 1None2
ST- X, RrStore Indirect and Pre-Dec.X ← X - 1, (X) ← RrNone2
STY, RrStore Indirect(Y) ← RrNone2
STY+, RrStore Indirect and Post-Inc.(Y) ← Rr, Y ← Y + 1None2
ST- Y, RrStore Indirect and Pre-Dec.Y ← Y - 1, (Y) ← RrNone2
STDY+q,RrStore Indirect with Displacement(Y + q) ← RrNone2
STZ, RrStore Indirect(Z) ← RrNone2
STZ+, RrStore Indirect and Post-Inc.(Z) ← Rr, Z ← Z + 1None2
ST-Z, RrStore Indirect and Pre-Dec.Z ← Z - 1, (Z) ← RrNone2
STDZ+q,RrStore Indirect with Displaceme nt(Z + q) ← RrNone2
STSk, RrStore Direct to SRAM(k) ← RrNone2
LPMLoad Program MemoryR0 ← (Z)None3
LPMRd, ZLoad Progra m MemoryRd ← (Z)None3
LPMRd, Z+Load Program Memory and Post-IncRd ← (Z), Z ← Z+1None3
ELPMExtended Load Program MemoryR0 ← (RAMPZ:Z)None3
ELPMRd, ZExtended Load Program MemoryRd ← (RAMPZ:Z)None3
Rd+1:Rd ← Rr+1:Rr
None1
2549LS–AVR–08/07
17
ATmega640/1280/1281/2560/2561
MnemonicsOperandsDescriptionOperationFlags#Clocks
ELPMRd, Z+Extended Load Program MemoryRd ← (RAMPZ:Z), RAMPZ:Z ←RAMPZ:Z+1None3
SPMStore Program Memory(Z) ← R1:R0NoneINRd, PIn PortRd ← PNone1
OUTP, RrOut PortP ← RrNone1
PUSHRrPush Register on StackSTACK ← RrNone2
POPRdPop Register from StackRd ← STACKNone2
MCU CONTROL INSTRUCTIONS
NOPNo OperationNone1
SLEEPSleep(see specific descr. for Sleep function)None1
WDRWatchdog Reset(see specific descr. for WDR/timer)None1
BREAKBreakFor On-chip Debug OnlyNoneN/A
Note:EICALL and EIJMP do not exist in ATmega640/1280/1281.
ELPM does not exist in ATmega640.
18
2549LS–AVR–08/07
ATmega640/1280/1281/2560/2561
7.Ordering Information
7.1ATmega640
Speed (MHz)
Notes:1. This device can also be supplied in wafer form. Please contact your local Atmel sales office for detailed ordering information
(2)
Power SupplyOrdering CodePackage
81.8 - 5.5V
162.7 - 5.5V
and minimum quantities.
2. See “Speed Grades” on page 372
3. Pb-free packaging, complies to the European Directive for Restriction of Hazardous Substances (RoHS directive). Also
Halide free and fully Green.
Notes:1. This package conforms to JEDEC reference MS-026, Variation AED.
2. Dimensions D1 and E1 do not include mold protrusion. Allowable
protrusion is 0.25 mm per side. Dimensions D1 and E1 are maximum
plastic body size dimensions including mold mismatch.
3. Lead coplanarity is 0.08 mm maximum.
A2A
SYMBOL
COMMON DIMENSIONS
(Unit of Measure = mm)
MIN
A––1.20
A10.05–0.15
A2 0.951.001.05
D15.7516.0016.25
D113.9014.0014.10Note 2
E15.7516.0016.25
E113.9014.0014.10Note 2
B 0.17–0.27
C0.09–0.20
L0.45– 0.75
e0.50 TYP
NOM
MAX
NOTE
2325 Orchard Parkway
R
San Jose, CA 95131
100A, 100-lead, 14 x 14 mm Body Size, 1.0 mm Body Thickness,
0.5 mm Lead Pitch, Thin Profile Plastic Quad Flat Package (TQFP)
16
TITLE
10/5/2001
DRAWING NO.
100A
2549LS–AVR–08/07
REV.
C
8.2100C1
E
Marked A1 Identifier
ATmega640/1280/1281/2560/2561
0.12
Z
0.90 TYP
0.90 TYP
D
TOP VIEW
SIDE VIEW
A
A1
e
10
9
A
B
C
D
E
F
G
e
H
I
J
678
5
E1
Øb
A1 Corner
1
2
4
3
COMMON DIMENSIONS
D1
SYMBOL
A 1.10 – 1.20
A1 0.30 0.35 0.40
D 8.90 9.00 9.10
E 8.90 9.00 9.10
(Unit of Measure = mm)
MIN
NOM
MAX
NOTE
D1 7.10 7.20 7.30
E1 7.10 7.20 7.30
BOTTOM VIEW
Øb 0.35 0.40 0.45
e 0.80 TYP
2325 Orchard Parkway
R
San Jose, CA 95131
2549LS–AVR–08/07
TITLE
100C1, 100-ball, 9 x 9 x 1.2 mm Body, Ball Pitch 0.80 mm
Chip Array BGA Package (CBGA)
DRAWING NO.
100C1
5/25/06
REV.
A
17
ATmega640/1280/1281/2560/2561
8.364A
PIN 1
B
PIN 1 IDENTIFIER
e
E1E
D1
D
C
0°~7°
A1
L
Notes:
1.This package conforms to JEDEC reference MS-026, Variation AEB.
2. Dimensions D1 and E1 do not include mold protrusion. Allowable
protrusion is 0.25 mm per side. Dimensions D1 and E1 are maximum
plastic body size dimensions including mold mismatch.
3. Lead coplanarity is 0.10 mm maximum.
A2A
SYMBOL
COMMON DIMENSIONS
(Unit of Measure = mm)
MIN
A – – 1.20
A1 0.05 – 0.15
A2 0.95 1.00 1.05
D 15.75 16.00 16.25
D1 13.90 14.00 14.10 Note 2
E 15.75 16.00 16.25
E1 13.90 14.00 14.10 Note 2
B 0.30 – 0.45
C 0.09 – 0.20
L 0.45 – 0.75
e 0.80 TYP
NOM
MAX
NOTE
2325 Orchard Parkway
R
San Jose, CA 95131
64A, 64-lead, 14 x 14 mm Body Size, 1.0 mm Body Thickness,
0.8 mm Lead Pitch, Thin Profile Plastic Quad Flat Package (TQFP)
18
TITLE
10/5/2001
DRAWING NO.
64A
2549LS–AVR–08/07
REV.
B
8.464M2
D
Marked Pin# 1 ID
ATmega640/1280/1281/2560/2561
E
SEATING PLANE
C
TOP VIEW
K
L
D2
1
2
3
E2
K
b
e
BOTTOM VIEW
1. JEDEC Standard MO-220, (SAW Singulation) Fig. 1, VMMD.
Note:
2. Dimension and tolerance conform to ASMEY14.5M-1994.
TITLE
2325 Orchard Parkway
R
San Jose, CA 95131
64M2, 64-pad, 9 x 9 x 1.0 mm Body, Lead Pitch 0.50 mm,
7.65 mm Exposed Pad, Micro Lead Frame Package (MLF)
Pin #1 Corner
Option A
Option B
Option C
Pin #1
Triangle
Pin #1
Chamfer
(C 0.30)
Pin #1
Notch
(0.20 R)
A1
A
0.08
C
SIDE VIEW
COMMON DIMENSIONS
(Unit of Measure = mm)
SYMBOL
A 0.80 0.90 1.00
A1 – 0.02 0.05
b 0.180.250.30
D
D2 7.507.657.80
E
E2 7.507.657.80
e 0.50 BSC
L0.35 0.40 0.45
K0.200.270.40
MIN
8.909.009.10
8.909.009.10
NOM
MAX
DRAWING NO.
64M2
NOTE
5/25/06
REV.
D
2549LS–AVR–08/07
19
ATmega640/1280/1281/2560/2561
9.Errata
9.1ATmega640 rev. A
• Inaccurate ADC conversion in differential mode with 200x gain
• High current consumption in sleep mode
1. Inaccurate ADC conversion in differential mode with 200x gain
With AVCC < 3.6V, random conversions will be inaccurate. Typical absolute accuracy may
reach 64 LSB.
Problem Fix/Workaround
None
2. High current consumption in sleep mode.
If a pending interrupt cannot wake the part up from the selected sleep mode, the current
consumption will increase during sleep when executing the SLEEP instruction directly after
a SEI instruction.
Problem Fix/Workaround
Before entering sleep, interrupts not used to wake the part from the sleep mode should be
disabled.
9.2ATmega1280 rev. A
• Inaccurate ADC conversion in differential mode with 200x gain
• High current consumption in sleep mode
1. Inaccurate ADC conversion in differential mode with 200x gain
With AVCC < 3.6V, random conversions will be inaccurate. Typical absolute accuracy may
reach 64 LSB.
Problem Fix/Workaround
None
2. High current consumption in sleep mode.
If a pending interrupt cannot wake the part up from the selected sleep mode, the current
consumption will increase during sleep when executing the SLEEP instruction directly after
a SEI instruction.
Problem Fix/Workaround
Before entering sleep, interrupts not used to wake the part from the sleep mode should be
disabled.
9.3ATmega1281 rev. A
• Inaccurate ADC conversion in differential mode with 200x gain
• High current consumption in sleep mode
1. Inaccurate ADC conversion in differential mode with 200x gain
With AVCC < 3.6V, random conversions will be inaccurate. Typical absolute accuracy may
reach 64 LSB.
Problem Fix/Workaround
None
20
2549LS–AVR–08/07
2. High current consumption in sleep mode.
If a pending interrupt cannot wake the part up from the selected sleep mode, the current
consumption will increase during sleep when executing the SLEEP instruction directly after
a SEI instruction.
Problem Fix/Workaround
Before entering sleep, interrupts not used to wake the part from the sleep mode should be
disabled.
9.4ATmega2560 rev. E
No known errata.
9.5ATmega2560 rev. D
Not sampled.
9.6ATmega2560 rev. C
• High current consumption in sleep mode
1. High current consumption in sleep mode.
If a pending interrupt cannot wake the part up from the selected sleep mode, the current
consumption will increase during sleep when executing the SLEEP instruction directly after
a SEI instruction.
ATmega640/1280/1281/2560/2561
Problem Fix/Workaround
Before entering sleep, interrupts not used to wake the part from the sleep mode should be
disabled.
9.7ATmega2560 rev. B
Not sampled.
9.8ATmega2560 rev. A
• Non-Read-While-Write area of flash not functional
• Part does not work under 2.4 volts
• Incorrect ADC reading in differential mode
• Internal ADC reference has too low value
• IN/OUT instructions may be executed twice when Stack is in external RAM
• EEPROM read from application code does not work in Lock Bit Mode 3
1. Non-Read-While-Write area of flash not functional
The Non-Read-While-Write area of the flash is not w orking as expected. The problem is
related to the speed of the part when reading the flash of this area.
Problem Fix/Workaround
- Only use the first 248K of the flash.
- If boot functionality is needed, run the code in the Non-Read-While-Write area at maximum
1/4th of the maximum frequency of the device at any given voltage. This is done by writing
the CLKPR register before entering the boot section of the code
2549LS–AVR–08/07
2. Part does not work under 2.4 volts
The part does not execute code correctly below 2.4 volts
21
ATmega640/1280/1281/2560/2561
Problem Fix/Workaround
Do not use the part at voltages below 2.4 volts.
3. Incorrect ADC reading in differential mode
The ADC has high noise in differential mode. It can give up to 7 LSB error.
Problem Fix/Workaround
Use only the 7 MSB of the result when using the ADC in differential mode.
4. Internal ADC reference has too low value
The internal ADC reference has a value lower than specified
Problem Fix/Workaround
- Use AVCC or external reference
- The actual value of the reference can be measured by applying a known voltage to the
ADC when using the internal reference. The result when doin g later conver sions can then be
calibrated.
5. IN/OUT instructions may be executed twice when Stack is in external RAM
If either an IN or an OUT instruction is executed directly before an interrupt occurs and the
stack pointer is located in external ram, the instruction will be executed twice. In some cases
this will cause a problem, for example:
- If reading SREG it will appear that the I-flag is cleared.
- If writing to the PIN registers, the port will toggle twice.
- If reading registers with interrupt flags, the flags will appear to be cleared.
Problem Fix/Workaround
There are two application work-arounds, where selecting one of them, will be omitting the
issue:
- Replace IN and OUT with LD/LDS/LDD and ST/STS/STD instructions
- Use internal RAM for stack pointer.
6. EEPROM read from application code does not work in Lock Bit Mode 3
When the Memory Lock Bits LB2 and LB1 are programmed to mode 3, EEPROM read does
not work from the application code.
Problem Fix/Workaround
Do not set Lock Bit Protection Mode 3 when the application code needs to rea d from
EEPROM.
9.9ATmega2561 rev. E
No known errata.
9.10ATmega2561 rev. D
Not sampled.
22
2549LS–AVR–08/07
9.11ATmega2561 rev. C
• High current consumption in sleep mode
1. High current consumption in sleep mode.
If a pending interrupt cannot wake the part up from the selected sleep mode, the current
consumption will increase during sleep when executing the SLEEP instruction directly after
a SEI instruction.
Problem Fix/Workaround
Before entering sleep, interrupts not used to wake the part from the sleep mode should be
disabled.
9.12ATmega2561 rev. B
Not sampled.
9.13ATmega2561 rev. A
• Non-Read-While-Write area of flash not functional
• Part does not work under 2.4 Volts
• Incorrect ADC reading in differential mode
• Internal ADC reference has too low value
• IN/OUT instructions may be executed twice when Stack is in external RAM
• EEPROM read from application code does not work in Lock Bit Mode 3
ATmega640/1280/1281/2560/2561
1. Non-Read-While-Write area of flash not functional
The Non-Read-While-Write area of the flash is not w orking as expected. The problem is
related to the speed of the part when reading the flash of this area.
Problem Fix/Workaround
- Only use the first 248K of the flash.
- If boot functionality is needed, run the code in the Non-Read-While-Write area at maximum
1/4th of the maximum frequency of the device at any given voltage. This is done by writing
the CLKPR register before entering the boot section of the code.
2549LS–AVR–08/07
23
ATmega640/1280/1281/2560/2561
2. Part does not work under 2.4 volts
The part does not execute code correctly below 2.4 volts
Problem Fix/Workaround
Do not use the part at voltages below 2.4 volts.
3. Incorrect ADC reading in differential mode
The ADC has high noise in differential mode. It can give up to 7 LSB error.
Problem Fix/Workaround
Use only the 7 MSB of the result when using the ADC in differential mode
4. Internal ADC reference has too low value
The internal ADC reference has a value lower than specified
Problem Fix/Workaround
- Use AVCC or external reference
- The actual value of the reference can be measured by applying a known voltage to the
ADC when using the internal reference. The result when doin g later conver sions can then be
calibrated.
5. IN/OUT instructions may be executed twice when Stack is in external RAM
If either an IN or an OUT instruction is executed directly before an interrupt occurs and the
stack pointer is located in external ram, the instruction will be executed twice. In some cases
this will cause a problem, for example:
- If reading SREG it will appear that the I-flag is cleared.
- If writing to the PIN registers, the port will toggle twice.
- If reading registers with interrupt flags, the flags will appear to be cleared.
Problem Fix/Workaround
There are two application workarounds, where selecting one of them, will be omitting the
issue:
- Replace IN and OUT with LD/LDS/LDD and ST/STS/STD instructions
- Use internal RAM for stack pointer.
6. EEPROM read from application code does not work in Lock Bit Mode 3
When the Memory Lock Bits LB2 and LB1 are programmed to mode 3, EEPROM read does
not work from the application code.
Problem Fix/Workaround
Do not set Lock Bit Protection Mode 3 when the application code needs to rea d from
EEPROM.
24
2549LS–AVR–08/07
10. Datasheet Revision History
Please note that the referring page numbers in this section are referring to this document.The
referring revision in this section are referring to the document revision.
10.1Rev. 2549L-08/07
1.Updated note in Table 10-10 on page 47.
2.Updated Table 10-3 on page 42, Table 10-5 on page 43, Table 10-8 on page
46.
3.Updated typos in “DC Characteristics” on page 370.
4.Updated “Clock Characteristics” on page 374.
5.Updated “External Clock Drive” on page 374.
6.Added “System and Reset Characteristics” on page 375.
7.Updated “SPI Timing Characteristics” on page 377.
8.Updated “ADC Characteristics – Preliminary Data” on page 379.
9.Updated ordering code in “ATmega640” on page 19.
7.Updated Bit description in “PCIFR – Pin Change Interrupt Flag Register”
8.Updated code example in “USART Initialization” on page 211.
9.Updated Figure 26-8 on page 284.
10.Updated “DC Characteristics” on page 370.
10.3Rev. 2549J-09/06
after setting the ACBG bit or enabling the ADC, the user must always
allow the reference to start up before the output from the An alog Comparator or ADC is used. To reduce power consumption in Power-down mode,
the user can avoid the three conditions abo ve to ensur e that the refer ence
is turned off before entering Power-down mode” on page 63.
on page 116.
2549LS–AVR–08/07
1.Updated “Calibrated Internal RC Oscillator” on page 46.
2.Updated code example in “Moving Interrupts Between Application and
Boot Section” on page 109.
3.Updated “Timer/Counter Prescaler” on page 187.
25
ATmega640/1280/1281/2560/2561
4.Updated “Device Identifica tion Register” on page 304.
5.Updated “Signature Bytes” on page 340.
6.Updated “Instruction Set Summary” on page 419.
10.4Rev. 2549I-07/06
1.Added “Data Retention” on page 10.
2.Updated Table 16-3 on page 129, Table 16-6 on page 130, Table 16-8 on
3.Updated “Fast PWM Mode” on page 150.
10.5Rev. 2549H-06/06
1.Updated “Calibrated Internal RC Oscillator” on page 46.
2.Updated “OSCCAL – Oscillator Calibration Register” on page 50.
3.Added Table 31-1 on page 374.
10.6Rev. 2549G-06/06
page 131, Table 17-2 on page 148, Table 17-4 on page 160, Table 17-5 on
page 160, Table 20-3 on page 188, Table 20-6 on page 189 and Table 20-8
on page 190.
1.Updated “Features” on page 1.
2.Added Figure 1-2 on page 3, Table 1-1 on page 3.
3.Updated “Calibrated Internal RC Oscillator” on page 46.
4.Updated “Power Management and Sleep Modes” on page 52.
5.Updated note for Table 12-1 on page 68.
6.Updated Figure 26-9 on page 285 and Figure 26-10 on page 285.
7.Updated “Setting the Boot Loader Lock Bits by SPM” on page 325.
8.Updated “Ordering Information” on page 19.
9.Added Package information “100C1” on page 25.
10.Updated “Errata” on page 28.
10.7Rev. 2549F-04/06
1.Updat ed Figure 9-3 on page 29, Figure 9-4 on page 30 and Figure 1 on
2.Updated Table 20-2 on page 188 and Table 20-3 on page 188.
3.Updated Features in “ADC – Analog to Digital Converter” on page 275.
4.Updated “Fuse Bits” on page 338.
page 30.
26
2549LS–AVR–08/07
10.8Rev. 2549E-04/06
1.Updated “Features” on page 1.
2.Updated Table 12-1 on page 62.
3.Updated note for Table 12-1 on page 62.
4.Updated “Bit 6 – ACBG: Analog Comparator Bandgap Select” on page
5.Updated “Prescaling and Conversion Timing” on page 278.
5.Updated “Maximum speed vs. V
6.Updated “Ordering Information” on page 19.
10.9Rev. 2549D-12/05
1.Advanced Information Status changed to Preliminary.
2.Changed number of I/O Ports from 51 to 54.
3.Updatet typos in “TCCR0A – Timer/Counter Control Register A” on page
4.Updated Features in “ADC – Analog to Digital Converter” on page 275.
5.Updated Operation in“ADC – Analog to Digital Converter” on page 275
6.Updated Stabilizing Time in “Changing Channel or Reference Selection”
7.Updated Figure 26-1 on page 276, Figure 26-9 on page 285, Figure 26-10
8.Updated Text in “ADCSRB – ADC Control and Status Register B” on page
9.Updated Note for T able 4 on page 42, T able 13-14 on page 86, Table 26-3
10.Updated Table 31-7 on page 379 and Table 31-8 on page 380.
11.Updated “Filling the Temporary Buffer (Page Loading)” on page 324.
12.Updated “Typical Characterist ic s” o n pag e 38 7 .
13.Updated “Packaging Information” on page 24.
14.Updated “Errata” on page 28.
ATmega640/1280/1281/2560/2561
272.
” on page 373.
CC
129.
on page 282.
on page 285.
291.
on page 290 and Table 26-6 on page 296.
10.10 Rev. 2549C-09/05
1.Updated Speed Grade in section “Features” on page 1.
2.Added “Resources” on page 10.
3.Upd ated “SPI – Serial Peripheral Interface” on page 196. In Slav e mode,
4.Updated “Bit Rate Generator Unit” on page 247.
5.Updated “Maximum speed vs. V
6.Updated “Ordering Information” on page 19.
7.Updated “Packaging Information” on page 24. Package 64M1 replaced by
8.Updated “Errata” on page 28.
2549LS–AVR–08/07
low and high period SPI clock must be larger than 2 CPU cycles.
” on page 373.
CC
64M2.
27
ATmega640/1280/1281/2560/2561
10.11 Rev. 2549B-05/05
1.JTAG ID/Signature for ATmega640 updated: 0x9608.
2.Updated Table 13-7 on page 81.
3.Updated “Serial Programming Instruction set” on page 354.
4.Updated “Errata” on page 28.
10.12 Rev. 2549A-03/05
1.Initial version.
28
2549LS–AVR–08/07
HeadquartersInternation al
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Room 1219
Chinachem Golden Plaza
77 Mody Road Tsimshatsui
East Kowloon
Hong Kong
Tel: (852) 2721-9778
Fax: (852) 2722-1369
Product Contact
Web Site
www.atmel.com
Literature Requests
www.atmel.com/literature
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054 Saint-Quentin-enYvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Technical Support
avr@atmel.com
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Sales Contact
www.atmel.com/contacts
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sa le of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-
TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENT AL DAMAGES (INCLUDING, WITHOUT LIMITATION, D AMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF
THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications
and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained here in. Unless specifically provided
otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to suppor t or sustain life.