Features * High-performance, Low-power 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 16 MIPS Throughput at 16 MHz - On-chip 2-cycle Multiplier Nonvolatile Program and Data Memories - 16/32/64K Bytes of In-System Self-Programmable Flash Endurance: 10,000 Write/Erase Cycles - Optional Boot Code Section with Independent Lock Bits In-System Programming by On-chip Boot Program True Read-While-Write Operation - 512B/1K/2K Bytes EEPROM Endurance: 100,000 Write/Erase Cycles - 1/2/4K Bytes Internal SRAM - 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(1) - Byte-oriented Two-wire Serial Interface - Two 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 - 44-lead TQFP, and 44-pad QFN/MLF Operating Voltages - 2.7 - 5.5V for ATmega164P/324P/644P Speed Grades - ATmega164P/324P/644P: 0 - 8MHz @ 2.7 - 5.5V, 0 - 16MHz @ 4.5 - 5.5V Power Consumption at 8 MHz, 5V, 25C for ATmega644P - Active mode: 8 mA - Idle mode: 2.4 mA - Power-down Mode: 0.8 A 8-bit Microcontroller with 16/32/64K Bytes In-System Programmable Flash ATmega164P ATmega324P ATmega644P Automotive 7674F-AVR-09/09 1. Pin Configurations Figure 1-1. Pinout ATmega164P/324P/644P 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 (PCINT/RXD1/26/INT0) PD2 (PCINT/TXD1/27/INT1) (PCINT28/XCK1/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. ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 2. Overview The ATmega164P/324P/644P 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 ATmega164P/324P/644P 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 Analog Comparator A/D Converter Watchdog Oscillator USART 0 XTAL1 Oscillator Circuits / Clock Generation EEPROM Internal Bandgap reference SPI XTAL2 8bit T/C 0 CPU JTAG/OCD TWI PORT C (8) TOSC2/PC7 TOSC1/PC6 PC5..0 16bit T/C 1 FLASH SRAM 8bit T/C 2 USART 1 PORT D (8) PD7..0 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. 3 7674F-AVR-09/09 The ATmega164P/324P/644P provides the following features: 16/32/64K bytes of In-System Programmable Flash with Read-While-Write capabilities, 512B/1K/2K bytes EEPROM, 1/2/4K bytes 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 On-chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega164P/324P/644P is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The ATmega164P/324P/644P 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 Comparison Between ATmega164P, ATmega324P and ATmega644P Table 2-1. 4 Differences between ATmega164P and ATmega644P Device Flash EEPROM RAM ATmega164P 16 Kbyte 512 Bytes 1 Kbyte ATmega324P 32 Kbyte 1 Kbyte 2 Kbyte ATmega644P 64 Kbyte 2 Kbyte 4 Kbyte ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 2.2.1 Automotive Quality Grade The ATmega164P/324P/644P have been developed and manufactured according to the most stringent requirements of the international standard ISO-TS-16949. This data sheet contains limit values extracted from the results of extensive characterization (Temperature and Voltage). The quality and reliability of the ATmega164P/324P/644P have been verified during regular product qualification as per AEC-Q100 grade 1 (-40C to +125C). Table 2-2. Temperature Temperature Grade Identification for Automotive Products Temperature Identifier -40 ; +125 2.3 2.3.1 Z Comments Full AutomotiveTemperature Range Pin Descriptions VCC Digital supply voltage. 2.3.2 GND Ground. 2.3.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 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 ATmega164P/324P/644P as listed on page 79. 2.3.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 ATmega164P/324P/644P as listed on page 81. 5 7674F-AVR-09/09 2.3.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 ATmega164P/324P/644P as listed on page 84. 2.3.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 ATmega164P/324P/644P as listed on page 86. 2.3.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 332. Shorter pulses are not guaranteed to generate a reset. 2.3.8 XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. 2.3.9 XTAL2 Output from the inverting Oscillator amplifier. 2.3.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.3.11 AREF This is the analog reference pin for the Analog-to-digital Converter. 6 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 3. Resources A comprehensive set of development tools, application notes and datasheetsare available for download on http://www.atmel.com/avr. 7 7674F-AVR-09/09 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 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 5. AVR CPU Core 5.1 Overview 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. 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 7674F-AVR-09/09 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- 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 ATmega164P/324P/644P has Extended I/O space from 0x60 - 0xFF in SRAM where only the ST/STS/STD and LD/LDS/LDD instructions can be used. 5.2 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 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 5.3 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.3.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. * Bit 1 - Z: Zero Flag 11 7674F-AVR-09/09 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.4 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 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 5.4.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 7 XL 0 R27 (0x1B) 15 Y-register YH 7 YL 0 0 7 0 R28 (0x1C) 15 ZH 7 0 R31 (0x1F) 0 R26 (0x1A) R29 (0x1D) Z-register 0 7 ZL 7 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.5 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 three 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 three 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. 13 7674F-AVR-09/09 5.5.1 SPH and SPL - Stack Pointer High and Stack pointer Low 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 5.6 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 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 on page 14 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 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. 14 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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.7 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 296 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 60. The list also determines the priority levels of the different interrupts. The lower the address the higher is the 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 60 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 296. 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. 15 7674F-AVR-09/09 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< ... ... Timer0 CompareB Timer0 Overflow SPI Transfer Complete USART0 RX Complete USART0,UDR Empty USART0 TX Complete Analog Comparator ADC Conversion Complete EEPROM Ready 2-wire Serial SPM Ready USART1 RX Complete USART1,UDR Empty USART1 TX Complete ; 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 8K bytes 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 62 0x1F002 jmp EXT_INT0 ; IRQ0 Handler 0x1F004 jmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1FO36 jmp SPM_RDY ; SPM Ready Handler ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P When the BOOTRST Fuse is programmed and the Boot section size set to 8K bytes, 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 out SPH,r16 0x1F002 ldi r16,low(RAMEND) 0x1F003 0x1F004 out sei SPL,r16 0x1F005 ; Set Stack Pointer to top of RAM ; Enable interrupts xxx When the BOOTRST Fuse is programmed, the Boot section size set to 8K bytes 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.2.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. 63 7674F-AVR-09/09 10.3 10.3.1 Register Description MCUCR - MCU Control Register Bit 7 6 5 4 3 2 1 0 0x35 (0x55) JTD BODS BODSE 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 296 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 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 296 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 the following Code Example. 64 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Assembly Code Example Move_interrupts: ; Enable change of Interrupt Vectors ldi 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. 183 7674F-AVR-09/09 17.8.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 (i.e., 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.8.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 177 and "Parity Checker" on page 185. 184 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 17.8.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 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.8.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 (i.e., 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.8.7 Flushing the Receive Buffer The receiver buffer FIFO will be flushed when the Receiver is disabled, i.e., 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 311 7674F-AVR-09/09 25.8.2 Serial Programming Algorithm When writing serial data to the ATmega164P/324P/644P, data is clocked on the rising edge of SCK. When reading data from the ATmega164P/324P/644P, data is clocked on the falling edge of SCK. See Figure 25-12 for timing details. To program and verify the ATmega164P/324P/644P 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, i.e., 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 25-16.) 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 stored until the command is re-issued, i.e., 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. 312 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 313 and Figure 25-11 on page 314 describes the Instruction set. Table 25-17. Serial Programming Instruction Set (Hexadecimal values) Instruction Format Instruction/Operation Byte 1 Byte 2 Byte 3 Byte4 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 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 Load Instructions Read Instructions Write Instructions(6) 313 7674F-AVR-09/09 Notes: 1. 2. 3. 4. 5. 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. 6. Instructions accessing program memory use a word address. This address may be random within the page range. 7. 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 314. 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 314 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 25.9.1 Serial Programming Characteristics For characteristics of the Serial Programming module see "SPI Timing Characteristics" on page 333. 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 on page 316. 315 7674F-AVR-09/09 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 16-bit 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. 316 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 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. 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. 317 7674F-AVR-09/09 25.10.7 Data Registers The Data Registers are selected by the JTAG instruction registers described in section "Programming Specific JTAG Instructions" on page 315. The Data Registers relevant for programming operations are: * Reset Register * Programming Enable Register * Programming Command Register * Flash Data Byte Register 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 30) 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 271. 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 on page 320. The state sequence when shifting in the programming commands is illustrated in Figure 25-16 on page 323. 318 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 319 7674F-AVR-09/09 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) 320 Notes (2) (10) (10) Low byte High byte (10) ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 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(9) 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) (7) Notes (10) 321 7674F-AVR-09/09 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: 322 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 297 7. The bit mapping for Fuses High byte is listed in Table 25-4 on page 298 8. The bit mapping for Fuses Low byte is listed in Table 25-5 on page 298 9. The bit mapping for Lock bits byte is listed in Table 25-1 on page 296 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...). ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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. 323 7674F-AVR-09/09 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 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. 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 on page 320. 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. 324 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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. 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 309). 25.10.16 Programming the Flash Before programming the Flash a Chip Erase must be performed, see "Performing Chip Erase" on page 325. 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 309). 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 299) 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 309). 9. Repeat steps 3 to 8 until all data have been programmed. 325 7674F-AVR-09/09 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: 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 299) 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 325. 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 309). 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. 326 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 309). 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 309). 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 309). 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. 327 7674F-AVR-09/09 26. Electrical Characteristics Absolute Maximum Ratings* Operating Temperature................................. -55 C to +125 C 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 *NOTICE: 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 Injection Current at VCC = 0V ................................... 5.0mA(1) Injection Current at VCC = 5V ...................................... 1.0mA Notes: 328 1. Maximum current per port = 30mA ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 26.1 DC Characteristics TA = -40 C to 125 C, VCC = 2.7V to 5.5V (unless otherwise noted) Symbol Parameter Condition Min. VIL Input Low Voltage,Except XTAL1 and Reset pin VCC = 2.7V - 5.5V VIL1 Input Low Voltage, XTAL1 pin VIL2 Max. Units -0.5 0.3VCC(1) V VCC = 2.7V - 5.5V -0.5 0.1VCC(1) V Input Low Voltage, RESET pin VCC = 2.7V - 5.5V -0.5 0.3VCC(1) V VIH Input High Voltage, Except XTAL1 and RESET pins VCC = 2.7V - 5.5V 0.6VCC(2) VCC + 0.5 V VIH1 Input High Voltage, XTAL1 pin VCC = 2.7V - 5.5V 0.7VCC(2) VCC + 0.5 V VIH2 Input High Voltage, RESET pin VCC = 2.7V - 5.5V 0.9VCC(2) VCC + 0.5 V VOL Output Low Voltage(3), IOL = 20 mA, VCC = 5V IOL = 5 mA, VCC = 3V 0.8 0.5 V 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 A IIH Input Leakage Current I/O Pin VCC = 5.5V, pin high (absolute value) 1 A RRST Reset Pull-up Resistor 30 60 k RPU I/O Pin Pull-up Resistor 20 50 k VACIO Analog Comparator Input Offset Voltage VCC = 5V Vin = VCC/2 40 mV IACLK Analog Comparator Input Leakage Current VCC = 5V Vin = VCC/2 50 nA tACID(5) Analog Comparator Propagation Delay VCC = 2.7V VCC = 4.0V Note: Typ. 4.1 2.3 V <10 -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 (20mA at VCC = 5V, 10mA 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 (20mA at VCC = 5V, 10mA 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. 329 7674F-AVR-09/09 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. Values indicated represent typical data from design simulation. 26.1.1 ATmega644P DC Characteristics Table 26-1. Symbol TA = -40 C to 125 C, VCC = 2.7V to 5.5V (unless otherwise noted) Parameter Condition Power Supply Current(1) ICC Power-down mode Min. Typ. Max. Units Active 4 MHz, VCC = 3V 2.7 4.0 mA Active 8 MHz, VCC = 5V 9.5 12 mA Idle 4 MHz, VCC = 3V 0.7 1.2 mA Idle 8 MHz, VCC = 5V) 3.0 4.0 mA WDT enabled, VCC = 3V 10 60 A WDT enabled, VCC = 5V 15 95 A WDT disabled, VCC = 3V 7 54 A WDT disabled, VCC = 5V 10 85 A Notes: 1. All bits set in the "PRR - Power Reduction Register" on page 47. 26.2 Speed Grades Maximum frequency is depending on VCC. as shown in Figure 26-1. Figure 26-1. Maximum Frequency vs. VCC, ATmega164P/324P/644P 16 MHz 8 MHz Safe Operating Area 2.7V 330 4.5V 5.5V ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 26.3 Clock Characteristics Table 26-2. Calibration Accuracy of Internal RC Oscillator Frequency VCC Temperature Calibration Accuracy 8.0 MHz 3V 25 C 2% 2.7V - 5.5V -40 C - 125 C 14% Factory Calibration 26.3.1 External Clock Drive Waveforms Figure 26-2. External Clock Drive Waveforms V IH1 V IL1 26.3.2 External Clock Drive Table 26-3. External Clock Drive(1) VCC=2.7-5.5V VCC=4.5-5.5V Symbol Parameter Min. Max. Min. Max. Units 1/tCLCL Oscillator Frequency 0 8 0 16 MHz tCLCL Clock Period 125 62.5 ns tCHCX High Time 50 25 ns tCLCX Low Time 50 25 ns tCLCH Rise Time 1.6 0.5 s tCHCL Fall Time 1.6 0.5 s tCLCL Change in period from one clock cycle to the next 2 2 % Note: 1. Values indicated represent typical data from design simulation. 331 7674F-AVR-09/09 26.4 System and Reset Characteristics Table 26-4. Symbol tRST (1) VHYST VRAM Reset, Brown-out and Internal Voltage Reference Characteristics Parameter Condition Min Minimum pulse width on RESET Pin Brown-out Detector Hysteresis (3) (1) tBOD RAM Retention Voltage (1) Min Pulse Width on Brown-out Reset VBG Bandgap reference voltage VC C= 2.7V, TA = 25 C tBG(1) Bandgap reference start-up time Bandgap reference current consumption IBG Notes: (1) Typ 1.0 Max Units 2.5 ns 50 mV 50 mV 2 ns 1.1 1.2 V VC C= 2.7V, TA = 25 C 40 70 s VC C= 2.7V, TA = 25 C 10 A 1. Values indicated represent typical data from design simulation. 2. The Power-on Reset will not work unless the supply voltage has been below VPOT (falling) 3. This is the limit to which VDD can be lowered without losing RAM data. Table 26-5. BODLEVEL Fuse Coding(1) BODLEVEL 2:0 Fuses Min VBOT 111 Typ VBOT Max VBOT Units BOD Disabled 110 Reserved 101 2.5 2.7 2.9 100 4.1 4.3 4.5 V 011 010 Reserved 001 000 Note: 332 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. ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 26.5 SPI Timing Characteristics See Figure 26-3 on page 333 and Figure 26-4 on page 334 for details. Table 26-6. SPI Timing Parameters(2) Description Mode 1 SCK period Master See Table 16-5 2 SCK high/low Master 50% duty cycle 3 Rise/Fall time Master TBD 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: Min Typ Max ns TBD 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 2. Values indicated represent typical data from design simulation. Figure 26-3. 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 333 7674F-AVR-09/09 Figure 26-4. 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 17 15 MISO (Data Output) 26.6 MSB ... LSB X 2-wire Serial Interface Characteristics Table 26-7 describes the requirements for devices connected to the 2-wire Serial Bus. The ATmega164P/324P/644P 2-wire Serial Interface meets or exceeds these requirements under the noted conditions. Timing symbols refer to Figure 26-5. Table 26-7. 2-wire Serial Bus Requirements(1) Symbol Parameter VIL VIH Min Max Units Input Low-voltage -0.5 0.3 VCC V Input High-voltage 0.7 VCC VCC + 0.5 V - V Vhys Hysteresis of Schmitt Trigger Inputs VOL Output Low-voltage tr Rise Time for both SDA and SCL tof Output Fall Time from VIHmin to VILmax tSP Spikes Suppressed by Input Filter Ii Input Current each I/O Pin Ci Capacitance for each I/O Pin fSCL SCL Clock Frequency Rp tHD;STA Condition 0.05 VCC 3 mA sink current 334 0.4 V (2)(3) 300 ns 20 + 0.1Cb(2)(3) 250 ns (2) ns 0 0.1VCC < Vi < 0.9VCC 50 -10 10 A - 10 pF fCK(4) > max(16fSCL, 250kHz)(5) 0 400 kHz fSCL 100 kHz V CC - 0,4V ---------------------------3mA 1000ns ------------------Cb fSCL > 100 kHz V CC - 0,4V ---------------------------3mA 300ns ---------------Cb fSCL 100 kHz 4.0 - s fSCL > 100 kHz 0.6 - s fSCL 100 kHz 4.7 - s fSCL > 100 kHz(7) 1.3 - s Value of Pull-up resistor Hold Time (repeated) START Condition (6) tLOW 0 20 + 0.1Cb 10 pF < Cb < 400 pF(3) (2) Low Period of the SCL Clock ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 2-wire Serial Bus Requirements(1) (Continued) Table 26-7. Symbol Parameter 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 Notes: Condition Min Max Units fSCL 100 kHz 4.0 - s fSCL > 100 kHz 0.6 - s fSCL 100 kHz 4.7 - s fSCL > 100 kHz 0.6 - s fSCL 100 kHz 0 3.45 s fSCL > 100 kHz 0 0.9 s fSCL 100 kHz 250 - ns fSCL > 100 kHz 100 - ns fSCL 100 kHz 4.0 - s fSCL > 100 kHz 0.6 - s fSCL 100 kHz 4.7 - s fSCL > 100 kHz 1.3 - s 1. 2. 3. 4. 5. Values indicated represent typical data from design simulation. Required only for fSCL > 100 kHz. Cb = capacitance of one bus line in pF. fCK = CPU clock frequency This requirement applies to all ATmega164P/324P/644P Two-wire Serial Interface operation. Other devices connected to the Two-wire Serial Bus need only obey the general fSCL requirement. 6. The actual low period generated by the ATmega164P/324P/644P Two-wire Serial Interface is (1/fSCL - 2/fCK), thus fCK must be greater than 6 MHz for the low time requirement to be strictly met at fSCL = 100 kHz. 7. The actual low period generated by the ATmega164P/324P/644P Two-wire Serial Interface is (1/fSCL - 2/fCK), thus the low time requirement will not be strictly met for fSCL > 308 kHz when fCK = 8 MHz. Still, ATmega164P/324P/644P devices connected to the bus may communicate at full speed (400 kHz) with other ATmega164P/324P/644P devices, as well as any other device with a proper tLOW acceptance margin. Figure 26-5. 2-wire Serial Bus Timing tof tHIGH tLOW tr tLOW SCL tSU;STA SDA tHD;STA tHD;DAT tSU;DAT tSU;STO tBUF 335 7674F-AVR-09/09 26.7 ADC Characteristics Table 26-8. Symbol ADC Characteristics, Single Ended Channel INL DNL Max(1) Resolution Single Ended Conversion 10 Single Ended Conversion(1) VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2.5 4 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz Noise Reduction Mode 2.5 4 Integral Non-Linearity Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.5 1.5 Differential Non-Linearity Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.3 0.7 Gain Error Single Ended Conversion(1) VREF = 4V, VCC = 4V, ADC clock = 200 kHz -4 -2 4 Offset Error Single Ended Conversion(1) VREF = 4V, VCC = 4V, ADC clock = 200 kHz -4 2 4 Units Bits LSB Conversion Time Free Running Conversion 65 260 s Clock Frequency Single Ended Conversion 50 200 kHz VCC - 0.3 VCC + 0.3 V 1.0 AVCC V GND VREF V V AVCC Analog Supply Voltage VREF Reference Voltage VIN Typ(1) Condition Absolute accuracy (Including INL, DNL, quantization error, gain and offset error) TUE Min(1) Parameter Input Voltage VINT1 Internal Voltage Reference 1.1V 1.0 1.1 1.2 2.56V 2.33 2.56 2.79 VINT2 Internal Voltage Reference RREF Reference Input Resistance 30 k RAIN Analog Input Resistance 100 M Notes: 336 V 1. On ATmega644P, offset gain and TUE will be higher if not using idle mode. ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Table 26-9. Symbol ADC Characteristics, Differential Channels Parameter Resolution TUE INL DNL Absolute Accuracy (Including INL, DNL Quantization Error and Offset Error) Integral Non-linearity Differential Non-linearity Gain Error Offset Error Condition Min(1) Typ(1) Gain = 1x 8 Gain = 10x 8 Gain = 200x 7 Max(1) Units Bits Gain = 1x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) 4.6 7 Gain = 10x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) 4.8 8 Gain = 200x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(2)(3) 1.0 4 Gain = 1x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1) 0.2 1.5 Gain = 10x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1) 0.2 1.5 Gain = 200x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(2) 0.25 1.5 Gain = 1x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1) 0.2 1.0 Gain = 10x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1) 0.2 1.0 Gain = 200x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(2) 0.25 1.0 Gain = 1x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) -12 -9 -4 Gain = 10x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) -12 -9 -4 Gain = 200x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(2)(3) -3 -1 3 Gain = 1x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) -4 0.25 4 Gain = 10x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(1)(3) -4 0.20 4 Gain = 200x, VCC =5 V, VREF = 4V ADC clock = 200 kHz(2)(3) -3 0.20 3 LSB LSB LSB LSB LSB Conversion Time 65 260 s Clock Frequency 50 200 kHz AVCC Analog Supply Voltage VCC 0.3 VCC + 0.3 V VREF Reference Voltage 2.56 AVCC - 0.5 V 0 AVCC V VIN Note: Input Differential Voltage 1. 8-bit resolution 2. 7-bit resolution 3. Vref = Vcm/2 337 7674F-AVR-09/09 27. ATmega644P 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. * 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. Figure 27-1. Active Supply Current vs. Frequency (0.1 - 1.0 MHz) ACTIVE S UP P LY CURRENT vs . LOW FREQUENCY Te mpe ra ture = 125C 1.8 1.6 5.5 V 1.4 5.0 V ICC (mA) 1.2 4.5 V 1 0.8 3.3 V 3.0 V 2.7 V 0.6 0.4 0.2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fre que nc y (MHz ) 338 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-2. Active Supply Current vs. Frequency (1 - 20MHz) ACTIVE SUPPLY CURRENT vs. FREQUENCY Temp = 125c 30 25 ICC (mA) 20 5.5 15 5 4.5 10 3.3 3 5 2.7 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) ACTIVE S UP P LY CURRENT vs . V CC INTERNAL RC OSCILLATOR, 8 MHz 12 125 85 25 -40 10 ICC (mA) 8 C C C C 6 4 2 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 27-4. Active Supply Current vs. Vcc (Internal RC Oscillator 1 MHz) 339 7674F-AVR-09/09 ACTIVE S UP P LY CURRENT vs . V CC INTERNAL RC OSCILLATOR, 1 MHz 3.5 3 125 85 25 -40 ICC (mA) 2.5 2 C C C C 1.5 1 0.5 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 340 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-5. Idle Supply Current vs. Frequency (0.1 - 1.0 MHz) - Temperature = 25C IDLE S UP P LY CURRENT vs . LOW FREQUENCY NO POWER REDUCTION ENABLED - Te mpe ra ture = 25C 0.9 0.8 0.7 ICC (mA) 0.6 5.5 V 5.0 V 4.5 V 0.5 0.4 3.3 V 3.0 V 2.7 V 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fre que nc y (MHz ) Figure 27-6. Idle Supply Current vs. Frequency (0.1 - 1.0 MHz) - Temperature = 125C IDLE S UP P LY CURRENT vs . LOW FREQUENCY Te mpe ra ture = 125C 0.6 0.5 ICC (mA) 0.4 5.5 V 5.0 V 4.5 V 0.3 3.3 V 3.0 V 2.7 V 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fre que nc y (MHz ) 341 7674F-AVR-09/09 Figure 27-7. Idle Supply Current vs. Frequency (1 - 20 MHz) - Temperature = 125C IDLE SUPPLY CURRENT vs. FREQUENCY Temp = 125c 10 9 ICC (mA) 8 7 5.5 6 5 5 4.5 4 3.3 3 3 2.7 2 1 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 27-8. Idle Supply Current vs. Vcc (Internal RC Oscillator 8 MHz) IDLE S UP P LY CURRENT vs . V CC INTERNAL RC OSCILLATOR, 8 MHz 3.5 3 ICC (mA) 2.5 125 85 25 -40 2 C C C C 1.5 1 0.5 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 342 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-9. Idle Supply Current vs. Vcc (Internal RC Oscillator 1 MHz) IDLE S UP P LY CURRENT vs . V CC INTERNAL RC OSCILLATOR, 1 MHz 0.8 0.7 0.6 125 85 25 -40 ICC (mA) 0.5 C C C C 0.4 0.3 0.2 0.1 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 27.1 Power-down Supply Current Figure 27-10. Power-down Supply Current vs. Vcc (Watchdog Timer Disabled) POWER-DOWN SUPPLY CURRENT vs. VCC WATCHDOG TIMER DISABLED 25 20 15 ICC (uA) 125 85 25 10 5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 343 7674F-AVR-09/09 Figure 27-11. Power-down Supply Current vs. Vcc (Watchdog Timer Enabled) POWER-DOWN SUPPLY CURRENT vs. VCC WATCHDOG TIMER ENABLED 30 25 ICC (uA) 20 125 15 85 25 10 5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 27.2 Power-save Supply Current Figure 27-12. Power-save Supply Current vs. Vcc (25C, Watchdog Timer Disabled) P OWER-S AVE S UP P LY CURRENT vs . VC C WATCHDOG TIMER DISABLED 2 25 C 1.8 1.6 ICC (uA) 1.4 1.2 1 0.8 0.6 0.4 0.2 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 344 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 27.3 Pin Pull-up Figure 27-13. I/O Pin Pull-up Resistor Current vs. Input Voltage (Vcc = 5V) I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE Vcc = 5.0v 160 140 120 IOP (uA) 100 125 80 85 60 25 -45 40 20 0 0 1 2 3 4 5 6 V OP (V) Figure 27-14. Reset Pull-up Resistor Current vs. Reset Pin Voltage (Vcc = 5V) RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE Vcc = 5.0v 120 100 80 IRESET (uA) 125 60 85 25 40 -45 20 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 -20 V RESET (V) 345 7674F-AVR-09/09 27.4 Pin Driver Strength Figure 27-15. I/O Pin Output Voltage vs. Source Current (Vcc = 5V) VOH VCC 5V, Load current up to 20 mA 5.1 125 85 5 25 4.9 -45 V OH (V) 4.8 4.7 4.6 4.5 4.4 4.3 0 2 4 6 8 10 12 14 16 18 20 Load current (mA) Figure 27-16. I/O Pin Output Voltage vs. Source Current (Vcc = 3.0V) VOH VCC 3V, Load current up to 20 mA 3.1 2.9 2.7 125 V OH (V) 2.5 85 2.3 25 2.1 -45 1.9 1.7 1.5 0 2 4 6 8 10 12 14 16 18 20 Load current (mA) 346 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-17. I/O Pin Output Voltage vs. Sink Current (Vcc = 5V) VOL VCC 5V, Load current up to 20 mA 0.7 0.6 0.5 V OL (V) 125 0.4 85 25 0.3 -45 0.2 0.1 0 0 2 4 6 8 10 12 14 16 18 20 Load current (mA) Figure 27-18. I/O Pin Output Voltage vs. Sink Current (Vcc = 3.0V) VOL VCC 3V, Load current up to 20 mA 1.2 1 V OL (V) 0.8 125 85 0.6 25 -45 0.4 0.2 0 0 2 4 6 8 10 12 14 16 18 20 Load current (mA) 347 7674F-AVR-09/09 27.5 Threshold and Hysteresis Figure 27-19. I/O Input Threshold Voltage vs. Vcc (VIH, I/O Pin Read as "1") I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC VIH, IO PIN READ AS '1' 3.5 3 Threshold (V) 2.5 2 125 1.5 85 25 1 -45 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 V CC (V) Figure 27-20. I/O Input Threshold Voltage vs. Vcc (VIL, I/O Pin Read as "0") I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC VIL, IO PIN READ AS '0' 3.5 3 Threshold (V) 2.5 2 125 1.5 85 25 1 -45 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 V CC (V) 348 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 27.6 BOD Thresholds and Analog Comparator Offset Figure 27-21. BOD Thresholds vs. Temperature (BOD level is 4.3V) BOD THRESHOLDS vs. TEMPERATURE BOD level = 4.3v 4.500 Threshold (V) 4.400 4.300 1 0 4.200 4.100 4.000 -50 -30 -10 10 30 50 70 90 110 130 150 Temperature (C) Figure 27-22. BOD Thresholds vs. Temperature (BOD level is 2.7V) BOD THRESHOLDS vs. TEMPERATURE BOD level = 2.7v 3.000 Threshold (V) 2.900 2.800 1 0 2.700 2.600 2.500 -50 -30 -10 10 30 50 70 90 110 130 150 Temperature (C) 349 7674F-AVR-09/09 Figure 27-23. Bandgap Voltage vs. Temperature BANDGAP VOLTAGE vs. TEMPERATURE 1.2 1.18 Bandgap Voltage (V) 1.16 1.14 1.12 1.1 1.08 5 1.06 3 1.04 1.02 1 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature (V) 27.7 Internal Oscillator Speed Figure 27-24. Watchdog Oscillator Frequency vs. Temperature WATCHDOG OSCILLATOR FREQUENCY vs. TEMPERATURE 130 FRC (kHz) 125 6 120 5.5 5 115 4.5 3.3 110 3 2.7 105 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature 350 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-25. Calibrated 8 MHz RC Oscillator Frequency vs. Temperature CALIBRATED 8 MHz RC OSCILLATOR FREQUENCY vs. TEMPERATURE 8.3 8.2 5.5 FRC (MHz) 8.1 5 4.5 8 3.3 3 7.9 2.7 7.8 7.7 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 Temperature Figure 27-26. Calibrated 8 MHz RC Oscillator Frequency vs. OSCCAL Value - Vcc = 5V CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. OSCCAL VALUE 16 14 FRC (MHz) 12 125 10 85 8 25 6 -45 4 2 0 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 OSCCAL (X1) 351 7674F-AVR-09/09 27.8 Current Consumption of Peripheral Units Figure 27-27. Brownout Detector Current vs. Operating Voltage BROWNOUT DETECTOR CURRENT vs . VC C 30 125 85 25 -40 25 ICC (uA) 20 C C C C 15 10 5 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 27-28. ADC Current vs. Operating Voltage (ADC at 1 MHz) ADC CURRENT vs . VCC AREF = AVCC 350 300 125 C 85 C 25 C ICC (uA) 250 -40 C 200 150 100 50 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 352 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-29. AREF External Reference Current vs. Operating Voltage AREF CURRENT vs . V C C WHEN US ED AS ADC REFERENCE 250 200 ICC (uA) 125 C -40 C 150 100 50 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) Figure 27-30. Analog Comparator Current vs. Operating Voltage ANALOG COMP ARATOR CURRENT vs . VC C 90 -40 25 85 125 80 70 C C C C ICC (uA) 60 50 40 30 20 10 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 353 7674F-AVR-09/09 Figure 27-31. Programming Current vs. Operating Voltage EEP ROM WRITE CURRENT vs . Vcc Ext Clk 20 18 16 ICC (mA) 14 12 -40 C 10 25 C 8 85 C 125 C 6 4 2 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 27.9 Current Consumption in Reset and Reset Pulse Width Figure 27-32. Reset Supply Current vs. Operating Voltage (0.1 - 1.0 MHz) (Excluding Current Through the Reset Pull-up), Temperature = 25C RES ET S UP P LY CURRENT vs . VC C EXCLUDING CURRENT THROUGH THE RESET PULLUP - Te mpe ra ture = 25C 0.18 5.5 V 0.16 5.0 V 0.14 4.5 V ICC (mA) 0.12 0.1 3.3 V 3.0 V 2.7 V 0.08 0.06 0.04 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fre que nc y (MHz ) 354 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Figure 27-33. Reset Supply Current vs. Operating Voltage (1 - 20 MHz) (Excluding Current Through the Reset Pull-up), Temperature = 25C RES ET S UP P LY CURRENT vs . VC C EXCLUDING CURRENT THROUGH THE RESET PULLUP - Te mpe ra ture = 25C 4 3.5 5.5 V 3 5.0 V ICC (mA) 2.5 4.5 V 2 3.3 V 3.0 V 2.7 V 1.5 1 0.5 0 0 2 4 6 8 10 12 14 16 18 20 Fre que nc y (MHz ) Figure 27-34. Minimum Reset Pulse Width vs. Operating Voltage MINIMUM RES ET P ULS E WIDTH vs . V C C 900 800 Puls ewidth (ns ) 700 600 500 400 125 C 300 25 C 200 100 0 2.5 3 3.5 4 4.5 5 5.5 V CC (V) 355 7674F-AVR-09/09 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) UDR1 (0xCD) UBRR1H - - - UBRR1L (0xCB) Reserved - - (0xCA) UCSR1C UMSEL11 UMSEL10 (0xC9) UCSR1B RXCIE1 TXCIE1 (0xC8) UCSR1A RXC1 TXC1 UDRE1 - - - 356 (0xC7) Reserved UDR0 (0xC5) UBRR0H - - USART1 I/O Data Register (0xCC) (0xC6) - - 190 USART1 Baud Rate Register High Byte 194/208 USART1 Baud Rate Register Low Byte 194/208 - - - - - UPM11 UPM10 USBS1 UCSZ11 UCSZ10 UCPOL1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 191/207 FE1 DOR1 UPE1 U2X1 MPCM1 190/206 - - - - - USART0 I/O Data Register - - - (0xC4) UBRR0L (0xC3) Reserved - - (0xC2) UCSR0C UMSEL01 UMSEL00 (0xC1) UCSR0B RXCIE0 TXCIE0 Page - 192/208 190 USART0 Baud Rate Register High Byte 194/208 USART0 Baud Rate Register Low Byte 194/208 - - - - - UPM01 UPM00 USBS0 UCSZ01 UCSZ00 UCPOL0 192/208 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 191/207 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Address (0xC0) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page UCSR0A Name RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 190/206 (0xBF) Reserved - - - - - - - - (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 238 (0xB9) TWSR TWS7 TWS6 TWS5 TWS4 TWS3 - TWPS1 TWPS0 237 2-wire Serial Interface Data Register 238 236 238 (0xB8) TWBR (0xB7) Reserved - - - 2-wire Serial Interface Bit Rate Register - - - - - 235 (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 158 (0xB2) TCNT2 Timer/Counter2 (8 Bit) 157 (0xB1) TCCR2B FOC2A FOC2B - - WGM22 CS22 CS21 CS20 156 (0xB0) TCCR2A COM2A1 COM2A0 COM2B1 COM2B0 - - WGM21 WGM20 153 (0xAF) Reserved - - - - - - - - 158 158 (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 136 (0x89) OCR1AH Timer/Counter1 - Output Compare Register A High Byte 136 (0x88) OCR1AL Timer/Counter1 - Output Compare Register A Low Byte 136 (0x87) ICR1H Timer/Counter1 - Input Capture Register High Byte 137 (0x86) ICR1L Timer/Counter1 - Input Capture Register Low Byte 137 (0x85) TCNT1H Timer/Counter1 - Counter Register High Byte 136 136 (0x84) TCNT1L (0x83) Reserved - - - Timer/Counter1 - Counter Register Low Byte (0x82) TCCR1C FOC1A FOC1B - - - - - - 135 (0x81) TCCR1B ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 134 (0x80) TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 - - WGM11 WGM10 131 (0x7F) DIDR1 - - - - - - AIN1D AIN0D 242 - - 136 - - - 357 7674F-AVR-09/09 Address Name (0x7E) DIDR0 (0x7D) Reserved Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D 262 - - - - - - - - (0x7C) ADMUX REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 258 (0x7B) ADCSRB - ACME - - - ADTS2 ADTS1 ADTS0 241 (0x7A) ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 (0x79) ADCH ADC Data Register High byte 260 261 (0x78) ADCL (0x77) Reserved - - - ADC Data Register Low byte - - - - - 261 (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 159 (0x6F) TIMSK1 - - ICIE1 - - OCIE1B OCIE1A TOIE1 137 (0x6E) TIMSK0 - - - - - OCIE0B OCIE0A TOIE0 108 (0x6D) PCMSK2 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 69 (0x6C) PCMSK1 PCINT15 PCINT14 PCINT13 PCINT12 PCINT11 PCINT10 PCINT9 PCINT8 69 (0x6B) PCMSK0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 70 (0x6A) Reserved - - - - - - - - 69 (0x69) EICRA - - ISC21 ISC20 ISC11 ISC10 ISC01 ISC00 66 (0x68) PCICR - - - - PCIE3 PCIE2 PCIE1 PCIE0 68 (0x67) Reserved - - - - - - - - (0x66) OSCCAL (0x65) Reserved (0x64) PRR (0x63) Reserved (0x62) Reserved (0x61) CLKPR (0x60) WDTCSR Oscillator Calibration Register 39 - - - - - - - - PRTWI PRTIM2 PRTIM0 PRUSART1 PRTIM1 PRSPI PRUSART0 PRADC - - - - - - - - 47 - - - - - - - - CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0 40 WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 58 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 BODS BODSE PUD - - IVSEL IVCE 90/278 0x34 (0x54) MCUSR - - - JTRF WDRF BORF EXTRF PORF 57/278 46 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 294 268 260 0x2F (0x4F) Reserved 0x2E (0x4E) SPDR 0x2D (0x4D) SPSR SPIF0 WCOL0 - - - - - SPI2X0 169 0x2C (0x4C) SPCR SPIE0 SPE0 DORD0 MSTR0 CPOL0 CPHA0 SPR01 SPR00 168 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 107 0x26 (0x46) TCNT0 Timer/Counter0 (8 Bit) 107 0x25 (0x45) TCCR0B FOC0A FOC0B - - WGM02 CS02 CS01 CS00 106 0x24 (0x44) TCCR0A COM0A1 COM0A0 COM0B1 COM0B0 - - WGM01 WGM00 108 0x23 (0x43) GTCCR TSM - - - - - PSR2 PSR54310 160 0x22 (0x42) EEARH - - - - 0x21 (0x41) EEARL 0x20 (0x40) EEDR 0x1F (0x3F) EECR 0x1E (0x3E) GPIOR0 0x1D (0x3D) EIMSK 358 SPI 0 Data Register - - - - 170 28 28 - - - 108 EEPROM Address Register High Byte 23 EEPROM Address Register Low Byte 23 EEPROM Data Register - - EEPM1 - - - EEPM0 EERIE 23 EEMWE EEWE EERE 23 INT2 INT1 INT0 67 General Purpose I/O Register 0 - - 28 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 0x1C (0x3C) Address EIFR Name - - - - - INTF2 INTF1 INTF0 Page 67 0x1B (0x3B) PCIFR - - - - PCIF3 PCIF2 PCIF1 PCIF0 68 0x1A (0x3A) Reserved - - - - - - - - 0x19 (0x39) Reserved - - - - - - - - 0x18 (0x38) Reserved - - - - - - - - 0x17 (0x37) TIFR2 - - - - - OCF2b OCF2A TOV2 160 0x16 (0x36) TIFR1 - - ICF1 - - OCF1B OCF1A TOV1 138 0x15 (0x35) TIFR0 - - - - - OCF0B OCF0A TOV0 108 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 91 0x0A (0x2A) DDRD DDD7 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0 91 0x09 (0x29) PIND PIND7 PIND6 PIND5 PIND4 PIND3 PIND2 PIND1 PIND0 91 0x08 (0x28) PORTC PORTC7 PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0 91 0x07 (0x27) DDRC DDC7 DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0 91 0x06 (0x26) PINC PINC7 PINC6 PINC5 PINC4 PINC3 PINC2 PINC1 PINC0 91 0x05 (0x25) PORTB PORTB7 PORTB6 PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 90 0x04 (0x24) DDRB DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 90 0x03 (0x23) PINB PINB7 PINB6 PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 90 0x02 (0x22) PORTA PORTA7 PORTA6 PORTA5 PORTA4 PORTA3 PORTA2 PORTA1 PORTA0 90 0x01 (0x21) DDRA DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 90 0x00 (0x20) PINA PINA7 PINA6 PINA5 PINA4 PINA3 PINA2 PINA1 PINA0 90 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 ATmega164P/324P/644P 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. 359 7674F-AVR-09/09 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 1 EOR Rd, Rr Exclusive OR Registers Rd Rd Rr Z,N,V 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 Relative Jump PC PC + k + 1 None 2 Indirect Jump to (Z) PC Z None 2 FMULS Rd, Rr Fractional Multiply Signed FMULSU Rd, Rr Fractional Multiply Signed with Unsigned BRANCH INSTRUCTIONS RJMP k IJMP 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 1/2/3 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 360 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 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 C 1 C 1 CLC Clear Carry C 0 C 1 SEN Set Negative Flag N 1 N 1 CLN Clear Negative Flag N 0 N 1 SEZ Set Zero Flag Z 1 Z 1 CLZ Clear Zero Flag Z 0 Z 1 SEI Global Interrupt Enable I 1 I 1 CLI Global Interrupt Disable I 0 I 1 SES Set Signed Test Flag S 1 S 1 CLS Clear Signed Test Flag S 0 S 1 SEV Set Twos Complement Overflow. V 1 V 1 CLV Clear Twos Complement Overflow V 0 V 1 SET Set T in SREG T 1 T 1 CLT Clear T in SREG T 0 T 1 SEH CLH Set Half Carry Flag in SREG Clear Half Carry Flag in SREG H 1 H 0 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 LD Rd, - X Load Indirect and Pre-Dec. X X - 1, Rd (X) None 2 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 2 ST - X, Rr Store Indirect and Pre-Dec. X X - 1, (X) Rr None 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 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 Store Program Memory (Z) R1:R0 None - LPM SPM IN Rd, P In Port Rd P None 1 OUT P, Rr Out Port P Rr None 1 361 7674F-AVR-09/09 Mnemonics Operands Description Operation Flags #Clocks 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 362 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 30. Ordering Information 30.1 ATmega164P Speed (MHz)(3) 8-16 2.7 - 5.5V 8-16 Notes: Power Supply 2.7 - 5.5V Package(1) Operational Range (2) ML -40C to +125C (2) PW -40C to +125C Ordering Code ATmega164P-A15AZ ATmega164P-A15MZ 1. Green and Rohs packaging 2. Tape & Reel with Dry-pack delivery 3. For Speed vs. VCC see "Speed Grades" on page 330 Package Type ML 44-lead, Thin (1.0 mm) Plastic Gull Wing Quad Flat Package (TQFP) PW 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) 30.2 ATmega324P Speed (MHz)(3) Notes: Power Supply Package(1) Ordering Code Operational Range (2) ML -40C to +125C PW -40C to +125C 8-16 2.7 - 5.5V ATmega324P-A15AZ 8-16 2.7 - 5.5V ATmega324P-A15MZ(2) 1. Green and Rohs packaging 2. Tape & Reel with Dry-pack delivery 3. For Speed vs. VCC see "Speed Grades" on page 330 Package Type ML 44-lead, Thin (1.0 mm) Plastic Gull Wing Quad Flat Package (TQFP) PW 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) 30.3 ATmega644P Speed (MHz)(3) 8-16 8-16 Notes: Power Supply 2.7 - 5.5V 2.7 - 5.5V Package(1) Operational Range (2) ML -40C to +125C (2) PW -40C to +125C Ordering Code ATmega644P-A15AZ ATmega644P-A15MZ 1. Green and Rohs packaging 2. Tape & Reel with Dry-pack delivery 3. For Speed vs. VCC see "Speed Grades" on page 330. Package Type ML 44-lead, Thin (1.0 mm) Plastic Gull Wing Quad Flat Package (TQFP) PW 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) 363 7674F-AVR-09/09 31. Packaging Information 31.1 364 ML ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 31.2 PW 365 7674F-AVR-09/09 Notes: 1. Dimensioning and tolerancing conform to ASME Y14.5M. - 1994. 2. Dimensions b applies to metallized terminal and is measured between 0.15 and 0.30 mm from terminal TIP. If the terminal has the optional radius on the other end of the terminal, the dimension b should not be measured in that radius area. 3. Maximum package warpage is 0.05 mm. 4. Maximum allowable burrs is 0.076 mm in all directions. 5. Pin #1 ID on top will be laser marked. 6. This drawing conforms to JEDEC registered outline M0-220. 7. A maximum 0.15 mm pull back (L1) may be present. L minus L1 to be equal to or greater than 0.30 mm. 8. The terminal #1 identifier are optional but must be located within the zone indicated the terminal #1 identifier be either a mold or marked feature. 366 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 32. Errata ATmega164P 32.1 ATmega164P Rev. B No known Errata. 32.2 ATmega164P Rev. A ADC differential mode not recommended above 85C. 33. Errata ATmega324P 33.1 ATmega324P Rev. B No known Errata. 33.2 ATmega324P Rev. A ADC differential mode not recommended above 85C. 34. Errata ATmega644P 34.1 ATmega644P Rev. B No known Errata. 34.2 ATmega644P Rev. A ADC differential mode not recommended above 85. 367 7674F-AVR-09/09 35. 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. 35.1 Rev. 7674F-AVR-09/09 1. PW packaging information updated 35.2 Rev. 7674E-AVR-02/09 1. Note page 1 is removed: Differential Mode is not recommended above 85C 2. Section 2.2.1 "Automotive Quality Grade" on page 5: Temperature range -40 to +85C identifier T and Temperature range -40 to +105C identifier T1 not supported anymore. Temperature range -40 to +125C (AEC-Q100 grade1) identifier Z replace all 3 previous ranges (T, T1, Z) 3. ADC Characterisitics Differential Channels Table 26-9 on page 337 updated to reflect new improvements and removal of temperature limitation. 4. Section 30. "Ordering Information" on page 363: Section 30.1 on page 363, Section 30.2 on page 363 and Section 30.3 on page 363: Ordering code T and T1 have been removed for the 3 parts ATmega164P, ATmega324P, ATmega644P respectively in the 2 package options (Package ML and PW) New Part Number change to reflect the new die revision ATmega164P-A15AZ replaces ATmega164P-15AZ ATmega164P-A15MZ replaces ATmega164P-15MZ ATmega324P-A15AZ replaces ATmega324P-15AZ ATmega324P-A15MZ replaces ATmega324P-15MZ ATmega644P-A15AZ replaces ATmega644P-15AZ ATmega644P-A15MZ replaces ATmega644P-15MZ 35.3 Rev. 7674D-AVR-07/08 1. Added ADC differential mode electrical characteristics for ATMega164. 2. Removed Ramp Z register. 35.4 Rev. 7674C-AVR-05/08 1. VIL reset pin update. Section 26.1 on page 329. 2. Updated EEPROM endurance. See "Features" on page 1. 35.5 Rev. 7674B-AVR-01/08 1. Update to electrical characteristics after product characterization. 35.6 Rev. 7674A-AVR-04/07 1. Initial Automotive revision 2. Insertion of specific for automative quality references 3. DC and Frequency adapted to Automotive temperature range 4. Part numbering and package selection according to Automotive rules 5. Current Consumption adapted based on Industrial electrical characterization. 368 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 36. Table of Contents Features ..................................................................................................... 1 1 Pin Configurations ................................................................................... 2 2 Overview ................................................................................................... 3 2.1 Block Diagram ...................................................................................................3 2.2 Comparison Between ATmega164P, ATmega324P and ATmega644P ...........4 2.3 Pin Descriptions .................................................................................................5 3 Resources ................................................................................................. 7 4 About Code Examples ............................................................................. 8 5 AVR CPU Core .......................................................................................... 9 6 7 5.1 Overview ............................................................................................................9 5.2 ALU - Arithmetic Logic Unit .............................................................................10 5.3 Status Register ................................................................................................11 5.4 General Purpose Register File ........................................................................12 5.5 Stack Pointer ...................................................................................................13 5.6 Instruction Execution Timing ...........................................................................14 5.7 Reset and Interrupt Handling ...........................................................................15 AVR Memories ........................................................................................ 18 6.1 Overview ..........................................................................................................18 6.2 In-System Reprogrammable Flash Program Memory .....................................18 6.3 SRAM Data Memory ........................................................................................19 6.4 EEPROM Data Memory ..................................................................................21 6.5 I/O Memory ......................................................................................................22 6.6 Register Description ........................................................................................23 System Clock and Clock Options ......................................................... 29 7.1 Clock Systems and their Distribution ...............................................................29 7.2 Clock Sources .................................................................................................30 7.3 Low Power Crystal Oscillator ...........................................................................32 7.4 Full Swing Crystal Oscillator ............................................................................33 7.5 Low Frequency Crystal Oscillator ....................................................................34 7.6 Calibrated Internal RC Oscillator .....................................................................36 7.7 128 kHz Internal Oscillator ..............................................................................37 7.8 External Clock .................................................................................................37 369 7674F-AVR-09/09 8 9 7.9 Timer/Counter Oscillator ..................................................................................38 7.10 Clock Output Buffer .........................................................................................38 7.11 System Clock Prescaler ..................................................................................38 7.12 Register Description ........................................................................................39 Power Management and Sleep Modes ................................................. 41 8.1 Overview ..........................................................................................................41 8.2 Sleep Modes ....................................................................................................41 8.3 BOD Disable ....................................................................................................42 8.4 Idle Mode .........................................................................................................42 8.5 ADC Noise Reduction Mode ............................................................................42 8.6 Power-down Mode ...........................................................................................43 8.7 Power-save Mode ............................................................................................43 8.8 Standby Mode .................................................................................................43 8.9 Extended Standby Mode .................................................................................43 8.10 Power Reduction Register ...............................................................................44 8.11 Minimizing Power Consumption ......................................................................44 8.12 Register Description ........................................................................................46 System Control and Reset .................................................................... 49 9.1 Internal Voltage Reference ..............................................................................53 9.2 Watchdog Timer ..............................................................................................54 9.3 Register Description ........................................................................................57 10 Interrupts ................................................................................................ 60 10.1 Overview ..........................................................................................................60 10.2 Interrupt Vectors in ATmega164P/324P/644P ................................................60 10.3 Register Description ........................................................................................64 11 External Interrupts ................................................................................. 66 11.1 Overview ..........................................................................................................66 11.2 Register Description ........................................................................................66 12 I/O-Ports .................................................................................................. 71 370 12.1 Overview ..........................................................................................................71 12.2 Ports as General Digital I/O .............................................................................72 12.3 Alternate Port Functions ..................................................................................77 12.4 Register Description ........................................................................................90 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 13 8-bit Timer/Counter0 with PWM ............................................................ 92 13.1 Features ..........................................................................................................92 13.2 Overview ..........................................................................................................92 13.3 Timer/Counter Clock Sources .........................................................................93 13.4 Counter Unit ....................................................................................................93 13.5 Output Compare Unit .......................................................................................94 13.6 Compare Match Output Unit ............................................................................96 13.7 Modes of Operation .........................................................................................97 13.8 Timer/Counter Timing Diagrams ...................................................................101 13.9 Register Description ......................................................................................103 14 16-bit Timer/Counter1 with PWM ........................................................ 110 14.1 Features ........................................................................................................110 14.2 Overview ........................................................................................................110 14.3 Accessing 16-bit Registers ............................................................................112 14.4 Timer/Counter Clock Sources .......................................................................115 14.5 Counter Unit ..................................................................................................116 14.6 Input Capture Unit .........................................................................................117 14.7 Output Compare Units ...................................................................................119 14.8 Compare Match Output Unit ..........................................................................121 14.9 Modes of Operation .......................................................................................122 14.10 Timer/Counter Timing Diagrams ...................................................................129 14.11 Register Description ......................................................................................131 15 8-bit Timer/Counter2 with PWM and Asynchronous Operation ...... 139 15.1 Features ........................................................................................................139 15.2 Overview ........................................................................................................139 15.3 Timer/Counter Clock Sources .......................................................................140 15.4 Counter Unit ..................................................................................................141 15.5 Output Compare Unit .....................................................................................142 15.6 Compare Match Output Unit ..........................................................................143 15.7 Modes of Operation .......................................................................................145 15.8 Timer/Counter Timing Diagrams ...................................................................149 15.9 Asynchronous Operation of Timer/Counter2 .................................................151 15.10 Timer/Counter Prescaler ...............................................................................153 15.11 Register Description ......................................................................................153 371 7674F-AVR-09/09 16 SPI - Serial Peripheral Interface ......................................................... 161 16.1 Features ........................................................................................................161 16.2 Overview ........................................................................................................161 16.3 SS Pin Functionality ......................................................................................166 16.4 Data Modes ...................................................................................................166 16.5 Register Description ......................................................................................168 17 USART ................................................................................................... 171 17.1 Features ........................................................................................................171 17.2 USART1 and USART0 ..................................................................................171 17.3 Overview ........................................................................................................171 17.4 Clock Generation ...........................................................................................173 17.5 Frame Formats ..............................................................................................176 17.6 USART Initialization .......................................................................................177 17.7 Data Transmission - The USART Transmitter ..............................................178 17.8 Data Reception - The USART Receiver .......................................................181 17.9 Asynchronous Data Reception ......................................................................185 17.10 Multi-processor Communication Mode ..........................................................188 17.11 Register Description ......................................................................................190 17.12 Examples of Baud Rate Setting .....................................................................195 18 USART in SPI Mode ............................................................................. 199 18.1 Features ........................................................................................................199 18.2 Overview ........................................................................................................199 18.3 Clock Generation ...........................................................................................199 18.4 SPI Data Modes and Timing ..........................................................................200 18.5 Frame Formats ..............................................................................................200 18.6 Data Transfer .................................................................................................203 18.7 AVR USART MSPIM vs. AVR SPI ................................................................205 18.8 Register Description ......................................................................................206 19 2-wire Serial Interface .......................................................................... 209 372 19.1 Features ........................................................................................................209 19.2 2-wire Serial Interface Bus Definition ............................................................209 19.3 Data Transfer and Frame Format ..................................................................210 19.4 Multi-master Bus Systems, Arbitration and Synchronization .........................213 19.5 Overview of the TWI Module .........................................................................215 19.6 Using the TWI ................................................................................................217 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 19.7 Transmission Modes .....................................................................................221 19.8 Multi-master Systems and Arbitration ............................................................234 19.9 Register Description ......................................................................................235 20 AC - Analog Comparator ..................................................................... 240 20.1 Overview ........................................................................................................240 20.2 Analog Comparator Multiplexed Input ...........................................................240 20.3 Register Description ......................................................................................241 21 ADC - Analog-to-digital Converter ..................................................... 243 21.1 Features ........................................................................................................243 21.2 Overview ........................................................................................................243 21.3 Operation .......................................................................................................244 21.4 Starting a Conversion ....................................................................................245 21.5 Prescaling and Conversion Timing ................................................................246 21.6 Changing Channel or Reference Selection ...................................................249 21.7 ADC Noise Canceler .....................................................................................251 21.8 ADC Conversion Result .................................................................................256 21.9 Register Description ......................................................................................258 22 JTAG Interface and On-chip Debug System ..................................... 263 22.1 Features ........................................................................................................263 22.2 Overview ........................................................................................................263 22.3 TAP - Test Access Port ................................................................................264 22.4 TAP Controller ...............................................................................................265 22.5 Using the Boundary-scan Chain ....................................................................266 22.6 Using the On-chip Debug System .................................................................266 22.7 On-chip Debug Specific JTAG Instructions ...................................................267 22.8 Using the JTAG Programming Capabilities ...................................................268 22.9 Bibliography ...................................................................................................268 22.10 Register Description ......................................................................................268 23 IEEE 1149.1 (JTAG) Boundary-scan ................................................... 269 23.1 Features ........................................................................................................269 23.2 Overview ........................................................................................................269 23.3 Data Registers ...............................................................................................270 23.4 Boundary-scan Specific JTAG Instructions ...................................................271 23.5 Boundary-scan Chain ....................................................................................272 23.6 ATmega164P/324P/644P Boundary-scan Order ..........................................275 373 7674F-AVR-09/09 23.7 Boundary-scan Description Language Files ..................................................277 23.8 Register Description ......................................................................................278 24 Boot Loader Support - Read-While-Write Self-Programming ......... 279 24.1 Features ........................................................................................................279 24.2 Overview ........................................................................................................279 24.3 Application and Boot Loader Flash Sections .................................................279 24.4 Read-While-Write and No Read-While-Write Flash Sections ........................280 24.5 Boot Loader Lock Bits ...................................................................................282 24.6 Entering the Boot Loader Program ................................................................283 24.7 Addressing the Flash During Self-Programming ...........................................284 24.8 Self-Programming the Flash ..........................................................................285 24.9 Register Description ......................................................................................294 25 Memory Programming ......................................................................... 296 25.1 Program And Data Memory Lock Bits ...........................................................296 25.2 Fuse Bits ........................................................................................................297 25.3 Signature Bytes .............................................................................................299 25.4 Calibration Byte .............................................................................................299 25.5 Page Size ......................................................................................................299 25.6 Parallel Programming Parameters, Pin Mapping, and Commands ...............300 25.7 Parallel Programming ....................................................................................302 25.8 Serial Downloading ........................................................................................311 25.9 Serial Programming Instruction set ...............................................................313 25.10 Programming via the JTAG Interface ............................................................315 26 Electrical Characteristics .................................................................... 328 26.1 DC Characteristics .........................................................................................329 26.2 Speed Grades ...............................................................................................330 26.3 Clock Characteristics .....................................................................................331 26.4 System and Reset Characteristics ................................................................332 26.5 SPI Timing Characteristics ............................................................................333 26.6 2-wire Serial Interface Characteristics ...........................................................334 26.7 ADC Characteristics ......................................................................................336 27 ATmega644P Typical Characteristics ................................................ 338 374 27.1 Power-down Supply Current ..........................................................................343 27.2 Power-save Supply Current ...........................................................................344 27.3 Pin Pull-up .....................................................................................................345 ATmega164P/324P/644P 7674F-AVR-09/09 ATmega164P/324P/644P 27.4 Pin Driver Strength ........................................................................................346 27.5 Threshold and Hysteresis ..............................................................................348 27.6 BOD Thresholds and Analog Comparator Offset ..........................................349 27.7 Internal Oscillator Speed ...............................................................................350 27.8 Current Consumption of Peripheral Units ......................................................352 27.9 Current Consumption in Reset and Reset Pulse Width .................................354 28 Register Summary ............................................................................... 356 29 Instruction Set Summary .................................................................... 360 30 Ordering Information ........................................................................... 363 30.1 ATmega164P .................................................................................................363 30.2 ATmega324P .................................................................................................363 30.3 ATmega644P .................................................................................................363 31 Packaging Information ........................................................................ 364 31.1 ML ..................................................................................................................364 31.2 PW .................................................................................................................365 32 Errata ATmega164P ............................................................................. 367 32.1 ATmega164P Rev. B .....................................................................................367 32.2 ATmega164P Rev. A .....................................................................................367 33 Errata ATmega324P ............................................................................. 367 33.1 ATmega324P Rev. B .....................................................................................367 33.2 ATmega324P Rev. A .....................................................................................367 34 Errata ATmega644P ............................................................................. 367 34.1 ATmega644P Rev. B .....................................................................................367 34.2 ATmega644P Rev. A .....................................................................................367 35 Datasheet Revision History ................................................................ 368 35.1 Rev. 7674E-AVR-02/09 .................................................................................368 35.2 Rev. 7674D-AVR-07/08 .................................................................................368 35.3 Rev. 7674C-AVR-05/08 .................................................................................368 35.4 Rev. 7674B-AVR-01/08 .................................................................................368 35.5 Rev. 7674A-AVR-04/07 .................................................................................368 36 Table of Contents ................................................................................. 369 375 7674F-AVR-09/09 376 ATmega164P/324P/644P 7674F-AVR-09/09 Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia 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 Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en-Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Product Contact Web Site www.atmel.com Literature Requests www.atmel.com/literature 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 ATMEL'S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL'S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel's products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. (c) 2009 Atmel Corporation. All rights reserved. Atmel(R), Atmel logo and combinations thereof, AVR (R), AVR(R) logo, AVR Studio (R) and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Windows (R) and others are registered trademarks or trademarks of Microsoft Corporation in US and/or other countries. Other terms and product names may be trademarks of others. 7674F-AVR-09/09