Features * High-performance, Low-power Atmel(R) AVR(R) 8-bit Microcontroller * Advanced RISC Architecture * * * * * * * - 131 Powerful Instructions - Most Single-clock Cycle Execution - 32 x 8 General Purpose Working Registers - Fully Static Operation - Up to 20 MIPS Throughput at 20MHz High Endurance Non-volatile Memory segments - 64 Kbytes of In-System Self-programmable Flash program memory - 2 Kbytes EEPROM - 4 Kbytes Internal SRAM - Write/Erase cyles: 10,000 Flash/100,000 EEPROM(1)(3) - Data retention: 20 years at 85C/100 years at 25C(2)(3) - 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 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 Prescalers and Compare Modes - One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode - Real Time Counter with Separate Oscillator - Six PWM Channels - 8-channel, 10-bit ADC Differential mode with selectable gain at 1x, 10x or 200x - Byte-oriented Two-wire Serial Interface - One Programmable Serial USART - Master/Slave SPI 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 Programmable Brown-out Detection - Internal Calibrated RC Oscillator - External and Internal Interrupt Sources - Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and Extended Standby I/O and Packages - 32 Programmable I/O Lines - 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF Speed Grades - ATmega644V: 0 - 4MHz @ 1.8V - 5.5V, 0 - 10MHz @ 2.7V - 5.5V - ATmega644: 0 - 10MHz @ 2.7V - 5.5V, 0 - 20MHz @ 4.5V - 5.5V Power Consumption at 1MHz, 3V, 25C - Active: 240A @ 1.8V, 1MHz - Power-down Mode: 0.1A @ 1.8V Notes: 8-bit Atmel Microcontroller with 64K Bytes In-System Programmable Flash ATmega644/V 1. Worst case temperature. Guaranteed after last write cycle. 2. Failure rate less than 1 ppm. 3. Characterized through accelerated tests. 2593O-AVR-02/12 1. Pin Configurations Figure 1-1. Pinout ATmega644 PDIP (PCINT8/XCK0/T0) PB0 (PCINT9/CLKO/T1) PB1 (PCINT10/INT2/AIN0) PB2 (PCINT11/OC0A/AIN1) PB3 (PCINT12/OC0B/SS) PB4 (PCINT13/MOSI) PB5 (PCINT14/MISO) PB6 (PCINT15/SCK) PB7 RESET VCC GND XTAL2 XTAL1 (PCINT24/RXD0) PD0 (PCINT25/TXD0) PD1 (PCINT26/INT0) PD2 (PCINT27/INT1) PD3 (PCINT28/OC1B) PD4 (PCINT29/OC1A) PD5 (PCINT30/OC2B/ICP) PD6 PA0 (ADC0/PCINT0) PA1 (ADC1/PCINT1) PA2 (ADC2/PCINT2) PA3 (ADC3/PCINT3) PA4 (ADC4/PCINT4) PA5 (ADC5/PCINT5) PA6 (ADC6/PCINT6) PA7 (ADC7/PCINT7) AREF GND AVCC PC7 (TOSC2/PCINT23) PC6 (TOSC1/PCINT22) PC5 (TDI/PCINT21) PC4 (TDO/PCINT20) PC3 (TMS/PCINT19) PC2 (TCK/PCINT18) PC1 (SDA/PCINT17) PC0 (SCL/PCINT16) PD7 (OC2A/PCINT31) PB4 (SS/OC0B/PCINT12) PB3 (AIN1/OC0A/PCINT11) PB2 (AIN0/INT2/PCINT10) PB1 (T1/CLKO/PCINT9) PB0 (XCK0/T0/PCINT8) GND VCC PA0 (ADC0/PCINT0) PA1 (ADC1/PCINT1) PA2 (ADC2/PCINT2) PA3 (ADC3/PCINT3) TQFP/QFN/MLF (PCINT13/MOSI) PB5 (PCINT14/MISO) PB6 (PCINT15/SCK) PB7 RESET VCC GND XTAL2 XTAL1 (PCINT24/RXD0) PD0 (PCINT25/TXD0) PD1 (PCINT26/INT0) PD2 (PCINT27/INT1) (PCINT28/OC1B) (PCINT29/OC1A) (PCINT30/OC2B/ICP) (PCINT31/OC2A) PD3 PD4 PD5 PD6 PD7 VCC GND (PCINT16/SCL) PC0 (PCINT17/SDA) PC1 (PCINT18/TCK) PC2 (PCINT19/TMS) PC3 PA4 (ADC4/PCINT4) PA5 (ADC5/PCINT5) PA6 (ADC6/PCINT6) PA7 (ADC7/PCINT7) AREF GND AVCC PC7 (TOSC2/PCINT23) PC6 (TOSC1/PCINT22) PC5 (TDI/PCINT21) PC4 (TDO/PCINT20) Note: 2 The large center pad underneath the QFN/MLF package should be soldered to ground on the board to ensure good mechanical stability. ATmega644 2593O-AVR-02/12 ATmega644 1.1 Disclaimer 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. 2. Overview The ATmega644 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 ATmega644 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. 2.1 Block Diagram Figure 2-1. Block Diagram PA7..0 PB7..0 VCC RESET GND Power Supervision POR / BOD & RESET PORT A (8) PORT B (8) Watchdog Timer Watchdog Oscillator Analog Comparator A/D Converter USART 0 XTAL1 Oscillator Circuits / Clock Generation EEPROM Internal Bandgap reference SPI XTAL2 16 bit T/C 1 CPU JTAG TWI 8 bit T/C 0 FLASH SRAM 8 bit T/C 2 PORT C (8) PORT D (8) PC7..0 PD7..0 3 2593O-AVR-02/12 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 ATmega644 provides the following features: 64 Kbytes of In-System Programmable Flash with Read-While-Write capabilities, 2 Kbytes EEPROM, 4 Kbytes SRAM, 32 general purpose I/O lines, 32 general purpose working registers, Real Time Counter (RTC), three flexible Timer/Counters with compare modes and PWM, 2 USARTs, a byte oriented 2-wire Serial Interface, a 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 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 ATmega644 is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The ATmega644 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. 2.2 2.2.1 Pin Descriptions VCC Digital supply voltage. 2.2.2 GND Ground. 2.2.3 Port A (PA7:PA0) Port A serves as analog inputs to the Analog-to-digital Converter. Port A also serves as 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 4 ATmega644 2593O-AVR-02/12 ATmega644 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 condition becomes active, even if the clock is not running. Port A also serves the functions of various special features of the ATmega644 as listed on page 73. 2.2.4 Port 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 condition becomes active, even if the clock is not running. Port B also serves the functions of various special features of the ATmega644 as listed on page 75. 2.2.5 Port 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 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 the JTAG interface, along with special features of the ATmega644 as listed on page 78. 2.2.6 Port 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 ATmega644 as listed on page 80. 2.2.7 RESET 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 320. Shorter pulses are not guaranteed to generate a reset. 2.2.8 XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. 2.2.9 XTAL2 Output from the inverting Oscillator amplifier. 5 2593O-AVR-02/12 2.2.10 AVCC AVCC is the supply voltage pin for Port F and the Analog-to-digital Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. 2.2.11 AREF This is the analog reference pin for the Analog-to-digital Converter. 6 ATmega644 2593O-AVR-02/12 ATmega644 3. Resources A comprehensive set of development tools, application notes and datasheetsare available for download on http://www.atmel.com/avr. 7 2593O-AVR-02/12 4. About Code Examples This documentation contains simple code examples that briefly show how to use various parts of the device. Be aware that not all C compiler vendors include bit definitions in the header files and interrupt handling in C is compiler dependent. Please confirm with the C compiler documentation for more details. The code examples assume that the part specific header file is included before compilation. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". 8 ATmega644 2593O-AVR-02/12 ATmega644 5. AVR CPU Core 5.1 Introduction This section discusses the AVR core architecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. 5.2 Architectural Overview Figure 5-1. Block Diagram of the AVR Architecture Data Bus 8-bit Flash Program Memory Program Counter Status and Control 32 x 8 General Purpose Registrers Control Lines Direct Addressing Instruction Decoder Indirect Addressing Instruction Register Interrupt Unit SPI Unit Watchdog Timer ALU Analog Comparator I/O Module1 Data SRAM I/O Module 2 I/O Module n EEPROM I/O Lines In order to maximize performance and parallelism, the AVR uses a Harvard architecture - with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This concept enables instructions to be executed in every clock cycle. The program memory is In-System Reprogrammable Flash memory. 9 2593O-AVR-02/12 The fast-access Register File contains 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU operation, two operands are output from the Register File, the operation is executed, and the result is stored back in the Register File - in one clock cycle. Six of the 32 registers can be used as three 16-bit indirect address register pointers for Data Space addressing - enabling efficient address calculations. One of the these address pointers can also be used as an address pointer for look up tables in Flash program memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this section. The ALU supports arithmetic and logic operations between registers or between a constant and a register. Single register operations can also be executed in the ALU. After an arithmetic operation, the Status Register is updated to reflect information about the result of the operation. Program flow is provided by conditional and unconditional jump and call instructions, able to directly address the whole address space. Most AVR instructions have a single 16-bit word format. Every program memory address contains a 16-bit or 32-bit instruction. Program Flash memory space is divided in two sections, the Boot Program section and the Application Program section. Both sections have dedicated Lock bits for write and read/write protection. The SPM instruction that writes into the Application Flash memory section must reside in the Boot Program section. During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the Stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialize the SP in the Reset routine (before subroutines or interrupts are executed). The Stack Pointer (SP) is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture. The memory spaces in the AVR architecture are all linear and regular memory maps. A flexible interrupt module has its control registers in the I/O space with an additional Global Interrupt Enable bit in the Status Register. All interrupts have a separate Interrupt Vector in the Interrupt Vector table. The interrupts have priority in accordance with their Interrupt Vector position. The lower the Interrupt Vector address, the higher the priority. The I/O memory space contains 64 addresses for CPU peripheral functions as Control Registers, SPI, and other I/O functions. The I/O Memory can be accessed directly, or as the Data Space locations following those of the Register File, 0x20 - 0x5F. In addition, the ATmega644 has Extended I/O space from 0x100 - 0xFF in SRAM where only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5.3 ALU - Arithmetic Logic Unit The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories - arithmetic, logical, and bit-functions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. See the "Instruction Set" section for a detailed description. 10 ATmega644 2593O-AVR-02/12 ATmega644 5.4 Status Register The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operations. Note that the Status Register is updated after all ALU operations, as specified in the Instruction Set Reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. The Status Register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by software. 5.4.1 SREG - Status Register The AVR Status Register - SREG - is defined as: Bit 7 6 5 4 3 2 1 0 0x3F (0x5F) I T H S V N Z C 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 SREG * Bit 7 - I: Global Interrupt Enable The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the Global Interrupt Enable Register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with the SEI and CLI instructions, as described in the instruction set reference. * Bit 6 - T: Bit Copy Storage The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or destination for the operated bit. A bit from a register in the Register File can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the Register File by the BLD instruction. * Bit 5 - H: Half Carry Flag The Half Carry Flag H indicates a Half Carry in some arithmetic operations. Half Carry Is useful in BCD arithmetic. See the "Instruction Set Description" for detailed information. * Bit 4 - S: Sign Bit, S = N V The S-bit is always an exclusive or between the Negative Flag N and the Two's Complement Overflow Flag V. See the "Instruction Set Description" for detailed information. * Bit 3 - V: Two's Complement Overflow Flag The Two's Complement Overflow Flag V supports two's complement arithmetics. See the "Instruction Set Description" for detailed information. * Bit 2 - N: Negative Flag The Negative Flag N indicates a negative result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. 11 2593O-AVR-02/12 * Bit 1 - Z: Zero Flag The Zero Flag Z indicates a zero result in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. * Bit 0 - C: Carry Flag The Carry Flag C indicates a carry in an arithmetic or logic operation. See the "Instruction Set Description" for detailed information. 5.5 General Purpose Register File The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the Register File: * One 8-bit output operand and one 8-bit result input * Two 8-bit output operands and one 8-bit result input * Two 8-bit output operands and one 16-bit result input * One 16-bit output operand and one 16-bit result input Figure 5-2 shows the structure of the 32 general purpose working registers in the CPU. Figure 5-2. AVR CPU General Purpose Working Registers 7 0 Addr. R0 0x00 R1 0x01 R2 0x02 ... R13 0x0D General R14 0x0E Purpose R15 0x0F Working R16 0x10 Registers R17 0x11 ... R26 0x1A X-register Low Byte R27 0x1B X-register High Byte R28 0x1C Y-register Low Byte R29 0x1D Y-register High Byte R30 0x1E Z-register Low Byte R31 0x1F Z-register High Byte Most of the instructions operating on the Register File have direct access to all registers, and most of them are single cycle instructions. As shown in Figure 5-2, each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user Data Space. Although not being physically implemented as SRAM locations, this memory organization provides great flexibility in access of the registers, as the X-, Y- and Z-pointer registers can be set to index any register in the file. 12 ATmega644 2593O-AVR-02/12 ATmega644 5.5.1 The X-register, Y-register, and Z-register The registers R26..R31 have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, and Z are defined as described in Figure 5-3. Figure 5-3. The X-, Y-, and Z-registers 15 X-register XH XL 7 0 R27 (0x1B) YH YL 7 0 R29 (0x1D) Z-register 0 R26 (0x1A) 15 Y-register 0 7 0 7 0 R28 (0x1C) 15 ZH 7 0 ZL 7 R31 (0x1F) 0 0 R30 (0x1E) In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 5.6 Stack Pointer The Stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The Stack Pointer Register always points to the top of the Stack. Note that the Stack is implemented as growing from higher memory locations to lower memory locations. This implies that a Stack PUSH command decreases the Stack Pointer. The Stack Pointer points to the data SRAM Stack area where the Subroutine and Interrupt Stacks are located. This Stack space in the data SRAM must be defined by the program before any subroutine calls are executed or interrupts are enabled. The Stack Pointer must be set to point above 0x0100. The initial value of the stack pointer is the last address of the internal SRAM. The Stack Pointer is decremented by one when data is pushed onto the Stack with the PUSH instruction, and it is decremented by two when the return address is pushed onto the Stack with subroutine call or interrupt. The Stack Pointer is incremented by one when data is popped from the Stack with the POP instruction, and it is incremented by two when data is popped from the Stack with return from subroutine RET or return from interrupt RETI. The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number of bits actually used is implementation dependent. Note that the data space in some implementations of the AVR architecture is so small that only SPL is needed. In this case, the SPH Register will not be present. Bit 15 14 13 12 11 10 9 8 0x3E (0x5E) - - - SP12 SP11 SP10 SP9 SP8 SPH 0x3D (0x5D) SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 SPL 7 6 5 4 3 2 1 0 Read/Write Initial Value R R R R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 13 2593O-AVR-02/12 5.7 Instruction Execution Timing This section describes the general access timing concepts for instruction execution. The AVR CPU is driven by the CPU clock clkCPU, directly generated from the selected clock source for the chip. No internal clock division is used. Figure 5-4 shows the parallel instruction fetches and instruction executions enabled by the Harvard architecture and the fast-access Register File concept. This is the basic pipelining concept to obtain up to 1 MIPS per MHz with the corresponding unique results for functions per cost, functions per clocks, and functions per power-unit. Figure 5-4. The Parallel Instruction Fetches and Instruction Executions T1 T2 T3 T4 clkCPU 1st Instruction Fetch 1st Instruction Execute 2nd Instruction Fetch 2nd Instruction Execute 3rd Instruction Fetch 3rd Instruction Execute 4th Instruction Fetch Figure 5-5 on page 14 shows the internal timing concept for the Register File. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. Figure 5-5. Single Cycle ALU Operation T1 T2 T3 T4 clkCPU Total Execution Time Register Operands Fetch ALU Operation Execute Result Write Back 5.8 Reset and Interrupt Handling The AVR provides several different interrupt sources. These interrupts and the separate Reset Vector each have a separate program vector in the program memory space. All interrupts are assigned individual enable bits which must be written logic one together with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. Depending on the Program Counter value, interrupts may be automatically disabled when Boot Lock bits BLB02 or BLB12 are programmed. This feature improves software security. See the section "Memory Programming" on page 284 for details. The lowest addresses in the program memory space are by default defined as the Reset and Interrupt Vectors. The complete list of vectors is shown in "Interrupts" on page 55. The list also determines the priority levels of the different interrupts. The lower the address the higher is the 14 ATmega644 2593O-AVR-02/12 ATmega644 priority level. RESET has the highest priority, and next is INT0 - the External Interrupt Request 0. The Interrupt Vectors can be moved to the start of the Boot Flash section by setting the IVSEL bit in the MCU Control Register (MCUCR). Refer to "Interrupts" on page 55 for more information. The Reset Vector can also be moved to the start of the Boot Flash section by programming the BOOTRST Fuse, see "Memory Programming" on page 284. When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction - RETI - is executed. There are basically two types of interrupts. The first type is triggered by an event that sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to execute the interrupt handling routine, and hardware clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set, and will then be executed by order of priority. The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not necessarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence.. Assembly Code Example in r16, SREG cli ; store SREG value ; disable interrupts during timed sequence sbi EECR, EEMPE ; start EEPROM write sbi EECR, EEPE out SREG, r16 ; restore SREG value (I-bit) C Code Example char cSREG; cSREG = SREG; /* store SREG value */ /* disable interrupts during timed sequence */ __disable_interrupt(); EECR |= (1< ... ... ... ; ADC Conversion Complete Handler ; EEPROM Ready Handler ; 2-wire Serial Handler ; SPM Ready Handler ; Main program start ; Set Stack Pointer to top of RAM r16, low(RAMEND) SPL,r16 ; Enable interrupts xxx ... When the BOOTRST Fuse is unprogrammed, the Boot section size set to 8 Kbytes and the IVSEL bit in the MCUCR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is: Address Labels Code Comments 0x00000 RESET: ldi r16,high(RAMEND); Main program start 0x00001 out SPH,r16 0x00002 ldi r16,low(RAMEND) 0x00003 0x00004 out sei SPL,r16 0x00005 ; Set Stack Pointer to top of RAM ; Enable interrupts xxx ; .org 0x1F002 0x1F002 jmp EXT_INT0 ; IRQ0 Handler 0x1F004 jmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1FO36 jmp SPM_RDY ; SPM Ready Handler When the BOOTRST Fuse is programmed and the Boot section size set to 8 Kbytes, the most typical and general program setup for the Reset and Interrupt Vector Addresses is: Address Labels Code Comments .org 0x0002 0x00002 jmp EXT_INT0 ; IRQ0 Handler 0x00004 jmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x00036 jmp SPM_RDY ; SPM Ready Handler ; .org 0x1F000 0x1F000 RESET: ldi r16,high(RAMEND); Main program start 0x1F001 SPH,r16 out ; Set Stack Pointer to top of RAM 57 2593O-AVR-02/12 0x1F002 ldi r16,low(RAMEND) 0x1F003 0x1F004 out sei SPL,r16 0x1F005 ; Enable interrupts xxx When the BOOTRST Fuse is programmed, the Boot section size set to 8 Kbytes and the IVSEL bit in the MCUCR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is: Address Labels Code Comments ; .org 0x1F000 0x1F000 0x1F002 jmp jmp RESET EXT_INT0 ; Reset handler ; IRQ0 Handler 0x1F004 jmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1F036 jmp SPM_RDY ; SPM Ready Handler ; 10.1.1 0x1F03E RESET: ldi r16,high(RAMEND); Main program start 0x1F03F out SPH,r16 0x1F040 ldi r16,low(RAMEND) 0x1F041 0x1F042 out sei SPL,r16 0x1FO43 ; Set Stack Pointer to top of RAM ; Enable interrupts xxx Moving Interrupts Between Application and Boot Space The General Interrupt Control Register controls the placement of the Interrupt Vector table. 10.2 10.2.1 Register Description MCUCR - MCU Control Register Bit 7 6 5 4 3 2 1 0 0x35 (0x55) JTD - - PUD - - IVSEL IVCE Read/Write R/W R R R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 MCUCR * Bit 1 - IVSEL: Interrupt Vector Select When the IVSEL bit is cleared (zero), the Interrupt Vectors are placed at the start of the Flash memory. When this bit is set (one), the Interrupt Vectors are moved to the beginning of the Boot Loader section of the Flash. The actual address of the start of the Boot Flash Section is determined by the BOOTSZ Fuses. Refer to the section "Memory Programming" on page 284 for details. To avoid unintentional changes of Interrupt Vector tables, a special write procedure must be followed to change the IVSEL bit: a. Write the Interrupt Vector Change Enable (IVCE) bit to one. b. Within four cycles, write the desired value to IVSEL while writing a zero to IVCE. Interrupts will automatically be disabled while this sequence is executed. Interrupts are disabled in the cycle IVCE is set, and they remain disabled until after the instruction following the write to 58 ATmega644 2593O-AVR-02/12 ATmega644 IVSEL. If IVSEL is not written, interrupts remain disabled for four cycles. The I-bit in the Status Register is unaffected by the automatic disabling. Note: If Interrupt Vectors are placed in the Boot Loader section and Boot Lock bit BLB02 is programmed, interrupts are disabled while executing from the Application section. If Interrupt Vectors are placed in the Application section and Boot Lock bit BLB12 is programed, interrupts are disabled while executing from the Boot Loader section. Refer to the section "Memory Programming" on page 284 for details on Boot Lock bits. * Bit 0 - IVCE: Interrupt Vector Change Enable The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts, as explained in the IVSEL description above. See Code Example below. Assembly Code Example Move_interrupts: ; Get MCUCR in r16, MCUCR mov r17, r16 ; Enable change of Interrupt Vectors ori r16, (1<>8); UBRRLn = (unsigned char)baud; /* Enable receiver and transmitter */ UCSRnB = (1<> 1) & 0x01; return ((resh << 8) | resl); } Note: 1. See "About Code Examples" on page 8. The receive function example reads all the I/O Registers into the Register File before any computation is done. This gives an optimal receive buffer utilization since the buffer location read will be free to accept new data as early as possible. 175 2593O-AVR-02/12 17.7.3 Receive Compete Flag and Interrupt The USART Receiver has one flag that indicates the Receiver state. The Receive Complete (RXCn) Flag indicates if there are unread data present in the receive buffer. This flag is one when unread data exist in the receive buffer, and zero when the receive buffer is empty (that is, does not contain any unread data). If the Receiver is disabled (RXENn = 0), the receive buffer will be flushed and consequently the RXCn bit will become zero. When the Receive Complete Interrupt Enable (RXCIEn) in UCSRnB is set, the USART Receive Complete interrupt will be executed as long as the RXCn Flag is set (provided that global interrupts are enabled). When interrupt-driven data reception is used, the receive complete routine must read the received data from UDRn in order to clear the RXCn Flag, otherwise a new interrupt will occur once the interrupt routine terminates. 17.7.4 Receiver Error Flags The USART Receiver has three Error Flags: Frame Error (FEn), Data OverRun (DORn) and Parity Error (UPEn). All can be accessed by reading UCSRnA. Common for the Error Flags is that they are located in the receive buffer together with the frame for which they indicate the error status. Due to the buffering of the Error Flags, the UCSRnA must be read before the receive buffer (UDRn), since reading the UDRn I/O location changes the buffer read location. Another equality for the Error Flags is that they can not be altered by software doing a write to the flag location. However, all flags must be set to zero when the UCSRnA is written for upward compatibility of future USART implementations. None of the Error Flags can generate interrupts. The Frame Error (FEn) Flag indicates the state of the first stop bit of the next readable frame stored in the receive buffer. The FEn Flag is zero when the stop bit was correctly read (as one), and the FEn Flag will be one when the stop bit was incorrect (zero). This flag can be used for detecting out-of-sync conditions, detecting break conditions and protocol handling. The FEn Flag is not affected by the setting of the USBSn bit in UCSRnC since the Receiver ignores all, except for the first, stop bits. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. The Data OverRun (DORn) Flag indicates data loss due to a receiver buffer full condition. A Data OverRun occurs when the receive buffer is full (two characters), it is a new character waiting in the Receive Shift Register, and a new start bit is detected. If the DORn Flag is set there was one or more serial frame lost between the frame last read from UDRn, and the next frame read from UDRn. For compatibility with future devices, always write this bit to zero when writing to UCSRnA. The DORn Flag is cleared when the frame received was successfully moved from the Shift Register to the receive buffer. The Parity Error (UPEn) Flag indicates that the next frame in the receive buffer had a Parity Error when received. If Parity Check is not enabled the UPEn bit will always be read zero. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. For more details see "Parity Bit Calculation" on page 169 and "Parity Checker" on page 176. 17.7.5 Parity Checker The Parity Checker is active when the high USART Parity mode (UPMn1) bit is set. Type of Parity Check to be performed (odd or even) is selected by the UPMn0 bit. When enabled, the Parity Checker calculates the parity of the data bits in incoming frames and compares the result with the parity bit from the serial frame. The result of the check is stored in the receive buffer together 176 ATmega644 2593O-AVR-02/12 ATmega644 with the received data and stop bits. The Parity Error (UPEn) Flag can then be read by software to check if the frame had a Parity Error. The UPEn bit is set if the next character that can be read from the receive buffer had a Parity Error when received and the Parity Checking was enabled at that point (UPMn1 = 1). This bit is valid until the receive buffer (UDRn) is read. 17.7.6 Disabling the Receiver In contrast to the Transmitter, disabling of the Receiver will be immediate. Data from ongoing receptions will therefore be lost. When disabled (that is, the RXENn is set to zero) the Receiver will no longer override the normal function of the RxDn port pin. The Receiver buffer FIFO will be flushed when the Receiver is disabled. Remaining data in the buffer will be lost 17.7.7 Flushing the Receive Buffer The receiver buffer FIFO will be flushed when the Receiver is disabled, that is, the buffer will be emptied of its contents. Unread data will be lost. If the buffer has to be flushed during normal operation, due to for instance an error condition, read the UDRn I/O location until the RXCn Flag is cleared. The following code example shows how to flush the receive buffer. Assembly Code Example(1) USART_Flush: sbis UCSRnA, RXCn ret in r16, UDRn rjmp USART_Flush C Code Example(1) void USART_Flush( void ) { unsigned char dummy; while ( UCSRnA & (1< 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz High: > 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz 25.8.2 Serial Programming Algorithm When writing serial data to the ATmega644, data is clocked on the rising edge of SCK. When reading data from the ATmega644, data is clocked on the falling edge of SCK. See Figure 25-12 for timing details. To program and verify the ATmega644 in the serial programming mode, the following sequence is recommended (See four byte instruction formats in Table 25-17): 1. Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to "0". In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to "0". 2. Wait for at least 20 ms and enable serial programming by sending the Programming Enable serial instruction to pin MOSI. 3. The serial programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command. 4. The Flash is programmed one page at a time. The memory page is loaded one byte at a time by supplying the 7 LSB of the address and data together with the Load Program Memory Page instruction. To ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. The Program Memory Page is stored by loading the Write Program Memory Page instruction with the address lines 15..8. Before issuing this command, make sure the instruction Load Extended Address Byte has been used to define the MSB of the address. The extended address byte is stored until the command is re-issued, that is, the command needs only be issued for the first page, and when crossing the 64KWord boundary. If polling (RDY/BSY) is not used, the user must wait at least tWD_FLASH before issuing the next page. (See Table 2516.) Accessing the serial programming interface before the Flash write operation completes can result in incorrect programming. 5. The EEPROM array is programmed one byte at a time by supplying the address and data together with the appropriate Write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling is not used, the user must wait at least tWD_EEPROM before issuing the next byte. (See Table 25-16.) In a chip erased device, no 0xFFs in the data file(s) need to be programmed. 6. Any memory location can be verified by using the Read instruction which returns the content at the selected address at serial output MISO. When reading the Flash memory, use the instruction Load Extended Address Byte to define the upper address byte, which is not included in the Read Program Memory instruction. The extended address byte is 300 ATmega644 2593O-AVR-02/12 ATmega644 stored until the command is re-issued, that is, the command needs only be issued for the first page, and when crossing the 64KWord boundary. 7. At the end of the programming session, RESET can be set high to commence normal operation. 8. Power-off sequence (if needed): Set RESET to "1". Turn VCC power off. Table 25-16. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location 25.9 Symbol Minimum Wait Delay tWD_FLASH 4.5 ms tWD_EEPROM 9.0 ms tWD_ERASE 9.0 ms Serial Programming Instruction set Table 25-17 on page 301 and Figure 25-11 on page 302 describes the Instruction set. Table 25-17. Serial Programming Instruction Set (Hexadecimal values) Instruction Format Instruction/Operation Byte 1 Byte 2 Byte 3 Byte 4 Programming Enable $AC $53 $00 $00 Chip Erase (Program Memory/EEPROM) $AC $80 $00 $00 Poll RDY/BSY $F0 $00 $00 data byte out Load Extended Address byte(1) $4D $00 Extended adr $00 Load Program Memory Page, High byte $48 $00 adr LSB high data byte in Load Program Memory Page, Low byte $40 $00 adr LSB low data byte in Load EEPROM Memory Page (page access) $C1 $00 0000 000aa data byte in Read Program Memory, High byte $28 adr MSB adr LSB high data byte out Read Program Memory, Low byte $20 adr MSB adr LSB low data byte out Read EEPROM Memory $A0 0000 00aa aaaa aaaa data byte out Read Lock bits $58 $00 $00 data byte out Read Signature Byte $30 $00 0000 000aa data byte out Read Fuse bits $50 $00 $00 data byte out Read Fuse High bits $58 $08 $00 data byte out Read Extended Fuse Bits $50 $08 $00 data byte out Read Calibration Byte $38 $00 $00 data byte out Write Program Memory Page $4C adr MSB adr LSB $00 Write EEPROM Memory $C0 0000 00aa aaaa aaaa data byte in Load Instructions Read Instructions Write Instructions 301 2593O-AVR-02/12 Table 25-17. Serial Programming Instruction Set (Hexadecimal values) (Continued) Instruction Format Instruction/Operation Byte 1 Byte 2 Byte 3 Byte 4 Write EEPROM Memory Page (page access) $C2 0000 00aa aaaa aa00 $00 Write Lock bits $AC $E0 $00 data byte in Write Fuse bits $AC $A0 $00 data byte in Write Fuse High bits $AC $A8 $00 data byte in Write Extended Fuse Bits $AC $A4 $00 data byte in Notes: 1. 2. 3. 4. 5. 6. Not all instructions are applicable for all parts. a = address. Bits are programmed `0', unprogrammed `1'. To ensure future compatibility, unused Fuses and Lock bits should be unprogrammed (`1') . Refer to the correspondig section for Fuse and Lock bits, Calibration and Signature bytes and Page size. See htt://www.atmel.com/avr for Application Notes regarding programming and programmers. If the LSB in RDY/BSY data byte out is `1', a programming operation is still pending. Wait until this bit returns `0' before the next instruction is carried out. Within the same page, the low data byte must be loaded prior to the high data byte. After data is loaded to the page buffer, program the EEPROM page, see Figure 25-11 on page 302. Figure 25-11. Serial Programming Instruction example Serial Programming Instruction Load Program Memory Page (High/Low Byte)/ Load EEPROM Memory Page (page access) Byte 1 Byte 2 Adr MSB A Bit 15 B Byte 3 Write Program Memory Page/ Write EEPROM Memory Page Byte 1 Byte 4 Byte 2 Adr LSB Adr MSB Bit 15 B 0 Byte 3 Byte 4 Adrr LSB B 0 Page Buffer Page Offset Page 0 Page 1 Page 2 Page Number Page N-1 Program Memory/ EEPROM Memory 302 ATmega644 2593O-AVR-02/12 ATmega644 25.9.1 Serial Programming Characteristics For characteristics of the Serial Programming module see "SPI Timing Characteristics" on page 322. Figure 25-12. Serial Programming Waveforms SERIAL DATA INPUT (MOSI) MSB LSB SERIAL DATA OUTPUT (MISO) MSB LSB SERIAL CLOCK INPUT (SCK) SAMPLE 25.10 Programming via the JTAG Interface Programming through the JTAG interface requires control of the four JTAG specific pins: TCK, TMS, TDI, and TDO. Control of the reset and clock pins is not required. To be able to use the JTAG interface, the JTAGEN Fuse must be programmed. The device is default shipped with the fuse programmed. In addition, the JTD bit in MCUCSR must be cleared. Alternatively, if the JTD bit is set, the external reset can be forced low. Then, the JTD bit will be cleared after two chip clocks, and the JTAG pins are available for programming. This provides a means of using the JTAG pins as normal port pins in Running mode while still allowing In-System Programming via the JTAG interface. Note that this technique can not be used when using the JTAG pins for Boundary-scan or On-chip Debug. In these cases the JTAG pins must be dedicated for this purpose. During programming the clock frequency of the TCK Input must be less than the maximum frequency of the chip. The System Clock Prescaler can not be used to divide the TCK Clock Input into a sufficiently low frequency. As a definition in this datasheet, the LSB is shifted in and out first of all Shift Registers. 25.10.1 Programming Specific JTAG Instructions The Instruction Register is 4-bit wide, supporting up to 16 instructions. The JTAG instructions useful for programming are listed below. The OPCODE for each instruction is shown behind the instruction name in hex format. The text describes which Data Register is selected as path between TDI and TDO for each instruction. The Run-Test/Idle state of the TAP controller is used to generate internal clocks. It can also be used as an idle state between JTAG sequences. The state machine sequence for changing the instruction word is shown in Figure 25-13. 303 2593O-AVR-02/12 Figure 25-13. State Machine Sequence for Changing the Instruction Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 1 0 1 Capture-DR Capture-IR 0 0 0 Shift-DR 1 1 Exit1-DR 0 0 Pause-DR 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 25.10.2 1 Exit1-IR 0 1 0 Shift-IR 1 0 1 Update-IR 0 1 0 AVR_RESET (0xC) The AVR specific public JTAG instruction for setting the AVR device in the Reset mode or taking the device out from the Reset mode. The TAP controller is not reset by this instruction. The one bit Reset Register is selected as Data Register. Note that the reset will be active as long as there is a logic "one" in the Reset Chain. The output from this chain is not latched. The active states are: * Shift-DR: The Reset Register is shifted by the TCK input. 25.10.3 PROG_ENABLE (0x4) The AVR specific public JTAG instruction for enabling programming via the JTAG port. The 16bit Programming Enable Register is selected as Data Register. The active states are the following: * Shift-DR: The programming enable signature is shifted into the Data Register. * Update-DR: The programming enable signature is compared to the correct value, and Programming mode is entered if the signature is valid. 304 ATmega644 2593O-AVR-02/12 ATmega644 25.10.4 PROG_COMMANDS (0x5) The AVR specific public JTAG instruction for entering programming commands via the JTAG port. The 15-bit Programming Command Register is selected as Data Register. The active states are the following: * Capture-DR: The result of the previous command is loaded into the Data Register. * Shift-DR: The Data Register is shifted by the TCK input, shifting out the result of the previous command and shifting in the new command. * Update-DR: The programming command is applied to the Flash inputs * Run-Test/Idle: One clock cycle is generated, executing the applied command 25.10.5 PROG_PAGELOAD (0x6) The AVR specific public JTAG instruction to directly load the Flash data page via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSBs of the Programming Command Register. The active states are the following: * Shift-DR: The Flash Data Byte Register is shifted by the TCK input. * Update-DR: The content of the Flash Data Byte Register is copied into a temporary register. A write sequence is initiated that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first UpdateDR encountered after entering the PROG_PAGELOAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the program counter increment into the next page. 25.10.6 PROG_PAGEREAD (0x7) The AVR specific public JTAG instruction to directly capture the Flash content via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSBs of the Programming Command Register. The active states are the following: * Capture-DR: The content of the selected Flash byte is captured into the Flash Data Byte Register. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Capture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. * Shift-DR: The Flash Data Byte Register is shifted by the TCK input. 25.10.7 Data Registers The Data Registers are selected by the JTAG instruction registers described in section "Programming Specific JTAG Instructions" on page 303. The Data Registers relevant for programming operations are: * Reset Register * Programming Enable Register * Programming Command Register * Flash Data Byte Register 305 2593O-AVR-02/12 25.10.8 Reset Register The Reset Register is a Test Data Register used to reset the part during programming. It is required to reset the part before entering Programming mode. A high value in the Reset Register corresponds to pulling the external reset low. The part is reset as long as there is a high value present in the Reset Register. Depending on the Fuse settings for the clock options, the part will remain reset for a Reset Time-out period (refer to "Clock Sources" on page 28) after releasing the Reset Register. The output from this Data Register is not latched, so the reset will take place immediately, as shown in Figure 23-2 on page 260. 25.10.9 Programming Enable Register The Programming Enable Register is a 16-bit register. The contents of this register is compared to the programming enable signature, binary code 0b1010_0011_0111_0000. When the contents of the register is equal to the programming enable signature, programming via the JTAG port is enabled. The register is reset to 0 on Power-on Reset, and should always be reset when leaving Programming mode. Figure 25-14. Programming Enable Register TDI D A T A 0xA370 = D Q Programming Enable ClockDR & PROG_ENABLE TDO 25.10.10 Programming Command Register The Programming Command Register is a 15-bit register. This register is used to serially shift in programming commands, and to serially shift out the result of the previous command, if any. The JTAG Programming Instruction Set is shown in Table 25-18. The state sequence when shifting in the programming commands is illustrated in Figure 25-16. 306 ATmega644 2593O-AVR-02/12 ATmega644 Figure 25-15. Programming Command Register TDI S T R O B E S A D D R E S S / D A T A Flash EEPROM Fuses Lock Bits TDO 307 2593O-AVR-02/12 Table 25-18. JTAG Programming Instruction Set a = address high bits, b = address low bits, c = address extended bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don't care Instruction TDI Sequence TDO Sequence 1a. Chip Erase 0100011_10000000 0110001_10000000 0110011_10000000 0110011_10000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx 1b. Poll for Chip Erase Complete 0110011_10000000 xxxxxox_xxxxxxxx 2a. Enter Flash Write 0100011_00010000 xxxxxxx_xxxxxxxx 2b. Load Address Extended High Byte 0001011_cccccccc xxxxxxx_xxxxxxxx 2c. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 2d. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 2e. Load Data Low Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 2f. Load Data High Byte 0010111_iiiiiiii xxxxxxx_xxxxxxxx 2g. Latch Data 0110111_00000000 1110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 2h. Write Flash Page 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 2i. Poll for Page Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 3a. Enter Flash Read 0100011_00000010 xxxxxxx_xxxxxxxx 3b. Load Address Extended High Byte 0001011_cccccccc xxxxxxx_xxxxxxxx 3c. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 3d. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 3e. Read Data Low and High Byte 0110010_00000000 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo xxxxxxx_oooooooo 4a. Enter EEPROM Write 0100011_00010001 xxxxxxx_xxxxxxxx 4b. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 4c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 4d. Load Data Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 4e. Latch Data 0110111_00000000 1110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 4f. Write EEPROM Page 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 4g. Poll for Page Write Complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 308 Notes (2) (10) (10) Low byte High byte (10) ATmega644 2593O-AVR-02/12 ATmega644 Table 25-18. JTAG Programming Instruction (Continued) Set (Continued) a = address high bits, b = address low bits, c = address extended bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don't care Instruction TDI Sequence TDO Sequence 5a. Enter EEPROM Read 0100011_00000011 xxxxxxx_xxxxxxxx 5b. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 5c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 5d. Read Data Byte 0110011_bbbbbbbb 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 6a. Enter Fuse Write 0100011_01000000 xxxxxxx_xxxxxxxx 6b. Load Data Low Byte(6) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6c. Write Fuse Extended Byte 0111011_00000000 0111001_00000000 0111011_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6d. Poll for Fuse Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6f. Write Fuse High Byte 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6g. Poll for Fuse Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 6h. Load Data Low Byte(7) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6i. Write Fuse Low Byte 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6j. Poll for Fuse Write Complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 7a. Enter Lock Bit Write 0100011_00100000 xxxxxxx_xxxxxxxx 7b. Load Data Byte 0010011_11iiiiii xxxxxxx_xxxxxxxx (4) 7c. Write Lock Bits 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 7d. Poll for Lock Bit Write complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 8a. Enter Fuse/Lock Bit Read 0100011_00000100 xxxxxxx_xxxxxxxx 8b. Read Extended Fuse Byte(6) 0111010_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8c. Read Fuse High Byte(7) 0111110_00000000 0111111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8d. Read Fuse Low Byte(8) 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 6e. Load Data Low Byte (7) (9) Notes (10) 309 2593O-AVR-02/12 Table 25-18. JTAG Programming Instruction (Continued) Set (Continued) a = address high bits, b = address low bits, c = address extended bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don't care Instruction TDI Sequence TDO Sequence Notes 8e. Read Lock Bits(9) 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxoooooo (5) 8f. Read Fuses and Lock Bits 0111010_00000000 0111110_00000000 0110010_00000000 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo xxxxxxx_oooooooo xxxxxxx_oooooooo xxxxxxx_oooooooo (5) Fuse Ext. byte Fuse High byte Fuse Low byte Lock bits 9a. Enter Signature Byte Read 0100011_00001000 xxxxxxx_xxxxxxxx 9b. Load Address Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 9c. Read Signature Byte 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 10a. Enter Calibration Byte Read 0100011_00001000 xxxxxxx_xxxxxxxx 10b. Load Address Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 10c. Read Calibration Byte 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 11a. Load No Operation Command 0100011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx Notes: 310 1. This command sequence is not required if the seven MSB are correctly set by the previous command sequence (which is normally the case). 2. Repeat until o = "1". 3. Set bits to "0" to program the corresponding Fuse, "1" to unprogram the Fuse. 4. Set bits to "0" to program the corresponding Lock bit, "1" to leave the Lock bit unchanged. 5. "0" = programmed, "1" = unprogrammed. 6. The bit mapping for Fuses Extended byte is listed in Table 25-3 on page 285 7. The bit mapping for Fuses High byte is listed in Table 25-4 on page 286 8. The bit mapping for Fuses Low byte is listed in Table 25-5 on page 286 9. The bit mapping for Lock bits byte is listed in Table 25-1 on page 284 10. Address bits exceeding PCMSB and EEAMSB (Table 25-7 and Table 25-8) are don't care 11. All TDI and TDO sequences are represented by binary digits (0b...). ATmega644 2593O-AVR-02/12 ATmega644 Figure 25-16. State Machine Sequence for Changing/Reading the Data Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 1 0 1 Capture-DR Capture-IR 0 0 Shift-DR Shift-IR 0 1 Exit1-DR 1 Exit1-IR 0 0 Pause-DR 0 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 1 0 1 1 0 1 Update-IR 0 1 0 25.10.11 Flash Data Byte Register The Flash Data Byte Register provides an efficient way to load the entire Flash page buffer before executing Page Write, or to read out/verify the content of the Flash. A state machine sets up the control signals to the Flash and senses the strobe signals from the Flash, thus only the data words need to be shifted in/out. The Flash Data Byte Register actually consists of the 8-bit scan chain and a 8-bit temporary register. During page load, the Update-DR state copies the content of the scan chain over to the temporary register and initiates a write sequence that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first Update-DR encountered after entering the PROG_PAGELOAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the Program Counter increment into the next page. During Page Read, the content of the selected Flash byte is captured into the Flash Data Byte Register during the Capture-DR state. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Cap- 311 2593O-AVR-02/12 ture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. Figure 25-17. Flash Data Byte Register STROBES TDI State Machine ADDRESS Flash EEPROM Fuses Lock Bits D A T A TDO The state machine controlling the Flash Data Byte Register is clocked by TCK. During normal operation in which eight bits are shifted for each Flash byte, the clock cycles needed to navigate through the TAP controller automatically feeds the state machine for the Flash Data Byte Register with sufficient number of clock pulses to complete its operation transparently for the user. However, if too few bits are shifted between each Update-DR state during page load, the TAP controller should stay in the Run-Test/Idle state for some TCK cycles to ensure that there are at least 11 TCK cycles between each Update-DR state. 25.10.12 Programming Algorithm All references below of type "1a", "1b", and so on, refer to Table 25-18. 25.10.13 Entering Programming Mode 1. Enter JTAG instruction AVR_RESET and shift 1 in the Reset Register. 2. Enter instruction PROG_ENABLE and shift 0b1010_0011_0111_0000 in the Programming Enable Register. 25.10.14 Leaving Programming Mode 1. Enter JTAG instruction PROG_COMMANDS. 2. Disable all programming instructions by using no operation instruction 11a. 3. Enter instruction PROG_ENABLE and shift 0b0000_0000_0000_0000 in the programming Enable Register. 4. Enter JTAG instruction AVR_RESET and shift 0 in the Reset Register. 312 ATmega644 2593O-AVR-02/12 ATmega644 25.10.15 Performing Chip Erase 1. Enter JTAG instruction PROG_COMMANDS. 2. Start Chip Erase using programming instruction 1a. 3. Poll for Chip Erase complete using programming instruction 1b, or wait for tWLRH_CE (refer to Table 25-14 on page 298). 25.10.16 Programming the Flash Before programming the Flash a Chip Erase must be performed, see "Performing Chip Erase" on page 313. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash write using programming instruction 2a. 3. Load address Extended High byte using programming instruction 2b. 4. Load address High byte using programming instruction 2c. 5. Load address Low byte using programming instruction 2d. 6. Load data using programming instructions 2e, 2f and 2g. 7. Repeat steps 5 and 6 for all instruction words in the page. 8. Write the page using programming instruction 2h. 9. Poll for Flash write complete using programming instruction 2i, or wait for tWLRH (refer to Table 25-14 on page 298). 10. Repeat steps 3 to 9 until all data have been programmed. A more efficient data transfer can be achieved using the PROG_PAGELOAD instruction: 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash write using programming instruction 2a. 3. Load the page address using programming instructions 2b, 2c and 2d. PCWORD (refer to Table 25-7 on page 287) is used to address within one page and must be written as 0. 4. Enter JTAG instruction PROG_PAGELOAD. 5. Load the entire page by shifting in all instruction words in the page byte-by-byte, starting with the LSB of the first instruction in the page and ending with the MSB of the last instruction in the page. Use Update-DR to copy the contents of the Flash Data Byte Register into the Flash page location and to auto-increment the Program Counter before each new word. 6. Enter JTAG instruction PROG_COMMANDS. 7. Write the page using programming instruction 2h. 8. Poll for Flash write complete using programming instruction 2i, or wait for tWLRH (refer to Table 25-14 on page 298). 9. Repeat steps 3 to 8 until all data have been programmed. 25.10.17 Reading the Flash 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash read using programming instruction 3a. 3. Load address using programming instructions 3b, 3c and 3d. 4. Read data using programming instruction 3e. 5. Repeat steps 3 and 4 until all data have been read. A more efficient data transfer can be achieved using the PROG_PAGEREAD instruction: 313 2593O-AVR-02/12 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash read using programming instruction 3a. 3. Load the page address using programming instructions 3b, 3c and 3d. PCWORD (refer to Table 25-7 on page 287) is used to address within one page and must be written as 0. 4. Enter JTAG instruction PROG_PAGEREAD. 5. Read the entire page (or Flash) by shifting out all instruction words in the page (or Flash), starting with the LSB of the first instruction in the page (Flash) and ending with the MSB of the last instruction in the page (Flash). The Capture-DR state both captures the data from the Flash, and also auto-increments the program counter after each word is read. Note that Capture-DR comes before the shift-DR state. Hence, the first byte which is shifted out contains valid data. 6. Enter JTAG instruction PROG_COMMANDS. 7. Repeat steps 3 to 6 until all data have been read. 25.10.18 Programming the EEPROM Before programming the EEPROM a Chip Erase must be performed, see "Performing Chip Erase" on page 313. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable EEPROM write using programming instruction 4a. 3. Load address High byte using programming instruction 4b. 4. Load address Low byte using programming instruction 4c. 5. Load data using programming instructions 4d and 4e. 6. Repeat steps 4 and 5 for all data bytes in the page. 7. Write the data using programming instruction 4f. 8. Poll for EEPROM write complete using programming instruction 4g, or wait for tWLRH (refer to Table 25-14 on page 298). 9. Repeat steps 3 to 8 until all data have been programmed. Note that the PROG_PAGELOAD instruction can not be used when programming the EEPROM. 25.10.19 Reading the EEPROM 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable EEPROM read using programming instruction 5a. 3. Load address using programming instructions 5b and 5c. 4. Read data using programming instruction 5d. 5. Repeat steps 3 and 4 until all data have been read. Note that the PROG_PAGEREAD instruction can not be used when reading the EEPROM. 25.10.20 Programming the Fuses 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Fuse write using programming instruction 6a. 3. Load data high byte using programming instructions 6b. A bit value of "0" will program the corresponding fuse, a "1" will unprogram the fuse. 4. Write Fuse High byte using programming instruction 6c. 5. Poll for Fuse write complete using programming instruction 6d, or wait for tWLRH (refer to Table 25-14 on page 298). 314 ATmega644 2593O-AVR-02/12 ATmega644 6. Load data low byte using programming instructions 6e. A "0" will program the fuse, a "1" will unprogram the fuse. 7. Write Fuse low byte using programming instruction 6f. 8. Poll for Fuse write complete using programming instruction 6g, or wait for tWLRH (refer to Table 25-14 on page 298). 25.10.21 Programming the Lock Bits 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Lock bit write using programming instruction 7a. 3. Load data using programming instructions 7b. A bit value of "0" will program the corresponding lock bit, a "1" will leave the lock bit unchanged. 4. Write Lock bits using programming instruction 7c. 5. Poll for Lock bit write complete using programming instruction 7d, or wait for tWLRH (refer to Table 25-14 on page 298). 25.10.22 Reading the Fuses and Lock Bits 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Fuse/Lock bit read using programming instruction 8a. 3. To read all Fuses and Lock bits, use programming instruction 8e. To only read Fuse High byte, use programming instruction 8b. To only read Fuse Low byte, use programming instruction 8c. To only read Lock bits, use programming instruction 8d. 25.10.23 Reading the Signature Bytes 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Signature byte read using programming instruction 9a. 3. Load address 0x00 using programming instruction 9b. 4. Read first signature byte using programming instruction 9c. 5. Repeat steps 3 and 4 with address 0x01 and address 0x02 to read the second and third signature bytes, respectively. 25.10.24 Reading the Calibration Byte 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Calibration byte read using programming instruction 10a. 3. Load address 0x00 using programming instruction 10b. 4. Read the calibration byte using programming instruction 10c. 315 2593O-AVR-02/12 26. Electrical Characteristics 26.1 Absolute Maximum Ratings* Operating Temperature....................................-55C to +125C *NOTICE: Storage Temperature ..................................... -65C to +150C Voltage on any Pin except RESET with respect to Ground ................................-0.5V to VCC+0.5V Voltage on RESET with respect to Ground......-0.5V to +13.0V Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability. Maximum Operating Voltage ............................................ 6.0V DC Current per I/O Pin ............................................... 40.0 mA DC Current VCC and GND Pins................................ 200.0 mA 26.2 DC Characteristics TA = -40C to 85C, VCC = 1.8V to 5.5V (unless otherwise noted) Symbol Parameter Condition Min.(5) Typ. Max.(5) Units (1) VIL Input Low Voltage,Except XTAL1 and Reset pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V -0.5 -0.5 0.2VCC 0.3VCC(1) VIL1 Input Low Voltage, XTAL1 pin VCC = 1.8V - 5.5V -0.5 0.1VCC(1) VIL2 Input Low Voltage, RESET pin VCC = 1.8V - 5.5V -0.5 0.1VCC(1) VIH Input High Voltage, Except XTAL1 and RESET pins VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.7VCC(2) 0.6VCC(2) VCC + 0.5 VCC + 0.5 VIH1 Input High Voltage, XTAL1 pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.8VCC(2) 0.7VCC(2) VCC + 0.5 VCC + 0.5 VIH2 Input High Voltage, RESET pin VCC = 1.8V - 5.5V 0.9VCC(2) VCC + 0.5 VOL Output Low Voltage(3), IOL = 10 mA, VCC = 5V IOL = 5 mA, VCC = 3V VOH Output High Voltage(4), IOH = -20 mA, VCC = 5V IOH = -10 mA, VCC = 3V IIL Input Leakage Current I/O Pin VCC = 5.5V, pin low (absolute value) 1 IIH Input Leakage Current I/O Pin VCC = 5.5V, pin high (absolute value) 1 RRST Reset Pull-up Resistor 30 60 RPU I/O Pin Pull-up Resistor 20 50 V 0.7 0.5 4.2 2.3 A 316 k ATmega644 2593O-AVR-02/12 ATmega644 TA = -40C to 85C, VCC = 1.8V to 5.5V (unless otherwise noted) (Continued) Symbol Parameter Condition (6) Min.(5) Typ. Max.(5) Active 1 MHz, VCC = 2V (ATmega644V) 0.5 Active 4 MHz, VCC = 3V (ATmega644L) 2.7 Active 8 MHz, VCC = 5V (ATmega644) 9.0 Power Supply Current mA Idle 1 MHz, VCC = 2V (ATmega644V) ICC Power-down mode(7) 0.4 0.15 Idle 4 MHz, VCC = 3V (ATmega644L) 0.7 Idle 8 MHz, VCC = 5V (ATmega644) 2.5 WDT enabled, VCC = 3V <8 20 WDT disabled, VCC = 3V <2 3 <10 40 mV 50 nA VACIO Analog Comparator Input Offset Voltage VCC = 5V Vin = VCC/2 IACLK Analog Comparator Input Leakage Current VCC = 5V Vin = VCC/2 tACID Analog Comparator Propagation Delay VCC = 2.7V VCC = 4.0V Note: Units A -50 750 500 ns 1. "Max" means the highest value where the pin is guaranteed to be read as low 2. "Min" means the lowest value where the pin is guaranteed to be read as high 3. Although each I/O port can sink more than the test conditions (20 mA at VCC = 5V, 10 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 1.)The sum of all IOL, for ports A0-A7, G2, C4-C7 should not exceed 100 mA. 2.)The sum of all IOL, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA. 3.)The sum of all IOL, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA. 4.)The sum of all IOL, for ports F0-F7 should not exceed 100 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition. 4. Although each I/O port can source more than the test conditions (20 mA at VCC = 5V, 10 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 1)The sum of all IOH, for ports A0-A7, G2, C4-C7 should not exceed 100 mA. 2)The sum of all IOH, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA. 3)The sum of all IOH, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA. 4)The sum of all IOH, for ports F0-F7 should not exceed 100 mA. If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition. 5. All DC Characteristics contained in this datasheet are based on simulation and characterization of other AVR microcontrollers manufactured in the same process technology. These values are preliminary values representing design targets, and will be updated after characterization of actual silicon 6. Values with "PRR - Power Reduction Register" disabled (0x00). 7. Power-down values includes Input Leakage Current. 317 2593O-AVR-02/12 26.3 Speed Grades Maximum frequency is depending on VCC. As shown in Figure 26-1 and Figure 26-2, the Maximum Frequency vs. VCC curve is linear between 1.8V < VCC < 2.7V and between 2.7V < VCC < 4.5V. Figure 26-1. Maximum Frequency vs. VCC, ATmega644V 10 MHz Safe Operating Area 4 MHz 1.8V 2.7V 5.5V Figure 26-2. Maximum Frequency vs. VCC, ATmega644 20 MHz 10 MHz Safe Operating Area 2.7V 318 4.5V 5.5V ATmega644 2593O-AVR-02/12 ATmega644 26.4 Clock Characteristics Table 26-1. Calibration Accuracy of Internal RC Oscillator Frequency VCC Temperature Calibration Accuracy 8.0 MHz 3V 25C 10% 7.3 MHz - 8.1 MHz 1.8V - 5.5V(1) 2.7V - 5.5V(2) -40C - 85C 1% Factory Calibration User Calibration Notes: 26.4.1 1. Voltage range for ATmega644V. 2. Voltage range for ATmega644. External Clock Drive Waveforms Figure 26-3. External Clock Drive Waveforms V IH1 V IL1 26.4.2 External Clock Drive Table 26-2. External Clock Drive VCC = 1.8V - 5.5V VCC = 2.7V - 5.5V VCC = 4.5V - 5.5V Symbol Parameter Min. Max. Min. Max. Min. Max. Units 1/tCLCL Oscillator Frequency 0 2 0 8 0 16 MHz tCLCL Clock Period 500 125 62.5 tCHCX High Time 200 50 25 tCLCX Low Time 200 50 25 tCLCH Rise Time 2.0 1.6 0.5 tCHCL Fall Time 2.0 1.6 0.5 tCLCL Change in period from one clock cycle to the next 2 2 2 Note: ns s % All DC Characteristics contained in this datasheet are based on simulation and characterization of other AVR microcontrollers manufactured in the same process technology. These values are preliminary values representing design targets, and will be updated after characterization of actual silicon. 319 2593O-AVR-02/12 26.5 System and Reset Characteristics Table 26-3. Symbol Reset, Brown-out and Internal Voltage Reference Characteristics Min Typ Max Power-on Reset Threshold Voltage (rising) 0.7 1.0 1.4 Power-on Reset Threshold Voltage (falling)(1) 0.05 0.9 1.3 VPSR Power-on Slope Rate 0.01 4.5 V/ms VRST RESET Pin Threshold Voltage 0.1VCC 0.9VCC V tRST Minimum pulse width on RESET Pin 1.5 s VPOT VHYST Parameter Condition V Brown-out Detector Hysteresis 50 tBOD Min Pulse Width on Brown-out Reset VBG Bandgap reference voltage VCC = 2.7 TA = 25C tBG Bandgap reference start-up time IBG Bandgap reference current consumption Note: Units mV ns 1.0 1.1 1.2 V VCC = 2.7 TA = 25C 40 70 s VCC = 2.7 TA = 25C 10 A 1. The Power-on Reset will not work unless the supply voltage has been below VPOT (falling) Table 26-4. BODLEVEL Fuse Coding(1) BODLEVEL [2:0] Fuses Min VBOT 111 Typ VBOT Max VBOT Units BOD Disabled 110 1.7 1.8 2.0 101 2.5 2.7 2.9 100 4.1 4.3 4.5 V 011 010 Reserved 001 000 Note: 320 1. VBOT may be below nominal minimum operating voltage for some devices. For devices where this is the case, the device is tested down to VCC = VBOT during the production test. This guarantees that a Brown-Out Reset will occur before VCC drops to a voltage where correct operation of the microcontroller is no longer guaranteed. The test is performed using BODLEVEL = 110 for ATmega644 and BODLEVEL = 101 for ATmega644V. ATmega644 2593O-AVR-02/12 ATmega644 26.6 2-wire Serial Interface Characteristics Table 26-5 describes the requirements for devices connected to the 2-wire Serial Bus. The ATmega644 2-wire Serial Interface meets or exceeds these requirements under the noted conditions. Timing symbols refer to Figure 26-4. Table 26-5. 2-wire Serial Bus Requirements Symbol Parameter VIL Min Max Input Low-voltage -0.5 0.3VCC VIH Input High-voltage 0.7VCC VCC + 0.5 Vhys(1) Hysteresis of Schmitt Trigger Inputs 0.05VCC(2) - VOL(1) Output Low-voltage 0 0.4 tr(1) Rise Time for both SDA and SCL tof(1) Output Fall Time from VIHmin to VILmax tSP(1) Spikes Suppressed by Input Filter Ii Input Current each I/O Pin Ci(1) Capacitance for each I/O Pin fSCL SCL Clock Frequency Rp 3 mA sink current Hold Time (repeated) START Condition tLOW Low Period of the SCL Clock tHIGH High period of the SCL clock tSU;STA Set-up time for a repeated START condition tHD;DAT Data hold time tSU;DAT Data setup time tSU;STO Setup time for STOP condition tBUF Bus free time between a STOP and START condition (2)(3) 300 20 + 0.1Cb(2)(3) 250 20 + 0.1Cb 10 pF < Cb < 400 pF(3) 0 0.1VCC < Vi < 0.9VCC Units V ns (2) 50 -10 10 A - 10 pF fCK(4) > max(16fSCL, 250kHz)(5) 0 400 kHz fSCL 100 kHz V CC - 0.4 V ----------------------------3 mA 1000n --------------------sCb fSCL > 100 kHz V CC - 0.4 V ----------------------------3 mA 300 ns----------------Cb fSCL 100 kHz 4.0 - fSCL > 100 kHz 0.6 - fSCL 100 kHz 4.7 - fSCL > 100 kHz 1.3 - fSCL 100 kHz 4.0 - fSCL > 100 kHz 0.6 - fSCL 100 kHz 4.7 - fSCL > 100 kHz 0.6 - fSCL 100 kHz 0 3.45 fSCL > 100 kHz 0 0.9 fSCL 100 kHz 250 - fSCL > 100 kHz 100 - fSCL 100 kHz 4.0 - fSCL > 100 kHz 0.6 - fSCL 100 kHz 4.7 - fSCL > 100 kHz 1.3 - Value of Pull-up resistor tHD;STA Notes: Condition s ns s 1. In ATmega644, this parameter is characterized and not 100% tested. 2. Required only for fSCL > 100 kHz. 3. Cb = capacitance of one bus line in pF. 321 2593O-AVR-02/12 4. fCK = CPU clock frequency 5. This requirement applies to all ATmega32 Two-wire Serial Interface operation. Other devices connected to the Two-wire Serial Bus need only obey the general fSCL requirement. Figure 26-4. 2-wire Serial Bus Timing tHIGH tof tLOW tr tLOW SCL tSU;STA tHD;STA tHD;DAT tSU;DAT tSU;STO SDA tBUF 26.7 SPI Timing Characteristics See Figure 26-5 and Figure 26-6 for details. Table 26-6. Description Mode 1 SCK period Master See Table 16-5 2 SCK high/low Master 50% duty cycle 3 Rise/Fall time Master 3.6 4 Setup Master 10 5 Hold Master 10 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 * tck 12 Rise/Fall time Slave 13 Setup Slave 10 14 Hold Slave tck 15 SCK to out Slave 16 SCK to SS high Slave 17 SS high to tri-state Slave 18 SS low to SCK Slave Note: 322 SPI Timing Parameters Min Typ Max ns 1600 15 20 10 20 1. In SPI Programming mode the minimum SCK high/low period is: - 2 tCLCL for fCK < 12 MHz - 3 tCLCL for fCK > 12 MHz ATmega644 2593O-AVR-02/12 ATmega644 Figure 26-5. SPI Interface Timing Requirements (Master Mode) SS 6 1 SCK (CPOL = 0) 2 2 SCK (CPOL = 1) 4 MISO (Data Input) 5 3 MSB ... LSB 8 7 MOSI (Data Output) MSB ... LSB Figure 26-6. SPI Interface Timing Requirements (Slave Mode) SS 10 9 16 SCK (CPOL = 0) 11 11 SCK (CPOL = 1) 13 MOSI (Data Input) 14 12 MSB ... LSB 15 MISO (Data Output) MSB 17 ... LSB X 323 2593O-AVR-02/12 26.8 ADC Characteristics Table 26-7. Symbol ADC Characteristics Parameter Min(1) Typ(1) Units 10 Differential Conversion Gain = 1x or 20x 8 Differential Conversion Gain = 200x 7 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz 4.5 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz Noise Reduction Mode 2 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz Noise Reduction Mode 4.5 Integral Non-Linearity (INL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.5 Differential Non-Linearity (DNL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.25 Gain Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2 Offset Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2 Conversion Time Free Running Conversion 13 260 s Clock Frequency Single Ended Conversion 50 1000 kHz VCC - 0.3 VCC + 0.3 Single Ended Conversion 1.0 AVCC Differential Conversion 1.0 AVCC - 0.5 Single ended channels GND VREF Differential Conversion 0 AVCC Absolute accuracy (Including INL, DNL, quantization error, gain and offset error) AVCC Analog Supply Voltage VREF Reference Voltage Input Voltage Single Ended Channels Bits 2.5 LSB V 38,5 Input Bandwidth kHz Differential Channels 324 Max(1) Single Ended Conversion Resolution VIN Condition 4 ATmega644 2593O-AVR-02/12 ATmega644 Table 26-7. Symbol ADC Characteristics (Continued) Min(1) Typ(1) Max(1) 1.1V 1.0 1.1 1.2 2.56V 2.4 2.56 2.8 Parameter Condition VINT1 Internal Voltage Reference VINT2 Internal Voltage Reference RREF Reference Input Resistance 32 k RAIN Analog Input Resistance 100 M Notes: Units V 1. Values are guidelines only. Actual values are TBD 325 2593O-AVR-02/12 27. Typical Characteristics The following charts show typical behavior. These figures are not tested during manufacturing. All current consumption measurements are performed with all I/O pins configured as inputs and with internal pull-ups enabled. A sine wave generator with rail-to-rail output is used as clock source. All Active- and Idle current consumption measurements are done with all bits in the PRR registers set and thus, the corresponding I/O modules are turned off. Also the Analog Comparator is disabled during these measurements. Table 27-1 on page 331 and Table 27-2 on page 332 show the additional current consumption compared to ICC Active and ICC Idle for every I/O module controlled by the Power Reduction Register. See "Power Reduction Register" on page 41 for details. The power consumption in Power-down mode is independent of clock selection. The current consumption is a function of several factors such as: operating voltage, operating frequency, loading of I/O pins, switching rate of I/O pins, code executed and ambient temperature. The dominating factors are operating voltage and frequency. The current drawn from capacitive loaded pins may be estimated (for one pin) as CL*VCC*f where CL = load capacitance, VCC = operating voltage and f = average switching frequency of I/O pin. The parts are characterized at frequencies higher than test limits. Parts are not guaranteed to function properly at frequencies higher than the ordering code indicates. The difference between current consumption in Power-down mode with Watchdog Timer enabled and Power-down mode with Watchdog Timer disabled represents the differential current drawn by the Watchdog Timer. 27.1 Active Supply Current Figure 27-1. Active Supply Current vs. Low Frequency (0.1 MHz - 1.0 MHz) 1,6 5.5V 1,4 5.0V 1,2 4.5V ICC (m A) 1 4.0V 0,8 3.3V 0,6 2.7V 0,4 1.8V 0,2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) 326 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-2. Active Supply Current vs. Frequency (1 MHz - 20 MHz) 20 5.5V ICC (mA) 18 16 5.0V 14 4.5V 12 4.0V 10 8 3.3V 6 2.7V 4 2 1.8V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 27-3. Active Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) 12 10 85C 25C -40C ICC (mA) 8 6 4 2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 327 2593O-AVR-02/12 Figure 27-4. Active Supply Current vs. VCC (Internal RC Oscillator, 1 MHz) 1.8 85C 25C -40C 1.6 1.4 ICC (mA) 1.2 1 0.8 0.6 0.4 0.2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-5. Active Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) 0.3 -40C 25C 85C 0.25 ICC (mA) 0.2 0.15 0.1 0.05 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 328 ATmega644 2593O-AVR-02/12 ATmega644 27.2 Idle Supply Current Figure 27-6. Idle Supply Current vs. Low Frequency (0.1 MHz - 1.0 MHz) 0.1 MHz - 1.0 MHz 0.35 5.5V 0.3 5.0V 4.5V ICC (m A) 0.25 4.0V 0.2 3.3V 0.15 2.7V 0.1 1.8V 0.05 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) Figure 27-7. Idle Supply Current vs. Frequency (1 MHz - 20 MHz) 6 5.5V 5 5.0V 4.5V ICC (mA) 4 3 4.0V 2 3.3V 2.7V 1 1.8V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) 329 2593O-AVR-02/12 Figure 27-8. Idle Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) 3 2.5 85C 25C -40C ICC (mA) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-9. Idle Supply Current vs. VCC (internal RC Oscillator, 1 MHz) 0.6 85C 25C -40C 0.5 ICC (mA) 0.4 0.3 0.2 0.1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 330 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-10. Idle Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) 0.14 -40C 25C 85C 0.12 ICC (mA) 0.1 0.08 0.06 0.04 0.02 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.3 Supply Current of IO modules The tables and formulas below can be used to calculate the additional current consumption for the different I/O modules in Active and Idle mode. The enabling or disabling of the I/O modules are controlled by the Power Reduction Register. See "Power Reduction Register" on page 41 for details. Table 27-1. Additional Current Consumption for the different I/O modules (absolute values) PRR bit Typical numbers VCC = 2V, F = 1 MHz VCC = 3V, F = 4 MHz VCC = 5V, F = 8 MHz PRUSART0 8.0 A 51 A 220 A PRTWI 12 A 75 A 315 A PRTIM2 11 A 72 A 300 A PRTIM1 6.0 A 39 A 150 A PRTIM0 4.0 A 24 A 100 A PRSPI 15 A 95 A 400 A PRADC 12 A 75 A 315 A 331 2593O-AVR-02/12 Table 27-2. Additional Current Consumption (percentage) in Active and Idle mode PRR bit Additional Current consumption compared to Active with external clock (see Figure 27-1 on page 326 and Figure 27-2 on page 327) Additional Current consumption compared to Idle with external clock (see Figure 27-6 on page 329 and Figure 27-7 on page 329) PRUSART0 3.0% 17% PRTWI 4.4% 24% PRTIM2 4.3% 23% PRTIM1 1.8% 10% PRTIM0 1.5% 8.0% PRSPI 3.3% 18% PRADC 4.5% 24% It is possible to calculate the typical current consumption based on the numbers from Table 27-1 for other VCC and frequency settings than listed in Table 27-2. Example Calculate the expected current consumption in idle mode with USART0, TIMER1, and TWI enabled at VCC = 2.0V and F = 1 MHz. From Table 27-2, third column, we see that we need to add 17% for the USART0, 24% for the TWI, and 10% for the TIMER1 module. Reading from Figure 27-6 on page 329, we find that the idle current consumption is ~0.11 mA at VCC = 2.0V and F = 1 MHz. The total current consumption in idle mode with USART0, TIMER1, and TWI enabled, gives: I CC total 0.11mA * ( 1 + 0.117 + 0.24 + 0.10 ) 0.166mA 27.4 Power-down Supply Current Figure 27-11. Power-down Supply Current vs. VCC (Watchdog Timer Disabled) 3 85C 2.5 ICC (A) 2 1.5 1 -40C 25C 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 332 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-12. Power-down Supply Current vs. VCC (Watchdog Timer Enabled) 12 85C -40C 25C 10 ICC (A) 8 6 4 2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.5 Power-save Supply Current Figure 27-13. Power-save Supply Current vs. VCC (Watchdog Timer Disabled) 10 9 25 C 8 ICC (A) 7 6 5 4 3 2 1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 333 2593O-AVR-02/12 27.6 Standby Supply Current Figure 27-14. Standby Supply Current vs. VCC (32 kHz XTAL, Watchdog Timer Disabled) 0.014 0.012 ICC (mA) 0.01 0.008 0.006 0.004 0.002 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-15. Standby Supply Current vs. VCC (455 kHz Resonator, Watchdog Timer Disabled) 0.07 0.06 ICC (mA) 0.05 0.04 0.03 0.02 0.01 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 334 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-16. Standby Supply Current vs, VCC (1 MHz Resonator, Watchdog Timer Disabled) 0.06 0.05 ICC (mA) 0.04 0.03 0.02 0.01 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-17. Standby Supply Current vs. VCC (2 MHz Resonator, Watchdog Timer Disabled) 0.09 0.08 0.07 ICC (mA) 0.06 0.05 0.04 0.03 0.02 0.01 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 335 2593O-AVR-02/12 Figure 27-18. Standby Supply Current vs. VCC (2 MHz XTAL, Watchdog Timer Disabled) 0.08 0.07 0.06 ICC (mA) 0.05 0.04 0.03 0.02 0.01 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-19. Standby Supply Current vs. VCC (4 MHz Resonator, Watchdog Timer Disabled) 0.14 0.12 ICC (mA) 0.1 0.08 0.06 0.04 0.02 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 336 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-20. Standby Supply Current vs. VCC (4 MHz XTAL, Watchdog Timer Disabled) 0.14 0.12 I CC(mA) 0.1 0.08 0.06 0.04 0.02 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-21. Standby Supply Current vs. VCC (6 MHz Resonator, Watchdog Timer Disabled) 0.18 0.16 0.14 ICC (mA) 0.12 0.1 0.08 0.06 0.04 0.02 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 337 2593O-AVR-02/12 Figure 27-22. Standby Supply Current vs. VCC (6 MHz XTAL, Watchdog Timer Disabled) 0.18 0.16 0.14 ICC (mA) 0.12 0.1 0.08 0.06 0.04 0.02 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.7 Pin Pull-up Figure 27-23. I/O Oin Pull-up Resistor Current vs. Input Voltage (VCC = 5V) 160 140 120 IIO (A) 100 80 60 40 25C 85C -40C 20 0 0 1 2 3 4 5 6 VIO (V) 338 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-24. I/O Pin Pull-up Resistor Current vs. Input Voltage (VCC = 2.7V) 90 80 70 IIO (A) 60 50 40 30 20 25C 85C -40C 10 0 0 0.5 1 1.5 2 2.5 3 VIO (V) Figure 27-25. I/O pin Pull-up Resistor Current vs. Input Voltage (VCC = 1.8V) 60 50 IIO (A) 40 30 20 25C 85C -40C 10 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 VIO (V) 339 2593O-AVR-02/12 Figure 27-26. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 5V) 120 100 IRESET (A) 80 60 40 25C 20 -40C 85C 0 0 1 2 3 4 5 6 VRESET (V) Figure 27-27. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 2.7V) 70 60 IRESET (A) 50 40 30 20 25C 10 -40C 85C 0 0 0.5 1 1.5 2 2.5 3 VRESET(V) 340 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-28. Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 1.8V) 40 35 IRESET (A) 30 25 20 15 10 25C -40C 85C 5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 VRESET(V) 27.8 Pin Driver Strength Figure 27-29. I/O Pin Output Voltage vs. Sink Current (VCC = 5V) 0.6 85C 0.5 25C VOL (V) 0.4 -40C 0.3 0.2 0.1 0 0 5 10 15 20 25 IOL (mA) 341 2593O-AVR-02/12 Figure 27-30. I/O Pin Output Voltage vs. Sink Current (VCC = 3V) 0.9 85C 0.8 0.7 25C VOL (V) 0.6 -40C 0.5 0.4 0.3 0.2 0.1 0 0 5 10 15 20 25 IOL(mA) Figure 27-31. I/O Pin Output Voltage vs. Source Current (VCC = 5V) 5.1 5 VOH (V) 4.9 4.8 4.7 4.6 -40C 25C 4.5 85C 4.4 0 5 10 15 20 25 IOH (mA) 342 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-32. I/O Pin Output Voltage vs. Source Current (VCC = 3V) 3.5 3 VOH (V) 2.5 -40C 25C 85C 2 1.5 1 0.5 0 0 5 10 15 20 25 IOH (mA) 27.9 Pin Threshold and Hysteresis Figure 27-33. I/O Pin Input Threshold Voltage vs. VCC (VIH, IO Pin Read as "1") 2.5 -40C 25C 85C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 343 2593O-AVR-02/12 Figure 27-34. I/O Pin Input Threshold Voltage vs. VCC (VIL, IO Pin Read as "0") 2.5 85C 25C -40C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-35. I/O Pin Input Hysteresis vs. VCC 0.6 Input Hysteresis (mV) 0.5 -40C 25C 0.4 85C 0.3 0.2 0.1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 344 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-36. Reset Input Threshold vs.VCC (VIH, IO Pin Read as "1") 2.5 25C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-37. Reset Input Threshold Voltage vs. VCC (VIL, IO Pin Read as "0") 2.5 25C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 345 2593O-AVR-02/12 Figure 27-38. Reset Pin Input Hysteresis vs. VCC| 0.45 Input Hysteresis (mV) 0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 25C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.10 BOD Threshold and Analog Comparator Offset Figure 27-39. BOD Threshold vs. Temperature (BOD Level is 4.3V) 5 Threshold (V) 4.5 Raising Vcc Falling Vcc 4 3.5 3 2.5 2 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 Temperature (C) 346 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-40. BOD Threshold vs. Temperature (BOD Level is 2.7V) 4 Threshold (V) 3.5 3 Raising Vcc Falling Vcc 2.5 2 1.5 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 Temperature (C) Figure 27-41. BOD Threshold vs. Temperature (BOD Level is 1.8V) 2.5 Threshold (V) 2 Raising Vcc Falling Vcc 1.5 1 0.5 0 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 Temperature (C) 347 2593O-AVR-02/12 Figure 27-42. Bandgap Voltage vs. VCC 1.072 Bandgap Voltage (V) 1.07 1.068 1.066 25C 1.064 1.062 -40C 1.06 1.058 85C 1.056 1.054 1.5 2 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) 27.11 Internal Oscillator Speed Figure 27-43. Watchdog Oscillator Frequency vs. VCC 130 128 126 FRC (kHz) 124 -40C 122 25C 120 118 116 85C 114 112 110 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 348 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-44. Calibrated 8 MHz RC Oscillator Frequency vs. Temperature 8.3 5.5V 5.0V 4.5V 4.0V 3.3V 2.7V 8.2 FRC (MHz) 8.1 8 7.9 7.8 7.7 -60 -40 -20 0 20 40 60 80 100 Temperature (C) Figure 27-45. Calibrated 8 MHz RC Oscillator Frequency vs. Operating Voltage 8.5 8.4 8.3 85C FRC (MHz) 8.2 8.1 25C 8 7.9 7.8 -40C 7.7 7.6 7.5 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 349 2593O-AVR-02/12 Figure 27-46. Calibrated 8 Mhz RC Oscillator Frequency vs. Osccal Value 18 85C 25C -40C 16 14 FRC (MHz) 12 10 8 6 4 2 0 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 OSCCAL VALUE 27.12 Current Consumption of Peripheral Units Figure 27-47. Brownout Detector Current vs. VCC 30 85C 25C -40C 25 ICC (A) 20 15 10 5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 350 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-48. ADC Current vs. VCC (AREF = AVCC) 400 85C -40C 25C 350 300 ICC (A) 250 200 150 100 50 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-49. AREF Current With ADC at 1 MHz va. VCC 250 -40C 25C 85C ICC (A) 200 150 100 50 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 351 2593O-AVR-02/12 Figure 27-50. Watchdog Timer Current vs. VCC 9 -40C 8 25C 85C 7 I CC (A) 6 5 4 3 2 1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-51. Analog Comparator Current vs. VCC 90 -40C 80 25C 85C 70 ICC (A) 60 50 40 30 20 10 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 352 ATmega644 2593O-AVR-02/12 ATmega644 Figure 27-52. Programming Current vs. VCC 16 14 -40C ICC (mA) 12 25C 10 85C 8 6 4 2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 353 2593O-AVR-02/12 28. Register Summary Address (0xFF) Bit 7 Bit 6 Bit 5 Bit 4 Reserved Name - - - - Bit 3 Bit 2 Bit 1 Bit 0 - - - (0xFE) Reserved - - - - - - - - (0xFD) Reserved - - - - - - - - (0xFC) Reserved - - - - - - - - (0xFB) Reserved - - - - - - - (0xFA) Reserved - - - - - - - (0xF9) Reserved - - - - - - - (0xF8) Reserved - - - - - - - - (0xF7) Reserved - - - - - - - - (0xF6) Reserved - - - - - - - - (0xF5) Reserved - - - - - - - (0xF4) Reserved - - - - - - - - (0xF3) Reserved - - - - - - - - (0xF2) Reserved - - - - - - - - (0xF1) Reserved - - - - - - - (0xF0) Reserved - - - - - - - (0xEF) Reserved - - - - - - - (0xEE) Reserved - - - - - - - - (0xED) Reserved - - - - - - - - (0xEC) Reserved - - - - - - - - (0xEB) Reserved - - - - - - - (0xEA) Reserved - - - - - - - - (0xE9) Reserved - - - - - - - - (0xE8) Reserved - - - - - - - - (0xE7) Reserved - - - - - - - (0xE6) Reserved - - - - - - - - (0xE5) Reserved - - - - - - - - (0xE4) Reserved - - - - - - - - (0xE3) Reserved - - - - - - - (0xE2) Reserved - - - - - - - (0xE1) Reserved - - - - - - - (0xE0) Reserved - - - - - - - (0xDF) Reserved - - - - - - - - (0xDE) Reserved - - - - - - - - (0xDD) Reserved - - - - - - - - (0xDC) Reserved - - - - - - - (0xDB) Reserved - - - - - - - - (0xDA) Reserved - - - - - - - - (0xD9) Reserved - - - - - - - - (0xD8) Reserved - - - - - - - - (0xD7) Reserved - - - - - - - - (0xD6) Reserved - - - - - - - - (0xD5) Reserved - - - - - - - - (0xD4) Reserved - - - - - - - - (0xD3) Reserved - - - - - - - - (0xD2) Reserved - - - - - - - - (0xD1) Reserved - - - - - - - - (0xD0) Reserved - - - - - - - - (0xCF) Reserved - - - - - - - - (0xCE) Reserved - - - - - - - - (0xCD) Reserved - - - - - - - - (0xCC) Reserved - - - - - - - - (0xCB) Reserved - - - - - - - - (0xCA) Reserved - - - - - - - - (0xC9) Reserved - - - - - - - - (0xC8) Reserved - - - - - - - - (0xC7) Reserved - - - - - - - - (0xC6) UDR0 (0xC5) UBRR0H 354 - - - USART0 I/O Data Register - - - (0xC4) UBRR0L (0xC3) Reserved - - (0xC2) UCSR0C UMSEL01 UMSEL00 (0xC1) UCSR0B RXCIE0 TXCIE0 (0xC0) UCSR0A RXC0 TXC0 UDRE0 - Page 182 USART0 Baud Rate Register High Byte 186/198 USART0 Baud Rate Register Low Byte 186/198 - - - - - UPM01 UPM00 USBS0 UCSZ01 UCSZ00 UCPOL0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 183/197 FE0 DOR0 UPE0 U2X0 MPCM0 182/196 184/197 ATmega644 2593O-AVR-02/12 ATmega644 Address (0xBF) Name Reserved Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 - - - - - - - - Page (0xBE) Reserved - - - - - - - (0xBD) TWAMR TWAM6 TWAM5 TWAM4 TWAM3 TWAM2 TWAM1 TWAM0 - (0xBC) TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN - TWIE (0xBB) TWDR (0xBA) TWAR TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE 228 (0xB9) TWSR TWS7 TWS6 TWS5 TWS4 TWS3 - TWPS1 TWPS0 227 2-wire Serial Interface Data Register 228 225 227 (0xB8) TWBR (0xB7) Reserved - - - 2-wire Serial Interface Bit Rate Register - - - - - 225 (0xB6) ASSR - EXCLK AS2 TCN2UB OCR2AUB OCR2BUB TCR2AUB TCR2BUB (0xB5) Reserved - - - - - - - - (0xB4) OCR2B Timer/Counter2 Output Compare Register B (0xB3) OCR2A Timer/Counter2 Output Compare Register A 150 (0xB2) TCNT2 Timer/Counter2 (8 Bit) 150 (0xB1) TCCR2B FOC2A FOC2B - - WGM22 CS22 CS21 CS20 149 (0xB0) TCCR2A COM2A1 COM2A0 COM2B1 COM2B0 - - WGM21 WGM20 146 (0xAF) Reserved - - - - - - - - 150 150 (0xAE) Reserved - - - - - - - - (0xAD) Reserved - - - - - - - - (0xAC) Reserved - - - - - - - - (0xAB) Reserved - - - - - - - - (0xAA) Reserved - - - - - - - - (0xA9) Reserved - - - - - - - - (0xA8) Reserved - - - - - - - - (0xA7) Reserved - - - - - - - - (0xA6) Reserved - - - - - - - - (0xA5) Reserved - - - - - - - - (0xA4) Reserved - - - - - - - - (0xA3) Reserved - - - - - - - - (0xA2) Reserved - - - - - - - - (0xA1) Reserved - - - - - - - - (0xA0) Reserved - - - - - - - - (0x9F) Reserved - - - - - - - - (0x9E) Reserved - - - - - - - - (0x9D) Reserved - - - - - - - - (0x9C) Reserved - - - - - - - - (0x9B) Reserved - - - - - - - - (0x9A) Reserved - - - - - - - - (0x99) Reserved - - - - - - - - (0x98) Reserved - - - - - - - - (0x97) Reserved - - - - - - - - (0x96) Reserved - - - - - - - - (0x95) Reserved - - - - - - - - (0x94) Reserved - - - - - - - - (0x93) Reserved - - - - - - - - (0x92) Reserved - - - - - - - - (0x91) Reserved - - - - - - - - (0x90) Reserved - - - - - - - - (0x8F) Reserved - - - - - - - - (0x8E) Reserved - - - - - - - - (0x8D) Reserved - - - - - - - - (0x8C) Reserved - - - - - - - - (0x8B) OCR1BH Timer/Counter1 - Output Compare Register B High Byte (0x8A) OCR1BL Timer/Counter1 - Output Compare Register B Low Byte 129 (0x89) OCR1AH Timer/Counter1 - Output Compare Register A High Byte 129 (0x88) OCR1AL Timer/Counter1 - Output Compare Register A Low Byte 129 (0x87) ICR1H Timer/Counter1 - Input Capture Register High Byte 130 (0x86) ICR1L Timer/Counter1 - Input Capture Register Low Byte 130 (0x85) TCNT1H Timer/Counter1 - Counter Register High Byte 129 129 (0x84) TCNT1L (0x83) Reserved - - - Timer/Counter1 - Counter Register Low Byte (0x82) TCCR1C FOC1A FOC1B - - - - - - 128 (0x81) TCCR1B ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 127 (0x80) TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 - - WGM11 WGM10 125 (0x7F) DIDR1 - - - - - - AIN1D AIN0D 232 (0x7E) DIDR0 ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D 252 - - 129 - - - 355 2593O-AVR-02/12 Address (0x7D) Name Reserved Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 - - - - - - - - Page (0x7C) ADMUX REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 248 (0x7B) ADCSRB - ACME - - - ADTS2 ADTS1 ADTS0 231 (0x7A) ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 (0x79) ADCH ADC Data Register High byte 249 251 (0x78) ADCL (0x77) Reserved - - - - - - - - (0x76) Reserved - - - - - - - - (0x75) Reserved - - - - - - - - (0x74) Reserved - - - - - - - - (0x73) PCMSK3 PCINT31 PCINT30 PCINT29 PCINT28 PCINT27 PCINT26 PCINT25 PCINT24 (0x72) Reserved - - - - - - - - (0x71) Reserved - - - - - - - - (0x70) TIMSK2 - - - - - OCIE2B OCIE2A TOIE2 152 (0x6F) TIMSK1 - - ICIE1 - - OCIE1B OCIE1A TOIE1 130 (0x6E) TIMSK0 - - - - - OCIE0B OCIE0A TOIE0 101 (0x6D) PCMSK2 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 63 (0x6C) PCMSK1 PCINT15 PCINT14 PCINT13 PCINT12 PCINT11 PCINT10 PCINT9 PCINT8 63 (0x6B) PCMSK0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 64 (0x6A) Reserved - - - - - - - - (0x69) EICRA - - ISC21 ISC20 ISC11 ISC10 ISC01 ISC00 60 (0x68) PCICR - - - - PCIE3 PCIE2 PCIE1 PCIE0 62 (0x67) Reserved - - - - - - - - (0x66) OSCCAL (0x65) Reserved (0x64) PRR (0x63) Reserved (0x62) Reserved (0x61) CLKPR (0x60) WDTCSR ADC Data Register Low byte 251 Oscillator Calibration Register 63 37 - - - - - - - - PRTWI PRTIM2 PRTIM0 - PRTIM1 PRSPI PRUSART0 PRADC - - - - - - - - 44 - - - - - - - - CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0 37 WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 52 0x3F (0x5F) SREG I T H S V N Z C 11 0x3E (0x5E) SPH SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 11 0x3D (0x5D) SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 11 0x3C (0x5C) Reserved - - - - - - - - 0x3B (0x5B) Reserved - - - - - - - - 0x3A (0x5A) Reserved - - - - - - - - 0x39 (0x59) Reserved - - - - - - - - 0x38 (0x58) Reserved - - - - - - - - 0x37 (0x57) SPMCSR SPMIE RWWSB SIGRD RWWSRE BLBSET PGWRT PGERS SPMEN 0x36 (0x56) Reserved - - - - - - - - 0x35 (0x55) MCUCR JTD - - PUD - - IVSEL IVCE 84/267 0x34 (0x54) MCUSR - - - JTRF WDRF BORF EXTRF PORF 52/268 43 0x33 (0x53) SMCR - - - - SM2 SM1 SM0 SE 0x32 (0x52) Reserved - - - - - - - - 0x31 (0x51) OCDR 0x30 (0x50) ACSR ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0 - - - - - - - - On-Chip Debug Register 281 258 249 0x2F (0x4F) Reserved 0x2E (0x4E) SPDR 0x2D (0x4D) SPSR SPIF WCOL - - - - - SPI2X 162 0x2C (0x4C) SPCR SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 161 0x2B (0x4B) GPIOR2 General Purpose I/O Register 2 0x2A (0x4A) GPIOR1 General Purpose I/O Register 1 0x29 (0x49) Reserved 0x28 (0x48) OCR0B Timer/Counter0 Output Compare Register B 0x27 (0x47) OCR0A Timer/Counter0 Output Compare Register A 101 0x26 (0x46) TCNT0 Timer/Counter0 (8 Bit) 101 0x25 (0x45) TCCR0B FOC0A FOC0B - - WGM02 CS02 CS01 CS00 0x24 (0x44) TCCR0A COM0A1 COM0A0 COM0B1 COM0B0 - - WGM01 WGM00 101 0x23 (0x43) GTCCR TSM - - - - - PSRASY PSRSYNC 153 0x22 (0x42) EEARH - - - 0x21 (0x41) EEARL 0x20 (0x40) EEDR 0x1F (0x3F) EECR SPI 0 Data Register - - - - 163 25 25 - - - - 101 EEPROM Address Register High Byte 21 EEPROM Address Register Low Byte 21 EEPROM Data Register - - EEPM1 EEPM0 EERIE 100 21 EEMPE EEPE EERE 21 0x1E (0x3E) GPIOR0 0x1D (0x3D) EIMSK - - - - - INT2 INT1 INT0 61 0x1C (0x3C) EIFR - - - - - INTF2 INTF1 INTF0 61 356 General Purpose I/O Register 0 26 ATmega644 2593O-AVR-02/12 ATmega644 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page 0x1B (0x3B) Address PCIFR Name - - - - PCIF3 PCIF2 PCIF1 PCIF0 62 0x1A (0x3A) Reserved - - - - - - - - 0x19 (0x39) Reserved - - - - - - - - 0x18 (0x38) Reserved - - - - - - - - 0x17 (0x37) TIFR2 - - - - - OCF2b OCF2A TOV2 152 0x16 (0x36) TIFR1 - - ICF1 - - OCF1B OCF1A TOV1 131 0x15 (0x35) TIFR0 - - - - - OCF0B OCF0A TOV0 102 0x14 (0x34) Reserved - - - - - - - - 0x13 (0x33) Reserved - - - - - - - - 0x12 (0x32) Reserved - - - - - - - - 0x11 (0x31) Reserved - - - - - - - - 0x10 (0x30) Reserved - - - - - - - - 0x0F (0x2F) Reserved - - - - - - - - 0x0E (0x2E) Reserved - - - - - - - - 0x0D (0x2D) Reserved - - - - - - - - 0x0C (0x2C) Reserved - - - - - - - - 0x0B (0x2B) PORTD PORTD7 PORTD6 PORTD5 PORTD4 PORTD3 PORTD2 PORTD1 PORTD0 85 0x0A (0x2A) DDRD DDD7 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0 85 0x09 (0x29) PIND PIND7 PIND6 PIND5 PIND4 PIND3 PIND2 PIND1 PIND0 85 0x08 (0x28) PORTC PORTC7 PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0 85 0x07 (0x27) DDRC DDC7 DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0 85 0x06 (0x26) PINC PINC7 PINC6 PINC5 PINC4 PINC3 PINC2 PINC1 PINC0 85 0x05 (0x25) PORTB PORTB7 PORTB6 PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 84 0x04 (0x24) DDRB DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 84 0x03 (0x23) PINB PINB7 PINB6 PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 84 0x02 (0x22) PORTA PORTA7 PORTA6 PORTA5 PORTA4 PORTA3 PORTA2 PORTA1 PORTA0 84 0x01 (0x21) DDRA DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 84 0x00 (0x20) PINA PINA7 PINA6 PINA5 PINA4 PINA3 PINA2 PINA1 PINA0 84 Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written. 2. I/O registers within the address range $00 - $1F are directly bit-accessible using the SBI and CBI instructions. 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 only. 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 ATmega644 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 - $FF, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 357 2593O-AVR-02/12 29. Instruction Set Summary Mnemonics Operands Description Operation Flags #Clocks ARITHMETIC AND LOGIC INSTRUCTIONS ADD Rd, Rr Add two Registers Rd Rd + Rr Z,C,N,V,H ADC Rd, Rr Add with Carry two Registers Rd Rd + Rr + C Z,C,N,V,H 1 ADIW Rdl,K Add Immediate to Word Rdh:Rdl Rdh:Rdl + K Z,C,N,V,S 2 SUB Rd, Rr Subtract two Registers Rd Rd - Rr Z,C,N,V,H 1 SUBI Rd, K Subtract Constant from Register Rd Rd - K Z,C,N,V,H 1 SBC Rd, Rr Subtract with Carry two Registers Rd Rd - Rr - C Z,C,N,V,H 1 SBCI Rd, K Subtract with Carry Constant from Reg. Rd Rd - K - C Z,C,N,V,H 1 SBIW Rdl,K Subtract Immediate from Word Rdh:Rdl Rdh:Rdl - K Z,C,N,V,S 2 AND Rd, Rr Logical AND Registers Rd Rd * Rr Z,N,V 1 ANDI Rd, K Logical AND Register and Constant Rd Rd * K Z,N,V 1 OR Rd, Rr Logical OR Registers Rd Rd v Rr Z,N,V 1 ORI Rd, K Logical OR Register and Constant Rd Rd v K Z,N,V 1 EOR Rd, Rr Exclusive OR Registers Rd Rd Rr Z,N,V 1 1 COM Rd One's Complement Rd 0xFF - Rd Z,C,N,V 1 NEG Rd Two's Complement Rd 0x00 - Rd Z,C,N,V,H 1 SBR Rd,K Set Bit(s) in Register Rd Rd v K Z,N,V 1 CBR Rd,K Clear Bit(s) in Register Rd Rd * (0xFF - K) Z,N,V 1 INC Rd Increment Rd Rd + 1 Z,N,V 1 DEC Rd Decrement Rd Rd - 1 Z,N,V 1 TST Rd Test for Zero or Minus Rd Rd * Rd Z,N,V 1 CLR Rd Clear Register Rd Rd Rd Z,N,V 1 SER Rd Set Register Rd 0xFF None 1 MUL Rd, Rr Multiply Unsigned R1:R0 Rd x Rr Z,C 2 MULS Rd, Rr Multiply Signed R1:R0 Rd x Rr Z,C 2 MULSU Rd, Rr Multiply Signed with Unsigned R1:R0 Rd x Rr Z,C 2 FMUL Rd, Rr Fractional Multiply Unsigned R1:R0 (Rd x Rr) << 1 R1:R0 (Rd x Rr) << 1 R1:R0 (Rd x Rr) << 1 Z,C 2 Z,C 2 Z,C 2 2 FMULS Rd, Rr Fractional Multiply Signed FMULSU Rd, Rr Fractional Multiply Signed with Unsigned BRANCH INSTRUCTIONS RJMP k IJMP Relative Jump PC PC + k + 1 None Indirect Jump to (Z) PC Z None 2 JMP k Direct Jump PC k None 3 RCALL k Relative Subroutine Call PC PC + k + 1 None 4 Indirect Call to (Z) PC Z None 4 Direct Subroutine Call PC k None 5 RET Subroutine Return PC STACK None 5 RETI Interrupt Return PC STACK I 5 ICALL CALL k CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC PC + 2 or 3 None CP Rd,Rr Compare Rd - Rr Z, N,V,C,H 1 CPC Rd,Rr Compare with Carry Rd - Rr - C Z, N,V,C,H 1 CPI Rd,K Compare Register with Immediate Rd - K Z, N,V,C,H SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC PC + 2 or 3 None 1/2/3 1/2/3 1 SBRS Rr, b Skip if Bit in Register is Set if (Rr(b)=1) PC PC + 2 or 3 None 1/2/3 SBIC P, b Skip if Bit in I/O Register Cleared if (P(b)=0) PC PC + 2 or 3 None 1/2/3 SBIS P, b Skip if Bit in I/O Register is Set if (P(b)=1) PC PC + 2 or 3 None 1/2/3 BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) then PCPC+k + 1 None 1/2 BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then PCPC+k + 1 None 1/2 BREQ k Branch if Equal if (Z = 1) then PC PC + k + 1 None 1/2 BRNE k Branch if Not Equal if (Z = 0) then PC PC + k + 1 None 1/2 BRCS k Branch if Carry Set if (C = 1) then PC PC + k + 1 None 1/2 BRCC k Branch if Carry Cleared if (C = 0) then PC PC + k + 1 None 1/2 BRSH k Branch if Same or Higher if (C = 0) then PC PC + k + 1 None 1/2 BRLO k Branch if Lower if (C = 1) then PC PC + k + 1 None 1/2 BRMI k Branch if Minus if (N = 1) then PC PC + k + 1 None 1/2 BRPL k Branch if Plus if (N = 0) then PC PC + k + 1 None 1/2 BRGE k Branch if Greater or Equal, Signed if (N V= 0) then PC PC + k + 1 None 1/2 BRLT k Branch if Less Than Zero, Signed if (N V= 1) then PC PC + k + 1 None 1/2 BRHS k Branch if Half Carry Flag Set if (H = 1) then PC PC + k + 1 None 1/2 BRHC k Branch if Half Carry Flag Cleared if (H = 0) then PC PC + k + 1 None 1/2 BRTS k Branch if T Flag Set if (T = 1) then PC PC + k + 1 None 1/2 BRTC k Branch if T Flag Cleared if (T = 0) then PC PC + k + 1 None 1/2 BRVS k Branch if Overflow Flag is Set if (V = 1) then PC PC + k + 1 None 1/2 358 ATmega644 2593O-AVR-02/12 ATmega644 Mnemonics Operands Description Operation Flags #Clocks BRVC k Branch if Overflow Flag is Cleared if (V = 0) then PC PC + k + 1 None 1/2 BRIE k Branch if Interrupt Enabled if ( I = 1) then PC PC + k + 1 None 1/2 BRID k Branch if Interrupt Disabled if ( I = 0) then PC PC + k + 1 None 1/2 BIT AND BIT-TEST INSTRUCTIONS SBI P,b Set Bit in I/O Register I/O(P,b) 1 None 2 CBI P,b Clear Bit in I/O Register I/O(P,b) 0 None 2 LSL Rd Logical Shift Left Rd(n+1) Rd(n), Rd(0) 0 Z,C,N,V 1 LSR Rd Logical Shift Right Rd(n) Rd(n+1), Rd(7) 0 Z,C,N,V 1 ROL Rd Rotate Left Through Carry Rd(0)C,Rd(n+1) Rd(n),CRd(7) Z,C,N,V 1 ROR Rd Rotate Right Through Carry Rd(7)C,Rd(n) Rd(n+1),CRd(0) Z,C,N,V 1 ASR Rd Arithmetic Shift Right Rd(n) Rd(n+1), n=0..6 Z,C,N,V 1 SWAP Rd Swap Nibbles Rd(3..0)Rd(7..4),Rd(7..4)Rd(3..0) None 1 BSET s Flag Set SREG(s) 1 SREG(s) 1 BCLR s Flag Clear SREG(s) 0 SREG(s) 1 BST Rr, b Bit Store from Register to T T Rr(b) T 1 BLD Rd, b Bit load from T to Register Rd(b) T None 1 SEC Set Carry C1 C 1 CLC Clear Carry C0 C 1 SEN Set Negative Flag N1 N 1 CLN Clear Negative Flag N0 N 1 SEZ Set Zero Flag Z1 Z 1 CLZ Clear Zero Flag Z0 Z 1 SEI Global Interrupt Enable I1 I 1 CLI Global Interrupt Disable I0 I 1 SES Set Signed Test Flag S1 S 1 CLS Clear Signed Test Flag S0 S 1 SEV Set Twos Complement Overflow. V1 V 1 CLV Clear Twos Complement Overflow V0 V 1 SET Set T in SREG T1 T 1 CLT Clear T in SREG T0 T 1 SEH CLH Set Half Carry Flag in SREG Clear Half Carry Flag in SREG H1 H0 H H 1 1 Rd Rr Rd+1:Rd Rr+1:Rr None 1 None 1 1 DATA TRANSFER INSTRUCTIONS MOV Rd, Rr Move Between Registers MOVW Rd, Rr Copy Register Word LDI Rd, K Load Immediate Rd K None LD Rd, X Load Indirect Rd (X) None 2 LD Rd, X+ Load Indirect and Post-Inc. Rd (X), X X + 1 None 2 2 LD Rd, - X Load Indirect and Pre-Dec. X X - 1, Rd (X) None LD Rd, Y Load Indirect Rd (Y) None 2 LD Rd, Y+ Load Indirect and Post-Inc. Rd (Y), Y Y + 1 None 2 LD Rd, - Y Load Indirect and Pre-Dec. Y Y - 1, Rd (Y) None 2 LDD Rd,Y+q Load Indirect with Displacement Rd (Y + q) None 2 LD Rd, Z Load Indirect Rd (Z) None 2 LD Rd, Z+ Load Indirect and Post-Inc. Rd (Z), Z Z+1 None 2 LD Rd, -Z Load Indirect and Pre-Dec. Z Z - 1, Rd (Z) None 2 LDD Rd, Z+q Load Indirect with Displacement Rd (Z + q) None 2 LDS Rd, k Load Direct from SRAM Rd (k) None 2 ST X, Rr Store Indirect (X) Rr None 2 ST X+, Rr Store Indirect and Post-Inc. (X) Rr, X X + 1 None 2 ST - X, Rr Store Indirect and Pre-Dec. X X - 1, (X) Rr None 2 ST Y, Rr Store Indirect (Y) Rr None 2 ST Y+, Rr Store Indirect and Post-Inc. (Y) Rr, Y Y + 1 None 2 ST - Y, Rr Store Indirect and Pre-Dec. Y Y - 1, (Y) Rr None 2 STD Y+q,Rr Store Indirect with Displacement (Y + q) Rr None 2 ST Z, Rr Store Indirect (Z) Rr None 2 ST Z+, Rr Store Indirect and Post-Inc. (Z) Rr, Z Z + 1 None 2 ST -Z, Rr Store Indirect and Pre-Dec. Z Z - 1, (Z) Rr None 2 STD Z+q,Rr Store Indirect with Displacement (Z + q) Rr None 2 STS k, Rr Store Direct to SRAM (k) Rr None 2 Load Program Memory R0 (Z) None 3 LPM LPM Rd, Z Load Program Memory Rd (Z) None 3 LPM Rd, Z+ Load Program Memory and Post-Inc Rd (Z), Z Z+1 None 3 ELPM Rd, Z 3 SPM IN Rd, P Extended Load Program Memory Rd (Z) None Store Program Memory (Z) R1:R0 None - In Port Rd P None 1 359 2593O-AVR-02/12 Mnemonics Operands Description Operation Flags #Clocks OUT P, Rr Out Port P Rr None 1 PUSH Rr Push Register on Stack STACK Rr None 2 POP Rd Pop Register from Stack Rd STACK None 2 MCU CONTROL INSTRUCTIONS NOP No Operation None 1 SLEEP Sleep (see specific descr. for Sleep function) None 1 WDR BREAK Watchdog Reset Break (see specific descr. for WDR/timer) For On-chip Debug Only None None 1 N/A 360 ATmega644 2593O-AVR-02/12 ATmega644 30. Ordering Information 30.1 ATmega644 Speed (MHz)(3) Power Supply 10 20 Note: Ordering Code(2) Package(1) 1.8V - 5.5V ATmega644V-10AU ATmega644V-10PU ATmega644V-10MU 44A 40P6 44M1 Industrial (-40oC to 85oC) 2.7V - 5.5V ATmega644-20AU ATmega644-20PU ATmega644-20MU 44A 40P6 44M1 Industrial (-40oC to 85oC) Operational Range 1. This device can also be supplied in wafer form. Please contact your local Atmel sales office for detailed ordering information and minimum quantities. 2. Pb-free packaging, complies to the European Directive for Restriction of Hazardous Substances (RoHS directive). Also Halide free and fully Green. 3. For Speed vs. VCC see "Speed Grades" on page 318. Package Type 44A 44-lead, Thin (1.0 mm) Plastic Gull Wing Quad Flat Package (TQFP) 40P6 40-pin, 0.600" Wide, Plastic Dual Inline Package (PDIP) 44M1 44-pad, 7 x 7 x 1.0 mm body, lead pitch 0.50 mm, Quad Flat No-Lead/Micro Lead Frame Package (QFN/MLF) 361 2593O-AVR-02/12 31. Packaging Information 31.1 44A PIN 1 IDENTIFIER PIN 1 e B E1 E D1 D C 0~7 A1 A2 A L COMMON DIMENSIONS (Unit of Measure = mm) Notes: 1. This package conforms to JEDEC reference MS-026, Variation ACB. 2. Dimensions D1 and E1 do not include mold protrusion. Allowable protrusion is 0.25mm per side. Dimensions D1 and E1 are maximum plastic body size dimensions including mold mismatch. 3. Lead coplanarity is 0.10mm maximum. SYMBOL MIN NOM MAX A - - 1.20 A1 0.05 - 0.15 A2 0.95 1.00 1.05 D 11.75 12.00 12.25 D1 9.90 10.00 10.10 E 11.75 12.00 12.25 E1 9.90 10.00 10.10 B 0.30 - 0.45 C 0.09 - 0.20 L 0.45 - 0.75 e NOTE Note 2 Note 2 0.80 TYP 2010-10-20 R 362 2325 Orchard Parkway San Jose, CA 95131 TITLE 44A, 44-lead, 10 x 10mm body size, 1.0mm body thickness, 0.8 mm lead pitch, thin profile plastic quad flat package (TQFP) DRAWING NO. REV. 44A C ATmega644 2593O-AVR-02/12 ATmega644 31.2 40P6 D PIN 1 E1 A SEATING PLANE A1 L B B1 e E 0 ~ 15 C COMMON DIMENSIONS (Unit of Measure = mm) REF SYMBOL eB Notes: 1. This package conforms to JEDEC reference MS-011, Variation AC. 2. Dimensions D and E1 do not include mold Flash or Protrusion. Mold Flash or Protrusion shall not exceed 0.25mm (0.010"). MIN NOM MAX A - - 4.826 A1 0.381 - - D 52.070 - 52.578 E 15.240 - 15.875 E1 13.462 - 13.970 B 0.356 - 0.559 B1 1.041 - 1.651 L 3.048 - 3.556 C 0.203 - 0.381 eB 15.494 - 17.526 e NOTE Note 2 Note 2 2.540 TYP 09/28/01 R 2325 Orchard Parkway San Jose, CA 95131 TITLE 40P6, 40-lead (0.600"/15.24mm Wide) Plastic Dual Inline Package (PDIP) DRAWING NO. 40P6 REV. B 363 2593O-AVR-02/12 31.3 44M1 D Marked Pin# 1 ID E SEATING PLANE A1 TOP VIEW A3 A K L Pin #1 Corner D2 1 2 3 Option A SIDE VIEW Pin #1 Triangle E2 Option B K Option C b e Pin #1 Chamfer (C 0.30) Pin #1 Notch (0.20 R) BOTTOM VIEW COMMON DIMENSIONS (Unit of Measure = mm) SYMBOL MIN NOM MAX A 0.80 0.90 1.00 A1 - 0.02 0.05 A3 0.20 REF b 0.18 0.23 0.30 D 6.90 7.00 7.10 D2 5.00 5.20 5.40 E 6.90 7.00 7.10 E2 5.00 5.20 5.40 e Note: JEDEC Standard MO-220, Fig. 1 (SAW Singulation) VKKD-3. NOTE 0.50 BSC L 0.59 0.64 0.69 K 0.20 0.26 0.41 9/26/08 Package Drawing Contact: packagedrawings@atmel.com 364 TITLE 44M1, 44-pad, 7 x 7 x 1.0mm body, lead pitch 0.50mm, 5.20mm exposed pad, thermally enhanced plastic very thin quad flat no lead package (VQFN) GPC ZWS DRAWING NO. REV. 44M1 H ATmega644 2593O-AVR-02/12 ATmega644 32. Errata 32.1 Rev. C * Inaccurate ADC conversion in differential mode with 200x gain. 1. Inaccurate ADC conversion in differential mode with 200x gain With AVCC < 3.6V, random conversions will be inaccurate. Typical absolute accuracymay reach 64 LSB. Problem Fix/Workaround None 32.2 Rev. B Not sampled 32.3 Rev. A * EEPROM read from application code does not work in Lock Bit Mode 3. 1. 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/Work around Do not set Lock Bit Protection Mode 3 when the application code needs to read from EEPROM. 365 2593O-AVR-02/12 33. Datasheet Revision History Please note that the referring page numbers in this section are referred to this document. The referring revision in this section are referring to the document revision. 33.1 Rev. 2593O - 02/12 1. 2. 33.2 Rev. 2593N - 07/10 1. 2. 3. 4. 5. 33.3 Updated "Features" on page 1. Updated description in "Stack Pointer" on page 13. Updated "Power-on Reset" on page 46. Updated "Brown-out Detection" on page 47. Updated "Internal Voltage Reference" on page 48. Updated code example in "MCUCR - MCU Control Register" on page 58. Added "System and Reset Characteristics" on page 320. All Register Descriptions moved to the end of their respective chapters. Rev. 2593L - 02/07 1. 2. 3. 4. 366 Updated Table 26-4 on page 320, BODLEVEL Fuse Coding. Corrected use of comma i formula for Rp in Table 26-5, "2-wire Serial Bus Requirements," on page 321 Corrected use of comma in example under Table 27-2, "Additional Current Consumption (percentage) in Active and Idle mode," on page 332 Note 6 and Note 7 in Table 26-5, "2-wire Serial Bus Requirements," on page 321 have been removed Updated document according to Atmel standard use of technical terminology Rev. 2593M - 08/07 1. 2. 3. 4. 5. 6. 7. 8. 33.4 Datasheet changes status from preliminary to complete. Updated the page layouts that include Atmel blue logo and new addresses on the last page. Updated bit description on page 153 Updated typos in "External Interrupts" Section 11.1.6 on page 63 UpdatedTable 24-8 on page 280 Updated Table 24-7 on page 280. ATmega644 2593O-AVR-02/12 ATmega644 33.5 Rev. 2593K - 01/07 1 2. 3. 4. 5. 33.6 Rev. 2593J - 09/06 1. 2. 3. 4. 5. 33.7 Updated note in "Pin Configurations" on page 2. Updated Table 7-2 on page 29, Table 12-11 on page 80 and Table 24-7 on page 280. Updated "Timer/Counter Prescaler" on page 145. Rev. 2593H - 07/06 1. 2. 3. 4. 33.9 Updated "Calibrated Internal RC Oscillator" on page 33. Updated "Fast PWM Mode" on page 117. Updated "Device Identification Register" on page 260. Updated "Signature Bytes" on page 287. Updated Table 13-3 on page 97,Table 13-6 on page 98, Table 14-3 on page 126, Table 14-4 on page 126, Table 14-5 on page 127, Table 15-3 on page 146, Table 15-6 on page 147 and Table 15-8 on page 148. Rev. 2593I - 08/06 1. 2. 3. 33.8 Removed the "Not recommended in new designs" notice on page 1. Updated Figure 2-1 on page 3. Updated "PCIFR - Pin Change Interrupt Flag Register" on page 62. Updated Table 21-4 on page 248. Added note to "DC Characteristics" on page 316. Updated "Fast PWM Mode" on page 117. Updated Figure 14-7 on page 118. Updated Table 24-7 on page 280. Updated "Packaging Information" on page 362. Rev. 2593G - 06/06 1. 2. 3. Updated "Calibrated Internal RC Oscillator" on page 33. Updated "OSCCAL - Oscillator Calibration Register" on page 37. Updated Table 26-1 on page 319. 33.10 Rev. 2593F - 04/06 1. 2. 3. Updated typos. Updated "ADC Noise Reduction Mode" on page 40. Updated "Power-down Mode" on page 40. 367 2593O-AVR-02/12 33.11 Rev. 2593E - 04/06 1. Updated "Calibrated Internal RC Oscillator" on page 33. 33.12 Rev. 2593D - 04/06 1. 2. Updated "Bit 6 - ACBG: Analog Comparator Bandgap Select" on page 231. Updated "Prescaling and Conversion Timing" on page 236. 33.13 Rev. 2593C - 03/06 1. 2. 3. 4. 5. 6. Added "Not recommended in new designs". Removed RAMPZ- Extended Z-pointer Register for ELPM/SPM from datasheet. Updated Table 10-1 on page 55. Updated code example in "Interrupt Vectors in ATmega644" on page 55. Updated "Setting the Boot Loader Lock Bits by SPM" on page 276. Updated "Register Summary" on page 354. 33.14 Rev. 2593B - 03/06 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Removed the occurancy of ATmega164 and ATmega324. Updated Adresses in Registers. Updated "Architectural Overview" on page 9. Updated SRAM sizes in "SRAM Data Memory" on page 18. Updated "I/O Memory" on page 20. Updated "PRR - Power Reduction Register" on page 44. Updated Register bit Discription in "Register Description" on page 146. Updated Note in "Overview of the TWI Module" on page 206. Updated Feauters in "Analog-to-digital Converter" on page 233. Changed name from "SFIOR" to "ADCSRB" in "Starting a Conversion" on page 235, in "Bit 5 - ADATE: ADC Auto Trigger Enable" on page 250 and "Bit 7, 5:3 - Res: Reserved Bits" on page 251. Updated "Signature Bytes" on page 287. Updated "DC Characteristics" on page 316. Updated "Typical Characteristics" on page 326. Updated Example in "Supply Current of IO modules" on page 331. Updated "Register Summary" on page 354. Updated Figure 6-2 on page 18 and Figure 21-1 on page 234. Updated "Errata" on page 365. Updated Table 9-1 on page 47, Table 9-4 on page 51,Table 10-1 on page 55,Table 23-1 on page 260, Table 25-7 on page 287, Table 25-15 on page 299,Table 26-6 on page 322, Table 27-1 on page 331, Table 27-2 on page 332. 11. 12. 13. 14. 15. 16. 17. 18. 33.15 Rev. 2593A-06/05 1. 368 Initial revision. ATmega644 2593O-AVR-02/12 ATmega644 Table of Contents Features ..................................................................................................... 1 1 Pin Configurations ................................................................................... 2 1.1Disclaimer ..................................................................................................................3 2 Overview ................................................................................................... 3 2.1Block Diagram ...........................................................................................................3 2.2Pin Descriptions ........................................................................................................4 3 Resources ................................................................................................. 7 4 About Code Examples ............................................................................. 8 5 AVR CPU Core .......................................................................................... 9 5.1Introduction ................................................................................................................9 5.2Architectural Overview ..............................................................................................9 5.3ALU - Arithmetic Logic Unit ....................................................................................10 5.4Status Register ........................................................................................................11 5.5General Purpose Register File ................................................................................12 5.6Stack Pointer ...........................................................................................................13 5.7Instruction Execution Timing ...................................................................................14 5.8Reset and Interrupt Handling ..................................................................................14 6 AVR Memories ........................................................................................ 17 6.1In-System Reprogrammable Flash Program Memory .............................................17 6.2SRAM Data Memory ...............................................................................................18 6.3EEPROM Data Memory ..........................................................................................19 6.4I/O Memory ..............................................................................................................20 6.5Register Description ................................................................................................21 7 System Clock and Clock Options ......................................................... 27 7.1Clock Systems and their Distribution .......................................................................27 7.2Clock Sources .........................................................................................................28 7.3Low Power Crystal Oscillator ...................................................................................30 7.4Full Swing Crystal Oscillator ....................................................................................31 7.5Low Frequency Crystal Oscillator ............................................................................32 7.6Calibrated Internal RC Oscillator .............................................................................33 7.7128 kHz Internal Oscillator ......................................................................................34 7.8External Clock .........................................................................................................35 i 2593O-AVR-02/12 7.9Clock Output Buffer .................................................................................................36 7.10Timer/Counter Oscillator .......................................................................................36 7.11System Clock Prescaler ........................................................................................36 7.12Register Description ..............................................................................................37 8 Power Management and Sleep Modes ................................................. 39 8.1Overview .................................................................................................................39 8.2Sleep Modes ...........................................................................................................39 8.3Idle Mode .................................................................................................................40 8.4ADC Noise Reduction Mode ...................................................................................40 8.5Power-down Mode ..................................................................................................40 8.6Power-save Mode ...................................................................................................41 8.7Standby Mode .........................................................................................................41 8.8Extended Standby Mode .........................................................................................41 8.9Power Reduction Register .......................................................................................41 8.10Minimizing Power Consumption ............................................................................41 8.11Register Description ..............................................................................................43 9 System Control and Reset .................................................................... 45 9.1Resetting the AVR ...................................................................................................45 9.2Reset Sources .........................................................................................................45 9.3Internal Voltage Reference ......................................................................................48 9.4Watchdog Timer ......................................................................................................49 9.5Register Description ................................................................................................52 10 Interrupts ................................................................................................ 55 10.1Interrupt Vectors in ATmega644 ...........................................................................55 10.2Register Description ..............................................................................................58 11 External Interrupts ................................................................................. 60 11.1Register Description ..............................................................................................60 12 I/O-Ports .................................................................................................. 65 12.1Introduction ............................................................................................................65 12.2Ports as General Digital I/O ...................................................................................66 12.3Alternate Port Functions ........................................................................................71 12.4Register Description ..............................................................................................84 13 8-bit Timer/Counter0 with PWM ............................................................ 86 13.1Feature ..................................................................................................................86 ii ATmega644 2593O-AVR-02/12 ATmega644 13.2Overview ...............................................................................................................86 13.3Timer/Counter Clock Sources ...............................................................................87 13.4Counter Unit ..........................................................................................................87 13.5Output Compare Unit ............................................................................................88 13.6Compare Match Output Unit ..................................................................................90 13.7Modes of Operation ...............................................................................................91 13.8Timer/Counter Timing Diagrams ...........................................................................95 13.9Register Description ..............................................................................................97 14 16-bit Timer/Counter1 with PWM ........................................................ 104 14.1Features ..............................................................................................................104 14.2Overview .............................................................................................................104 14.3Accessing 16-bit Registers ..................................................................................106 14.4Timer/Counter Clock Sources .............................................................................109 14.5Counter Unit ........................................................................................................110 14.6Input Capture Unit ...............................................................................................111 14.7Output Compare Units .........................................................................................113 14.8Compare Match Output Unit ................................................................................115 14.9Modes of Operation .............................................................................................116 14.10Timer/Counter Timing Diagrams .......................................................................123 14.11Register Description ..........................................................................................125 15 8-bit Timer/Counter2 with PWM and Asynchronous Operation ...... 132 15.1Features ..............................................................................................................132 15.2Overview .............................................................................................................132 15.3Timer/Counter Clock Sources .............................................................................133 15.4Counter Unit ........................................................................................................133 15.5Output Compare Unit ..........................................................................................134 15.6Compare Match Output Unit ................................................................................136 15.7Modes of Operation .............................................................................................137 15.8Timer/Counter Timing Diagrams .........................................................................141 15.9Asynchronous Operation of Timer/Counter2 .......................................................143 15.10Timer/Counter Prescaler ...................................................................................145 15.11Register Description ..........................................................................................146 16 SPI - Serial Peripheral Interface ......................................................... 154 16.1Features ..............................................................................................................154 16.2Overview .............................................................................................................154 iii 2593O-AVR-02/12 16.3SS Pin Functionality ............................................................................................159 16.4Data Modes .........................................................................................................159 16.5Register Description ............................................................................................161 17 USART ................................................................................................... 164 17.1Features ..............................................................................................................164 17.2Overview .............................................................................................................164 17.3Clock Generation .................................................................................................165 17.4Frame Formats ....................................................................................................168 17.5USART Initialization ............................................................................................170 17.6Data Transmission - The USART Transmitter ....................................................171 17.7Data Reception - The USART Receiver .............................................................173 17.8Asynchronous Data Reception ............................................................................177 17.9Multi-processor Communication Mode ................................................................180 17.10Register Description ..........................................................................................182 17.11Examples of Baud Rate Setting ........................................................................187 18 USART in SPI Mode ............................................................................. 191 18.1Features ..............................................................................................................191 18.2Overview .............................................................................................................191 18.3Clock Generation .................................................................................................191 18.4SPI Data Modes and Timing ...............................................................................192 18.5Frame Formats ....................................................................................................193 18.6Data Transfer ......................................................................................................194 18.7Register Description ............................................................................................196 18.8AVR USART MSPIM vs. AVR SPI ......................................................................199 19 2-wire Serial Interface .......................................................................... 200 19.1Features ..............................................................................................................200 19.22-wire Serial Interface Bus Definition ..................................................................200 19.3Data Transfer and Frame Format ........................................................................201 19.4Multi-master Bus Systems, Arbitration and Synchronization ...............................204 19.5Overview of the TWI Module ...............................................................................206 19.6Using the TWI ......................................................................................................208 19.7Transmission Modes ...........................................................................................211 19.8Multi-master Systems and Arbitration ..................................................................224 19.9Register Description ............................................................................................225 20 Analog Comparator ............................................................................. 230 iv ATmega644 2593O-AVR-02/12 ATmega644 20.1Overview .............................................................................................................230 20.2Analog Comparator Multiplexed Input .................................................................230 20.3Register Description ............................................................................................231 21 Analog-to-digital Converter ................................................................ 233 21.1Features ..............................................................................................................233 21.2Overview .............................................................................................................233 21.3Operation .............................................................................................................234 21.4Starting a Conversion ..........................................................................................235 21.5Prescaling and Conversion Timing ......................................................................236 21.6Changing Channel or Reference Selection .........................................................239 21.7ADC Noise Canceler ...........................................................................................241 21.8ADC Conversion Result ......................................................................................246 21.9Register Description ............................................................................................248 22 JTAG Interface and On-chip Debug System ..................................... 253 22.1Overview .............................................................................................................253 22.2TAP - Test Access Port ......................................................................................253 22.3TAP Controller .....................................................................................................255 22.4Using the Boundary-scan Chain ..........................................................................256 22.5Using the On-chip Debug System .......................................................................256 22.6On-chip Debug Specific JTAG Instructions .........................................................257 22.7Using the JTAG Programming Capabilities .........................................................257 22.8Bibliography .........................................................................................................258 22.9Register Description ............................................................................................258 23 IEEE 1149.1 (JTAG) Boundary-scan ................................................... 259 23.1Features ..............................................................................................................259 23.2Overview .............................................................................................................259 23.3Data Registers .....................................................................................................259 23.4Boundary-scan Specific JTAG Instructions .........................................................261 23.5Boundary-scan Chain ..........................................................................................262 23.6ATmega644 Boundary-scan Order .....................................................................265 23.7Boundary-scan Description Language Files ........................................................267 23.8Register Description ............................................................................................267 24 Boot Loader Support - Read-While-Write Self-Programming ......... 269 24.1Features ..............................................................................................................269 24.2Overview .............................................................................................................269 v 2593O-AVR-02/12 24.3Application and Boot Loader Flash Sections .......................................................269 24.4Read-While-Write and No Read-While-Write Flash Sections ..............................270 24.5Boot Loader Lock Bits .........................................................................................272 24.6Entering the Boot Loader Program ......................................................................273 24.7Addressing the Flash During Self-Programming .................................................274 24.8Self-Programming the Flash ................................................................................274 24.9Register Description ............................................................................................281 25 Memory Programming ......................................................................... 284 25.1Program And Data Memory Lock Bits .................................................................284 25.2Fuse Bits .............................................................................................................285 25.3Signature Bytes ...................................................................................................287 25.4Calibration Byte ...................................................................................................287 25.5Page Size ............................................................................................................287 25.6Parallel Programming Parameters, Pin Mapping, and Commands .....................287 25.7Parallel Programming ..........................................................................................290 25.8Serial Downloading .............................................................................................299 25.9Serial Programming Instruction set .....................................................................301 25.10Programming via the JTAG Interface ................................................................303 26 Electrical Characteristics .................................................................... 316 26.1Absolute Maximum Ratings* ...............................................................................316 26.2DC Characteristics ..............................................................................................316 26.3Speed Grades .....................................................................................................318 26.4Clock Characteristics ...........................................................................................319 26.5System and Reset Characteristics ......................................................................320 26.62-wire Serial Interface Characteristics .................................................................321 26.7SPI Timing Characteristics ..................................................................................322 26.8ADC Characteristics ............................................................................................324 27 Typical Characteristics ........................................................................ 326 27.1Active Supply Current ..........................................................................................326 27.2Idle Supply Current ..............................................................................................329 27.3Supply Current of IO modules .............................................................................331 27.4Power-down Supply Current ...............................................................................332 27.5Power-save Supply Current ................................................................................333 27.6Standby Supply Current ......................................................................................334 27.7Pin Pull-up ...........................................................................................................338 vi ATmega644 2593O-AVR-02/12 ATmega644 27.8Pin Driver Strength ..............................................................................................341 27.9Pin Threshold and Hysteresis .............................................................................343 27.10BOD Threshold and Analog Comparator Offset ................................................346 27.11Internal Oscillator Speed ...................................................................................348 27.12Current Consumption of Peripheral Units ..........................................................350 28 Register Summary ............................................................................... 354 29 Instruction Set Summary .................................................................... 358 30 Ordering Information ........................................................................... 361 30.1ATmega644 .........................................................................................................361 31 Packaging Information ........................................................................ 362 31.144A ......................................................................................................................362 31.240P6 ....................................................................................................................363 31.344M1 ...................................................................................................................364 32 Errata ..................................................................................................... 365 32.1Rev. C .................................................................................................................365 32.2Rev. B ..................................................................................................................365 32.3Rev. A ..................................................................................................................365 33 Datasheet Revision History ................................................................ 366 33.1Rev. 2593O - 02/12 .............................................................................................366 33.2Rev. 2593N - 07/10 .............................................................................................366 33.3Rev. 2593M - 08/07 .............................................................................................366 33.4Rev. 2593L - 02/07 ..............................................................................................366 33.5Rev. 2593K - 01/07 .............................................................................................367 33.6Rev. 2593J - 09/06 ..............................................................................................367 33.7Rev. 2593I - 08/06 ...............................................................................................367 33.8Rev. 2593H - 07/06 .............................................................................................367 33.9Rev. 2593G - 06/06 .............................................................................................367 33.10Rev. 2593F - 04/06 ............................................................................................367 33.11Rev. 2593E - 04/06 ...........................................................................................368 33.12Rev. 2593D - 04/06 ...........................................................................................368 33.13Rev. 2593C - 03/06 ...........................................................................................368 33.14Rev. 2593B - 03/06 ...........................................................................................368 33.15Rev. 2593A-06/05 .............................................................................................368 Table of Contents....................................................................................... i vii 2593O-AVR-02/12 Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: (+1)(408) 441-0311 Fax: (+1)(408) 487-2600 www.atmel.com Atmel Asia Limited Unit 1-5 & 16, 19/F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon HONG KONG Tel: (+852) 2245-6100 Fax: (+852) 2722-1369 Atmel Munich GmbH Business Campus Parkring 4 D-85748 Garching b. Munich GERMANY Tel: (+49) 89-31970-0 Fax: (+49) 89-3194621 Atmel Japan 16F, Shin Osaki Kangyo Bldg. 1-6-4 Osaki Shinagawa-ku Tokyo 104-0032 JAPAN Tel: (+81) 3-6417-0300 Fax: (+81) 3-6417-0370 (c) 2012 Atmel Corporation. All rights reserved. Atmel (R), Atmel logo and combinations thereof, AVR (R) and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 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 sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, 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 INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND 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 herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. 2593O-AVR-02/12