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 20 MIPS Throughput at 20 MHz - On-chip 2-cycle Multiplier Nonvolatile Program and Data Memories - 128K 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 - 4K Bytes EEPROM Endurance: 100,000 Write/Erase Cycles - 16K 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 - Two 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode - Real Time Counter with Separate Oscillator - Six PWM Channels - 8-channel, 10-bit ADC Differential mode with selectable gain at 1x, 10x or 200x - Byte-oriented Two-wire Serial Interface - 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 - 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF Operating Voltages - 1.8 - 5.5V for ATmega1284P Speed Grades - 0 - 4 MHz @ 1.8 - 5.5V - 0 - 10 MHz @ 2.7 - 5.5V - 0 - 20 MHz @ 4.5 - 5.5V Power Consumption at 1 MHz, 1.8V, 25C - Active: 0.4 mA - Power-down Mode: 0.1 A - Power-save Mode: 0.7 A (Including 32 kHz RTC) 8-bit Microcontroller with 128K Bytes In-System Programmable Flash ATmega1284P Preliminary 8059D-AVR-11/09 ATmega1284P 1. Pin Configurations Figure 1-1. Pinout ATmega1284P PDIP (PCINT8/XCK0/T0) PB0 (PCINT9/CLKO/T1) PB1 (PCINT10/INT2/AIN0) PB2 (PCINT11/OC0A/AIN1) PB3 (PCINT12/OC0B/SS) PB4 (PCINT13/ICP3/MOSI) PB5 (PCINT14/OC3A/MISO) PB6 (PCINT15/OC3B/SCK) PB7 RESET VCC GND XTAL2 XTAL1 (PCINT24/RXD0/T3) PD0 (PCINT25/TXD0) PD1 (PCINT26/RXD1/INT0) PD2 (PCINT27/TXD1/INT1) PD3 (PCINT28/XCK1/OC1B) PD4 (PCINT29/OC1A) PD5 (PCINT30/OC2B/ICP) PD6 PA0 (ADC0/PCINT0) PA1 (ADC1/PCINT1) PA2 (ADC2/PCINT2) PA3 (ADC3/PCINT3) PA4 (ADC4/PCINT4) PA5 (ADC5/PCINT5) PA6 (ADC6/PCINT6) PA7 (ADC7/PCINT7) AREF GND AVCC PC7 (TOSC2/PCINT23) PC6 (TOSC1/PCINT22) PC5 (TDI/PCINT21) PC4 (TDO/PCINT20) PC3 (TMS/PCINT19) PC2 (TCK/PCINT18) PC1 (SDA/PCINT17) PC0 (SCL/PCINT16) PD7 (OC2A/PCINT31) PB4 (SS/OC0B/PCINT12) PB3 (AIN1/OC0A/PCINT11) PB2 (AIN0/INT2/PCINT10) PB1 (T1/CLKO/PCINT9) PB0 (XCK0/T0/PCINT8) GND VCC PA0 (ADC0/PCINT0) PA1 (ADC1/PCINT1) PA2 (ADC2/PCINT2) PA3 (ADC3/PCINT3) TQFP/QFN/MLF (PCINT13/ICP3/MOSI) PB5 (PCINT14/OC3A/MISO) PB6 (PCINT15/OC3B/SCK) PB7 RESET VCC GND XTAL2 XTAL1 (PCINT24/RXD0/T3) PD0 (PCINT25/TXD0) PD1 (PCINT26/RXD1/INT0) PD2 (PCINT27/TXD1/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: The large center pad underneath the QFN/MLF package should be soldered to ground on the board to ensure good mechanical stability. 2 8059D-AVR-11/09 ATmega1284P 2. Overview The ATmega1284P 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 ATmega1284P 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 XTAL2 SPI 8bit T/C 0 CPU 16bit T/C 1 16bit T/C 1 JTAG/OCD 8bit T/C 2 TWI PORT C (8) TOSC2/PC7 TOSC1/PC6 PC5..0 FLASH SRAM 16bit T/C 3 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. The ATmega1284P provides the following features: 128K bytes of In-System Programmable Flash with Read-While-Write capabilities, 4K bytes EEPROM, 16K bytes SRAM, 32 general pur- 3 8059D-AVR-11/09 ATmega1284P pose I/O lines, 32 general purpose working registers, Real Time Counter (RTC), three flexible Timer/Counters with compare modes and PWM, 2 USARTs, a byte oriented 2-wire Serial Interface, a 8-channel, 10-bit ADC with optional differential input stage with programmable gain, programmable Watchdog Timer with Internal Oscillator, an SPI serial port, IEEE std. 1149.1 compliant JTAG test interface, also used for accessing the On-chip Debug system and programming and six software selectable power saving modes. The Idle mode stops the CPU while allowing the SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next interrupt or Hardware Reset. In Power-save mode, the asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the Crystal/Resonator Oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low power consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to run. The device is manufactured using Atmel's high-density nonvolatile memory technology. The Onchip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega1284P is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The ATmega1284P AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits. 2.2 2.2.1 Pin Descriptions VCC Digital supply voltage. 2.2.2 GND Ground. 2.2.3 Port A (PA7:PA0) Port A serves as analog inputs to the Analog-to-digital Converter. Port A also serves as an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink 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 ATmega1284P as listed on page 78. 4 8059D-AVR-11/09 ATmega1284P 2.2.4 Port B (PB7:PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B also serves the functions of various special features of the ATmega1284P as listed on page 80. 2.2.5 Port C (PC7:PC0) Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port C also serves the functions of the JTAG interface, along with special features of the ATmega1284P as listed on page 83. 2.2.6 Port D (PD7:PD0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port D also serves the functions of various special features of the ATmega1284P as listed on page 86. 2.2.7 RESET Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. The minimum pulse length is given in "System and Reset Characteristics" on page 327. Shorter pulses are not guaranteed to generate a reset. 2.2.8 XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. 2.2.9 XTAL2 Output from the inverting Oscillator amplifier. 2.2.10 AVCC AVCC is the supply voltage pin for Port F and the Analog-to-digital Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. 2.2.11 AREF This is the analog reference pin for the Analog-to-digital Converter. 5 8059D-AVR-11/09 ATmega1284P 3. Resources A comprehensive set of development tools, application notes and datasheetsare available for download on http://www.atmel.com/avr. 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". 6 8059D-AVR-11/09 ATmega1284P 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. 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 typ- 7 8059D-AVR-11/09 ATmega1284P ical 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 ATmega1284P 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. 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 8 8059D-AVR-11/09 ATmega1284P 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 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. 9 8059D-AVR-11/09 ATmega1284P 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. 10 8059D-AVR-11/09 ATmega1284P 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. 11 8059D-AVR-11/09 ATmega1284P 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.5.2 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 RAMPZ - Extended Z-pointer Register for ELPM/SPM Bit 7 6 5 4 3 2 1 0 RAMPZ7 RAMPZ6 RAMPZ5 RAMPZ4 RAMPZ3 RAMPZ2 RAMPZ1 RAMPZ0 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 0x3B (0x5B) RAMPZ For ELPM/SPM instructions, the Z-pointer is a concatenation of RAMPZ, ZH, and ZL, as shown in Figure 5-4. Note that LPM is not affected by the RAMPZ setting. Figure 5-4. The Z-pointer used by ELPM and SPM Bit ( Individually) 7 Bit (Z-pointer) 23 0 7 16 15 RAMPZ 0 7 8 7 ZH 0 ZL 0 The actual number of bits is implementation dependent. Unused bits in an implementation will always read as zero. For compatibility with future devices, be sure to write these bits to zero. 5.6 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-5 on page 13 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. 12 8059D-AVR-11/09 ATmega1284P Figure 5-5. 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-6 shows the internal timing concept for the Register File. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. Figure 5-6. 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 291 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 59. 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 59 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 291. 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 13 8059D-AVR-11/09 ATmega1284P interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction - RETI - is executed. There are basically two types of interrupts. The first type is triggered by an event that sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to execute the interrupt handling routine, and hardware clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set, and will then be executed by order of priority. The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not necessarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruction to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence.. Assembly Code Example in r16, SREG cli ; store SREG value ; disable interrupts during timed sequence sbi EECR, EEMPE ; start EEPROM write sbi EECR, EEPE out SREG, r16 ; restore SREG value (I-bit) C Code Example char cSREG; cSREG = SREG; /* store SREG value */ /* disable interrupts during timed sequence */ __disable_interrupt(); EECR |= (1< ... ... Timer1 Capture Timer1 CompareA Timer1 CompareB Timer1 Overflow Timer0 CompareA 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 Timer3 Capture Timer3 CompareA Timer3 CompareB Timer3 Overflow ; 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 0x1F002 jmp EXT_INT0 ; IRQ0 Handler 61 8059D-AVR-11/09 ATmega1284P 0x1F004 jmp EXT_INT1 ; IRQ1 Handler ... ... ... ; 0x1FO36 jmp SPM_RDY ; SPM Ready Handler When the BOOTRST Fuse is programmed and the Boot section size set to 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. 62 8059D-AVR-11/09 ATmega1284P 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 291 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 291 for details on Boot Lock bits. 63 8059D-AVR-11/09 ATmega1284P * 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. 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 6. 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. 182 8059D-AVR-11/09 ATmega1284P 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 176 and "Parity Checker" on page 183. 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 183 8059D-AVR-11/09 ATmega1284P 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 306 8059D-AVR-11/09 ATmega1284P 25.8.2 Serial Programming Algorithm When writing serial data to the ATmega1284P, data is clocked on the rising edge of SCK. When reading data from the ATmega1284P, data is clocked on the falling edge of SCK. See Figure 25-12 for timing details. To program and verify the ATmega1284P 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 2516.) Accessing the serial programming interface before the Flash write operation completes can result in incorrect programming. 5. The EEPROM array is programmed one byte at a time by supplying the address and data together with the appropriate Write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling is not used, the user must wait at least tWD_EEPROM before issuing the next byte. (See Table 25-16.) In a chip erased device, no 0xFFs in the data file(s) need to be programmed. 6. Any memory location can be verified by using the Read instruction which returns the content at the selected address at serial output MISO. When reading the Flash memory, use the instruction Load Extended Address Byte to define the upper address byte, which is not included in the Read Program Memory instruction. The extended address byte is 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. 307 8059D-AVR-11/09 ATmega1284P 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 308 and Figure 25-11 on page 309 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) 308 8059D-AVR-11/09 ATmega1284P 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 309. 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 309 8059D-AVR-11/09 ATmega1284P 25.9.1 Serial Programming Characteristics For characteristics of the Serial Programming module see "SPI Timing Characteristics" on page 328. 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 311. 310 8059D-AVR-11/09 ATmega1284P Figure 25-13. State Machine Sequence for Changing the Instruction Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 1 0 1 Capture-DR Capture-IR 0 0 0 Shift-DR 1 1 Exit1-DR 0 0 Pause-DR 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 25.10.2 1 Exit1-IR 0 1 0 Shift-IR 1 0 1 Update-IR 0 1 0 AVR_RESET (0xC) The AVR specific public JTAG instruction for setting the AVR device in the Reset mode or taking the device out from the Reset mode. The TAP controller is not reset by this instruction. The one bit Reset Register is selected as Data Register. Note that the reset will be active as long as there is a logic "one" in the Reset Chain. The output from this chain is not latched. The active states are: * Shift-DR: The Reset Register is shifted by the TCK input. 25.10.3 PROG_ENABLE (0x4) The AVR specific public JTAG instruction for enabling programming via the JTAG port. The 16bit Programming Enable Register is selected as Data Register. The active states are the following: * Shift-DR: The programming enable signature is shifted into the Data Register. * Update-DR: The programming enable signature is compared to the correct value, and Programming mode is entered if the signature is valid. 311 8059D-AVR-11/09 ATmega1284P 25.10.4 PROG_COMMANDS (0x5) The AVR specific public JTAG instruction for entering programming commands via the JTAG port. The 15-bit Programming Command Register is selected as Data Register. The active states are the following: * Capture-DR: The result of the previous command is loaded into the Data Register. * Shift-DR: The Data Register is shifted by the TCK input, shifting out the result of the previous command and shifting in the new command. * Update-DR: The programming command is applied to the Flash inputs * Run-Test/Idle: One clock cycle is generated, executing the applied command 25.10.5 PROG_PAGELOAD (0x6) The AVR specific public JTAG instruction to directly load the Flash data page via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSBs of the Programming Command Register. The active states are the following: * Shift-DR: The Flash Data Byte Register is shifted by the TCK input. * Update-DR: The content of the Flash Data Byte Register is copied into a temporary register. A write sequence is initiated that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first UpdateDR encountered after entering the PROG_PAGELOAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the program counter increment into the next page. 25.10.6 PROG_PAGEREAD (0x7) The AVR specific public JTAG instruction to directly capture the Flash content via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSBs of the Programming Command Register. The active states are the following: * Capture-DR: The content of the selected Flash byte is captured into the Flash Data Byte Register. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Capture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. * Shift-DR: The Flash Data Byte Register is shifted by the TCK input. 25.10.7 Data Registers The Data Registers are selected by the JTAG instruction registers described in section "Programming Specific JTAG Instructions" on page 310. The Data Registers relevant for programming operations are: * Reset Register * Programming Enable Register * Programming Command Register * Flash Data Byte Register 312 8059D-AVR-11/09 ATmega1284P 25.10.8 Reset Register The Reset Register is a Test Data Register used to reset the part during programming. It is required to reset the part before entering Programming mode. A high value in the Reset Register corresponds to pulling the external reset low. The part is reset as long as there is a high value present in the Reset Register. Depending on the Fuse settings for the clock options, the part will remain reset for a Reset Time-out period (refer to "Clock Sources" on page 28) after releasing the Reset Register. The output from this Data Register is not latched, so the reset will take place immediately, as shown in Figure 23-2 on page 268. 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 315. The state sequence when shifting in the programming commands is illustrated in Figure 25-16 on page 318. 313 8059D-AVR-11/09 ATmega1284P 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 314 8059D-AVR-11/09 ATmega1284P 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 Notes 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) (2) (10) (10) Low byte High byte (10) 315 8059D-AVR-11/09 ATmega1284P Table 25-18. JTAG Programming Instruction (Continued) Set (Continued) a = address high bits, b = address low bits, c = address extended bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don't care Instruction TDI Sequence TDO Sequence 5a. Enter EEPROM Read 0100011_00000011 xxxxxxx_xxxxxxxx 5b. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 5c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 5d. Read Data Byte 0110011_bbbbbbbb 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 6a. Enter Fuse Write 0100011_01000000 xxxxxxx_xxxxxxxx 6b. Load Data Low Byte(6) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6c. Write Fuse Extended Byte 0111011_00000000 0111001_00000000 0111011_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6d. Poll for Fuse Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6f. Write Fuse High Byte 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6g. Poll for Fuse Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 6h. Load Data Low Byte(7) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3) 6i. Write Fuse Low Byte 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 6j. Poll for Fuse Write Complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 7a. Enter Lock Bit Write 0100011_00100000 xxxxxxx_xxxxxxxx 7b. Load Data Byte 0010011_11iiiiii xxxxxxx_xxxxxxxx (4) 7c. Write Lock Bits 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (1) 7d. Poll for Lock Bit Write complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 8a. Enter Fuse/Lock Bit Read 0100011_00000100 xxxxxxx_xxxxxxxx 8b. Read Extended Fuse Byte(6) 0111010_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8c. Read Fuse High Byte(7) 0111110_00000000 0111111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8d. Read Fuse Low Byte(8) 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 6e. Load Data Low Byte (7) (9) Notes (10) 316 8059D-AVR-11/09 ATmega1284P 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: 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 292 7. The bit mapping for Fuses High byte is listed in Table 25-4 on page 293 8. The bit mapping for Fuses Low byte is listed in Table 25-5 on page 293 9. The bit mapping for Lock bits byte is listed in Table 25-1 on page 291 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...). 317 8059D-AVR-11/09 ATmega1284P Figure 25-16. State Machine Sequence for Changing/Reading the Data Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 1 0 1 Capture-DR Capture-IR 0 0 Shift-DR Shift-IR 0 1 Exit1-DR 1 Exit1-IR 0 0 Pause-DR 0 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 1 0 1 1 0 1 Update-IR 0 1 0 25.10.11 Flash Data Byte Register The Flash Data Byte Register provides an efficient way to load the entire Flash page buffer before executing Page Write, or to read out/verify the content of the Flash. A state machine sets up the control signals to the Flash and senses the strobe signals from the Flash, thus only the data words need to be shifted in/out. The Flash Data Byte Register actually consists of the 8-bit scan chain and a 8-bit temporary register. During page load, the Update-DR state copies the content of the scan chain over to the temporary register and initiates a write sequence that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first Update-DR encountered after entering the PROG_PAGELOAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the Program Counter increment into the next page. During Page Read, the content of the selected Flash byte is captured into the Flash Data Byte Register during the Capture-DR state. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Cap- 318 8059D-AVR-11/09 ATmega1284P ture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. Figure 25-17. Flash Data Byte Register STROBES TDI State Machine ADDRESS Flash EEPROM Fuses Lock Bits D A T A TDO The state machine controlling the Flash Data Byte Register is clocked by TCK. During normal operation in which eight bits are shifted for each Flash byte, the clock cycles needed to navigate through the TAP controller automatically feeds the state machine for the Flash Data Byte Register with sufficient number of clock pulses to complete its operation transparently for the user. However, if too few bits are shifted between each Update-DR state during page load, the TAP controller should stay in the Run-Test/Idle state for some TCK cycles to ensure that there are at least 11 TCK cycles between each Update-DR state. 25.10.12 Programming Algorithm All references below of type "1a", "1b", and so on, refer to Table 25-18 on page 315. 25.10.13 Entering Programming Mode 1. Enter JTAG instruction AVR_RESET and shift 1 in the Reset Register. 2. Enter instruction PROG_ENABLE and shift 0b1010_0011_0111_0000 in the Programming Enable Register. 25.10.14 Leaving Programming Mode 1. Enter JTAG instruction PROG_COMMANDS. 2. Disable all programming instructions by using no operation instruction 11a. 3. Enter instruction PROG_ENABLE and shift 0b0000_0000_0000_0000 in the programming Enable Register. 4. Enter JTAG instruction AVR_RESET and shift 0 in the Reset Register. 319 8059D-AVR-11/09 ATmega1284P 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 304). 25.10.16 Programming the Flash Before programming the Flash a Chip Erase must be performed, see "Performing Chip Erase" on page 320. 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 304). 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 294) 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 304). 9. Repeat steps 3 to 8 until all data have been programmed. 25.10.17 Reading the Flash 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash read using programming instruction 3a. 3. Load address using programming instructions 3b, 3c and 3d. 4. Read data using programming instruction 3e. 5. Repeat steps 3 and 4 until all data have been read. A more efficient data transfer can be achieved using the PROG_PAGEREAD instruction: 320 8059D-AVR-11/09 ATmega1284P 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 294) 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 320. 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 304). 9. Repeat steps 3 to 8 until all data have been programmed. Note that the PROG_PAGELOAD instruction can not be used when programming the EEPROM. 25.10.19 Reading the EEPROM 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable EEPROM read using programming instruction 5a. 3. Load address using programming instructions 5b and 5c. 4. Read data using programming instruction 5d. 5. Repeat steps 3 and 4 until all data have been read. Note that the PROG_PAGEREAD instruction can not be used when reading the EEPROM. 25.10.20 Programming the Fuses 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Fuse write using programming instruction 6a. 3. Load data high byte using programming instructions 6b. A bit value of "0" will program the corresponding fuse, a "1" will unprogram the fuse. 4. Write Fuse High byte using programming instruction 6c. 5. Poll for Fuse write complete using programming instruction 6d, or wait for tWLRH (refer to Table 25-14 on page 304). 321 8059D-AVR-11/09 ATmega1284P 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 304). 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 304). 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. 322 8059D-AVR-11/09 ATmega1284P 26. Electrical Characteristics Absolute Maximum Ratings* Operating Temperature.................................. -55C to +125C *NOTICE: Storage Temperature ..................................... -65C to +150C Voltage on any Pin except RESET with respect to Ground ................................-0.5V to VCC+0.5V Voltage on RESET with respect to Ground......-0.5V to +13.0V Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability. Maximum Operating Voltage ............................................ 6.0V DC Current per I/O Pin ............................................... 40.0 mA DC Current VCC and GND Pins................................ 200.0 mA 26.1 DC Characteristics TA = -40C to 85C, VCC = 1.8V to 5.5V (unless otherwise noted) Symbol Parameter Condition Min.(1) Typ. Max.(1) Units (2) VIL Input Low Voltage,Except XTAL1 and Reset pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V -0.5 -0.5 0.2VCC 0.3VCC(2) V VIL1 Input Low Voltage, XTAL1 pin VCC = 1.8V - 5.5V -0.5 0.1VCC(2) V VIL2 Input Low Voltage, RESET pin VCC = 1.8V - 5.5V -0.5 0.1VCC(2) V VIH Input High Voltage, Except XTAL1 and RESET pins VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.7VCC(3) 0.6VCC(3) VCC + 0.5 VCC + 0.5 V VIH1 Input High Voltage, XTAL1 pin VCC = 1.8V - 2.4V VCC = 2.4V - 5.5V 0.8VCC(3) 0.7VCC(3) VCC + 0.5 VCC + 0.5 V VIH2 Input High Voltage, RESET pin VCC = 1.8V - 5.5V 0.9VCC(3) VCC + 0.5 V VOL Output Low Voltage(4), IOL = 10 mA, VCC = 5V IOL = 5 mA, VCC = 3V 0.7 0.5 V VOH Output High Voltage(5), 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 4.2 2.3 V <10 -50 323 8059D-AVR-11/09 ATmega1284P TA = -40C to 85C, VCC = 1.8V to 5.5V (unless otherwise noted) (Continued) Min.(1) Parameter Condition tACID Analog Comparator Propagation Delay VCC = 2.7V VCC = 4.0V 750 500 Active 1 MHz, VCC = 2V TBD TBD mA Active 4 MHz, VCC = 3V TBD TBD mA Active 8 MHz, VCC = 5V TBD TBD mA Idle 1 MHz, VCC = 2V TBD TBD mA Idle 4 MHz, VCC = 3V TBD TBD mA Idle 8 MHz, VCC = 5V) TBD TBD mA 32 kHz TOSC enabled, VCC = 1.8V TBD A 32 kHz TOSC enabled, VCC = 3V TBD A WDT enabled, VCC = 3V TBD TBD A WDT disabled, VCC = 3V TBD TBD A Power Supply Current(6) ICC Power-save mode(7) Power-down mode(7) Notes: Typ. Max.(1) Symbol Units ns 1. All DC Characteristics contained in this datasheet are based on simulation and characterization of other AVR microcontrollers manufactured in the same process technology. These values are preliminary values representing design targets, and will be updated after characterization of actual silicon. 2. "Max" means the highest value where the pin is guaranteed to be read as low 3. "Min" means the lowest value where the pin is guaranteed to be read as high 4. 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. 5. 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. 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. 6. All bits set in the "PRR0 - Power Reduction Register 0" on page 46. 7. Typical values at 25C. Maximum values are characterized values and not test limits in production 324 8059D-AVR-11/09 ATmega1284P 26.2 Speed Grades Maximum frequency is depending on VCC. As shown in Figure 26-1, the Maximum Frequency vs. VCC curve is linear between 1.8V < VCC < 2.7V and between 2.7V < VCC < 4.5V. Figure 26-1. Maximum Frequency vs. VCC, ATmega1284P 20 MHz 10 MHz Safe Operating Area 4 MHz 1.8V 2.7V 4.5V 5.5V 325 8059D-AVR-11/09 ATmega1284P 26.3 Clock Characteristics Table 26-1. Calibration Accuracy of Internal RC Oscillator Frequency VCC Temperature Calibration Accuracy Factory Calibration 8.0 MHz 3V 25C 10% User Calibration 7.3 - 8.1 MHz 1.8V - 5.5V -40C - 85C 1% 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-2. External Clock Drive VCC=1.8-5.5V VCC=2.7-5.5V VCC=4.5-5.5V Symbol Parameter Min. Max. Min. Max. Min. Max. Units 1/tCLCL Oscillator Frequency 0 2 0 8 0 16 MHz tCLCL Clock Period 500 125 62.5 ns tCHCX High Time 200 50 25 ns tCLCX Low Time 200 50 25 ns tCLCH Rise Time 2.0 1.6 0.5 s tCHCL Fall Time 2.0 1.6 0.5 s tCLCL Change in period from one clock cycle to the next 2 2 2 % Note: All DC Characteristics contained in this datasheet are based on simulation and characterization of other AVR microcontrollers manufactured in the same process technology. These values are preliminary values representing design targets, and will be updated after characterization of actual silicon. 326 8059D-AVR-11/09 ATmega1284P 26.4 System and Reset Characteristics Reset, Brown-out and Internal Voltage Reference Characteristics(1) Table 26-3. Symbol Parameter VPOT Min Typ Max Units Power-on Reset Threshold Voltage (rising) 0.7 1.0 1.4 V Power-on Reset Threshold Voltage (falling)(2) 0.6 0.9 1.3 V 0.9VCC V 2.5 ns VRST RESET Pin Threshold Voltage tRST Minimum pulse width on RESET Pin Condition 0.2VCC Brown-out Detector Hysteresis 50 mV tBOD Min Pulse Width on Brown-out Reset 2 ns VBG Bandgap reference voltage VC C= 2.7V, TA = 25C tBG Bandgap reference start-up time IBG Bandgap reference current consumption VHYST Notes: 1.0 1.1 1.2 V VC C= 2.7V, TA = 25C 40 70 s VC C= 2.7V, TA = 25C 10 A 1. Values are guidelines only. Actual values are TBD. 2. The Power-on Reset will not work unless the supply voltage has been below VPOT (falling) BODLEVEL Fuse Coding(1) Table 26-4. BODLEVEL 2:0 Fuses Min VBOT 111 Typ VBOT Max VBOT Units BOD Disabled 110 1.7 1.8 2.0 101 2.5 2.7 2.9 100 4.1 4.3 4.5 V 011 010 Reserved 001 000 Note: 1. VBOT may be below nominal minimum operating voltage for some devices. For devices where this is the case, the device is tested down to VCC = VBOT during the production test. This guarantees that a Brown-Out Reset will occur before VCC drops to a voltage where correct operation of the microcontroller is no longer guaranteed. The test is performed using BODLEVEL = 110 and BODLEVEL = 101 for ATmega1284P. 26.5 External Interrupts Characteristics Table 26-5. Symbol tINT Asynchronous External Interrupt Characteristics Parameter Minimum pulse width for asynchronous external interrupt Condition Min Typ 50 Max Units ns 327 8059D-AVR-11/09 ATmega1284P 26.6 SPI Timing Characteristics See Figure 26-3 on page 328 and Figure 26-4 on page 329 for details. Table 26-6. SPI Timing Parameters 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 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 328 8059D-AVR-11/09 ATmega1284P 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 15 MISO (Data Output) 26.7 17 MSB ... LSB X 2-wire Serial Interface Characteristics Table 26-7 describes the requirements for devices connected to the 2-wire Serial Bus. The ATmega1284P 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 Symbol Parameter VIL Min Max Units Input Low-voltage -0.5 0.3 VCC V VIH Input High-voltage 0.7 VCC VCC + 0.5 V Vhys(1) Hysteresis of Schmitt Trigger Inputs 0.05 VCC(2) - V VOL(1) Output Low-voltage 0 tr(1) Output Fall Time from VIHmin to VILmax tSP(1) Spikes Suppressed by Input Filter Ii Input Current each I/O Pin Ci(1) Capacitance for each I/O Pin Rp tHD;STA tLOW 3 mA sink current 0.4 V 20 + 0.1Cb (2)(3) 300 ns 20 + 0.1Cb (2)(3) 250 ns 0 50(2) ns -10 10 A - 10 pF 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 Rise Time for both SDA and SCL tof(1) fSCL Condition SCL Clock Frequency (3) 10 pF < Cb < 400 pF 0.1VCC < Vi < 0.9VCC fCK(4) (5) > max(16fSCL, 250kHz) Value of Pull-up resistor Hold Time (repeated) START Condition Low Period of the SCL Clock fSCL 100 kHz 0.6 - s (6) 4.7 - s (7) 1.3 - s fSCL > 100 kHz 329 8059D-AVR-11/09 ATmega1284P Table 26-7. 2-wire Serial Bus Requirements (Continued) 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. In ATmega1284P, this parameter is characterized and not 100% tested. Required only for fSCL > 100 kHz. Cb = capacitance of one bus line in pF. fCK = CPU clock frequency This requirement applies to all ATmega1284P 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 ATmega1284P 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 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, ATmega1284P devices connected to the bus may communicate at full speed (400 kHz) with other ATmega1284P 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 330 8059D-AVR-11/09 ATmega1284P 26.8 ADC Characteristics Table 26-8. Symbol ADC Characteristics, Single Ended Channel Typ(1) Max(1) Condition Resolution Single Ended Conversion 10 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz 3 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz Noise Reduction Mode 2 Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 1 MHz Noise Reduction Mode 3 Integral Non-Linearity (INL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 1.2 Differential Non-Linearity (DNL) Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 0.3 Gain Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz 2 Offset Error Single Ended Conversion VREF = 4V, VCC = 4V, ADC clock = 200 kHz -1.6 Conversion Time Free Running Conversion 13 260 s Clock Frequency Single Ended Conversion 50 1000 kHz VCC - 0.3 VCC + 0.3 V 1.0 AVCC V GND VREF V Absolute accuracy (Including INL, DNL, quantization error, gain and offset error) AVCC Analog Supply Voltage VREF Reference Voltage VIN Min(1) Parameter Input Voltage Units Bits LSB Input Bandwidth TBD kHz VINT1 Internal Voltage Reference 1.1V 1.0 1.1 1.2 V VINT2 Internal Voltage Reference 2.56V 2.33 2.56 2.79 V RREF Reference Input Resistance 32 k RAIN Analog Input Resistance 100 M Notes: 1. Values are guidelines only. 331 8059D-AVR-11/09 ATmega1284P Table 26-9. Symbol ADC Characteristics, Differential Channels Parameter Resolution Absolute Accuracy (Including INL, DNL Quantization Error and Offset Error) Integral Non-linearity (INL) Differential Non-linearity (DNL) Condition Min(1) Typ(1) Gain = 1x 10 Gain = 10x 10 Gain = 200x 7 Gain = 1x VCC =5 V, VREF = 4V ADC clock = 200 kHz 20 Gain = 10x VCC =5 V, VREF = 4V ADC clock = 200 kHz 20 Gain = 200x VCC =5 V, VREF = 4V ADC clock = 200 kHz 13 Gain = 1x VCC =5 V, VREF = 4V ADC clock = 200 kHz 2 Gain = 10x VCC =5 V, VREF = 4V ADC clock = 200 kHz 4 Gain = 200x VCC =5 V, VREF = 4V ADC clock = 200 kHz 13 Gain = 1x VCC =5 V, VREF = 4V ADC clock = 200 kHz 1 Gain = 10x VCC =5 V, VREF = 4V ADC clock = 200 kHz 1 Gain = 200x VCC =5 V, VREF = 4V ADC clock = 200 kHz 14 Max(1) Units Bits LSB 332 8059D-AVR-11/09 ATmega1284P Table 26-9. Symbol ADC Characteristics, Differential Channels (Continued) Parameter Gain Error Offset Error Min(1) Gain = 1x VCC =5 V, VREF = 4V ADC clock = 200 kHz 18 Gain = 10x VCC =5 V, VREF = 4V ADC clock = 200 kHz 18 Gain = 200x VCC =5 V, VREF = 4V ADC clock = 200 kHz 2 Gain = 1x VCC =5 V, VREF = 4V ADC clock = 200 kHz 2 Gain = 10x VCC =5 V, VREF = 4V ADC clock = 200 kHz 2 Gain = 200x VCC =5 V, VREF = 4V ADC clock = 200 kHz 2 Max(1) Units LSB 13 260 s Clock Frequency 50 1000 kHz VCC 0.3 VCC + 0.3 V 1.0 AVCC 0.5 V Input Differential Voltage 0 AVCC V ADC Conversion Output TBD TBD LSB Analog Supply Voltage VREF Reference Voltage Input Bandwidth Note: Typ(1) Conversion Time AVCC VIN Condition TBD kHz VINT1 Internal Voltage Reference 1.1V 1.0 1.1 1.2 V VINT2 Internal Voltage Reference 2.56V 2.33 2.56 2.79 V RREF Reference Input Resistance 32 k 1. Values are guidelines only. 333 8059D-AVR-11/09 ATmega1284P 27. Typical Characteristics The following charts show typical behavior. These figures are not tested during manufacturing. All current consumption measurements are performed with all I/O pins configured as inputs and with internal pull-ups enabled. A sine wave generator with rail-to-rail output is used as clock source. All Active- and Idle current consumption measurements are done with all bits in the PRR registers set and thus, the corresponding I/O modules are turned off. Also the Analog Comparator is disabled during these measurements. The power consumption in Power-down mode is independent of clock selection. The current consumption is a function of several factors such as: operating voltage, operating frequency, loading of I/O pins, switching rate of I/O pins, code executed and ambient temperature. The dominating factors are operating voltage and frequency. The current drawn from capacitive loaded pins may be estimated (for one pin) as CL*VCC*f where CL = load capacitance, VCC = operating voltage and f = average switching frequency of I/O pin. The parts are characterized at frequencies higher than test limits. Parts are not guaranteed to function properly at frequencies higher than the ordering code indicates. The difference between current consumption in Power-down mode with Watchdog Timer enabled and Power-down mode with Watchdog Timer disabled represents the differential current drawn by the Watchdog Timer. 27.1 Active Supply Current ICC (mA) Figure 27-1. ATmega1284P: Active Supply Current vs. Low Frequency (0.1 - 1.0 MHz) 1.6 5.5 V 1.4 5.0 V 1.2 4.5 V 1 4.0 V 0.8 3.3 V 0.6 2.7 V 0.4 1.8 V 0.2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) 334 8059D-AVR-11/09 ATmega1284P Figure 27-2. ATmega1284P: Active Supply Current vs. Frequency (1 - 20 MHz) 20 5.5 V 18 5.0 V 16 4.5 V ICC (mA) 14 12 4.0 V 10 8 3.3 V 6 2.7 V 4 2 1.8 V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 27-3. ATmega1284P: Active Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) 9 85 C 25 C -40 C 8 7 ICC (mA) 6 5 4 3 2 1 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 335 8059D-AVR-11/09 ATmega1284P Figure 27-4. ATmega1284P: Active Supply Current vs. VCC (Internal RC Oscillator, 1 MHz) 1.8 85 C 25 C -40 C 1.5 ICC (mA) 1.2 0.9 0.6 0.3 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-5. ATmega1284P: Active Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) 0.28 -40 C 25 C 85 C 0.24 ICC (mA) 0.2 0.16 0.12 0.08 0.04 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 336 8059D-AVR-11/09 ATmega1284P 27.2 Idle Supply Current Figure 27-6. ATmega1284P: Idle Supply Current vs. Low Frequency (0.1 - 1.0 MHz) 0.24 5.5 V 0.21 5.0 V 0.18 4.5 V 4.0 V 3.6 V ICC (mA) 0.15 0.12 2.7 V 0.09 1.8 V 0.06 0.03 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) Figure 27-7. ATmega1284P: Idle Supply Current vs. Frequency (1 - 20 MHz) 3 5.5 V 2.5 5.0 V 4.5 V ICC (mA) 2 1.5 4.0 V 1 2.7 V 0.5 3.3 V 1.8 V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) 337 8059D-AVR-11/09 ATmega1284P Figure 27-8. ATmega1284P: Idle Supply Current vs. VCC (Internal RC Oscillator, 8 MHz) 1.4 85 C 1.2 25 C -40 C ICC (mA) 1 0.8 0.6 0.4 0.2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-9. ATmega1284P: Idle Supply Current vs. VCC (Internal RC Oscillator, 1 MHz) 0.42 85 C 25 C -40 C 0.36 ICC (mA) 0.3 0.24 0.18 0.12 0.06 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 338 8059D-AVR-11/09 ATmega1284P Figure 27-10. ATmega1284P: Idle Supply Current vs. VCC (Internal RC Oscillator, 128 kHz) 0.28 -40 C 25 C 85 C 0.24 ICC (mA) 0.2 0.16 0.12 0.08 0.04 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 339 8059D-AVR-11/09 ATmega1284P 27.3 Supply Current of I/O modules The tables and formulas below can be used to calculate the additional current consumption for the different I/O modules in Active and Idle mode. The enabling or disabling of the I/O modules are controlled by the Power Reduction Register. See "PRR0 - Power Reduction Register 0" on page 46 for details. Table 27-1. PRR bit Additional Current Consumption for the different I/O modules (absolute values) Typical numbers in VCC = 2V, F = 1 MHz VCC = 3V, F = 4 MHz VCC = 5V, F = 8 MHz PRUSART1 3.0 A 19.2 A 87.7 A PRUSART0 2.9 A 19.2 A 88.5 A PRTWI 7.5 A 49.3 A 230.3 A PRTIM3 4.0 A 24.7 A 105.5 A PRTIM2 6.0 A 39.7 A 176.3 A PRTIM1 4.2 A 26.4 A 113.7 A PRTIM0 1.7 A 11.6 A 54.3 A PRADC 13.5 A 54.7 A 273 A PRSPI 5.7 A 40.6 A 212.2 A Table 27-2. Additional Current Consumption (percentage) in Active and Idle mode Additional Current consumption compared to Active with external clock (see Figure 27-1 on page 334 and Figure 27-2 on page 335) Additional Current consumption compared to Idle with external clock (see Figure 27-6 on page 337 and Figure 27-7 on page 337) PRUSART1 0.9% 6.0% PRUSART0 0.9% 6.0% PRTWI 2.3% 15.4% PRTIM3 1.1% 7.5% PRTIM2 1.8% 12.1% PRTIM1 1.2% 8.0% PRTIM0 0.5% 3.6% PRTADC 3.0% 19.8% PRSPI 2.0% 13.2% PRR bit It is possible to calculate the typical current consumption based on the numbers from Table 27-2 on page 340 for other VCC and frequency settings than listed in Table 27-1 on page 340. Example Calculate the expected current consumption in idle mode with TIMER1, ADC, and SPI enabled at VCC = 2.0V and F = 1MHz. From Table 27-2 on page 340, third column, we see that we need to add 8.0% for the TIMER1, 19.8% for the ADC, and 13.2% for the SPI module. Reading from Figure 27-7 on page 337, we find that the idle current consumption is ~0.075 mA at VCC = 2.0V and F = 1MHz. The total current consumption in idle mode with TIMER1, ADC, and SPI enabled, gives: 340 8059D-AVR-11/09 ATmega1284P I CC total 0.075 mA (1+ 0.08 + 0.198 + 0.132) 0.106 mA 27.4 Power-down Supply Current Figure 27-11. ATmega1284P: Power-down Supply Current vs. VCC (Watchdog Timer Disabled) 4 85 C 3.5 3 ICC (uA) 2.5 2 1.5 1 0.5 25 C -40 C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-12. ATmega1284P: Power-down Supply Current vs. VCC (Watchdog Timer Enabled) 11 85 C 10.2 9.4 ICC (uA) 8.6 -40 C 25 C 7.8 7 6.2 5.4 4.6 3.8 3 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 341 8059D-AVR-11/09 ATmega1284P 27.5 Power-save Supply Current Figure 27-13. ATmega1284P: Power-save Supply Current vs. VCC (Watchdog Timer Disabled and 32 kHz Crystal Oscillator Running). 5.0 85 C 4.5 4.0 ICC (uA) 3.5 3.0 2.5 2.0 1.5 25 C -40 C 1.0 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.6 Standby Supply Current Figure 27-14. ATmega1284P: Standby Supply Current vs. VCC (Watchdog Timer Disabled). 0.25 6MHz_xtal ICC (mA) 0.2 6MHz_res 4MHz_xtal 4MHz_res 2MHz_xtal 0.15 0.1 2MHz_res 1MHz_res 450kHz_res 0.05 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 342 8059D-AVR-11/09 ATmega1284P 27.7 Pin Pull-up Figure 27-15. ATmega1284P: I/O Pin Pull-up Resistor Current vs. Input Voltage (VCC = 1.8V). 50 45 40 IOP (uA) 35 30 25 20 15 10 -40 C 25 C 85 C 5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 VOP (V) Figure 27-16. ATmega1284P: I/O Pin Pull-up Resistor Current vs. Input Voltage (VCC = 2.7V). 80 70 60 IOP (uA) 50 40 30 20 -40 C 25 C 85 C 10 0 0 0.5 1 1.5 2 2.5 3 VOP (V) 343 8059D-AVR-11/09 ATmega1284P Figure 27-17. ATmega1284P: I/O Pin Pull-up Resistor Current vs. Input Voltage (VCC = 5V). 140 120 IOP (uA) 100 80 60 40 -40 C 25 C 85 C 20 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 VOP (V) Figure 27-18. ATmega1284P: Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 1.8V). 35 30 IRESET (uA) 25 20 15 10 -40 C 25 C 85 C 5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 VRESET (V) 344 8059D-AVR-11/09 ATmega1284P Figure 27-19. ATmega1284P: Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 2.7V). 60 50 IRESET (uA) 40 30 20 25 C -40 C 85 C 10 0 0 0.5 1 1.5 2 2.5 3 VRESET (V) Figure 27-20. ATmega1284P: Reset Pull-up Resistor Current vs. Reset Pin Voltage (VCC = 5V). 120 100 IRESET (uA) 80 60 40 20 -40 C 25 C 85 C 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 VRESET (V) 345 8059D-AVR-11/09 ATmega1284P 27.8 Pin Driver Strength Figure 27-21. ATmega1284P: I/O Pin Output Voltage vs. Sink Current (VCC = 2.7V). 1.2 85 C VOL (V) 1 0.8 25 C 0.6 -40 C 0.4 0.2 0 0 2 4 6 8 10 12 14 16 18 20 IOL (mA) Figure 27-22. ATmega1284P: I/O Pin Output Voltage vs. Sink Current (VCC = 3V). 0.9 85 C 0.8 0.7 25 C VOL (V) 0.6 -40 C 0.5 0.4 0.3 0.2 0.1 0 0 2 4 6 8 10 12 14 16 18 20 IOL (mA) 346 8059D-AVR-11/09 ATmega1284P Figure 27-23. ATmega1284P: I/O Pin Output Voltage vs. Sink Current (VCC = 5V). 0.6 85 C 0.5 25 C VOL (V) 0.4 -40 C 0.3 0.2 0.1 0 0 2 4 6 8 10 12 14 16 18 20 IOL(mA) Figure 27-24. ATmega1284P: I/O Pin Output Voltage vs. Source Current (VCC = 2.7V). 3 VOH (V) 2.5 2 -40 C 25 C 1.5 85 C 1 0.5 0 0 2 4 6 8 10 12 14 16 18 20 IOH (mA) 347 8059D-AVR-11/09 ATmega1284P Figure 27-25. ATmega1284P: I/O Pin Output Voltage vs. Source Current (VCC = 3V). 3.5 3 VOH (V) 2.5 -40 C 25 C 85 C 2 1.5 1 0.5 0 0 2 4 6 8 10 12 14 16 18 20 IOH (mA) 27.9 Pin Threshold and Hysteresis Figure 27-26. ATmega1284P: I/O Pin Input Threshold vs. VCC (VIH , I/O Pin Read as `1'). 3 85 C 25 C -40 C Threshold (V) 2.5 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 348 8059D-AVR-11/09 ATmega1284P Figure 27-27. ATmega1284P: I/O Pin Input Threshold vs. VCC (VIL, I/O Pin Read as `0'). 2.5 85 C -40 C 25 C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-28. ATmega1284P: I/O Pin Input Hysteresis vs. VCC 0.6 Input Hysteresis (mV) 0.55 85 C 25 C -40 C 0.5 0.45 0.4 0.35 0.3 0.25 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 349 8059D-AVR-11/09 ATmega1284P Figure 27-29. ATmega1284P: Reset Pin Input Threshold vs. VCC (VIH , I/O Pin Read as `1'). -40 C 85 C 25 C 2.5 Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-30. ATmega1284P: Reset Pin Input Threshold vs. VCC (VIL, I/O Pin Read as `0'). 2.5 -40 C 85 C 25 C Threshold (V) 2 1.5 1 0.5 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 350 8059D-AVR-11/09 ATmega1284P Figure 27-31. ATmega1284P: Reset Pin Input Hysteresis vs. VCC 0.6 Input Hysteresis (mV) 0.5 0.4 0.3 0.2 0.1 -40 C 25 C 85 C 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.10 BOD Threshold Figure 27-32. ATmega1284P: BOD Threshold vs. Temperature (VBOT = 4.3V) 4.37 Rising Vcc 4.35 Threshold (V) 4.33 4.31 Falling Vcc 4.29 4.27 4.25 4.23 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Temperature (C) 351 8059D-AVR-11/09 ATmega1284P Figure 27-33. ATmega1284P: BOD Threshold vs. Temperature (VBOT = 2.7V) 2.78 Rising Vcc Threshold (V) 2.76 2.74 2.72 2.7 Falling Vcc 2.68 2.66 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Temperature (C) Figure 27-34. ATmega1284P: BOD Threshold vs. Temperature (VBOT = 1.8V) 1.84 Rising Vcc Threshold (V) 1.83 1.82 1.81 Falling Vcc 1.8 1.79 1.78 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Temperature (C) 352 8059D-AVR-11/09 ATmega1284P 27.11 Internal Oscillator Speed Figure 27-35. ATmega1284P: Watchdog Oscillator Frequency vs. Temperature 123 122 121 FRC (kHz) 120 119 118 117 2.7 V 116 3.3 V 4.0 V 5.5 V 115 114 113 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Temperature (C) Figure 27-36. ATmega1284P: Watchdog Oscillator Frequency vs. VCC 124 122 FRC (kHz) -40 C 120 25 C 118 116 85 C 114 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 353 8059D-AVR-11/09 ATmega1284P Figure 27-37. ATmega1284P: Calibrated 8 MHz RC Oscillator vs. VCC 8.6 85 C 8.4 25 C FRC (MHz) 8.2 8 -40 C 7.8 7.6 7.4 7.2 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-38. ATmega1284P: Calibrated 8 MHz RC Oscillator vs. Temperature 8.3 5.5 V 8.2 3.3 V 2.7 V FRC (MHz) 8.1 1.8 V 8 7.9 7.8 7.7 7.6 7.5 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Temperature (C) 354 8059D-AVR-11/09 ATmega1284P Figure 27-39. ATmega1284P: Calibrated 8 MHz RC Oscillator vs. OSCCAL Value 16 85 C 25 C -40 C 14 FRC (MHz) 12 10 8 6 4 2 0 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 256 OSCCAL (X1) 27.12 Current Consumption of Peripheral Units Figure 27-40. ATmega1284P: ADC Current vs. VCC (AREF = AVCC) 280 -40 C 25 C 85 C 260 240 ICC (uA) 220 200 180 160 140 120 100 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 355 8059D-AVR-11/09 ATmega1284P Figure 27-41. ATmega1284P: Analog Comparator Current vs. VCC 85 -40 C 25 C 85 C 75 ICC (uA) 65 55 45 35 25 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-42. ATmega1284P: AREF External Reference Current vs. VCC 200 85 C 25 C -40 C 180 ICC (uA) 160 140 120 100 80 60 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 356 8059D-AVR-11/09 ATmega1284P ICC (uA) Figure 27-43. ATmega1284P: Brownout Detector Current vs. VCC 25 85 C 23 25 C 21 -40 C 19 17 15 13 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) Figure 27-44. ATmega1284P: Programming Current vs. VCC 14 -40 C 12 ICC (mA) 10 25 C 8 85 C 6 4 2 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 357 8059D-AVR-11/09 ATmega1284P Figure 27-45. ATmega1284P: Watchdog Timer Current vs. VCC 8.5 -40 C 7.5 25 C 85 C ICC (uA) 6.5 5.5 4.5 3.5 2.5 1.5 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 27.13 Current Consumption in Reset and Reset Pulsewidth Figure 27-46. ATmega1284P: Reset Supply Current vs. Low Frequency (0.1 - 1.0 MHz) 0.1 5.5 V 5.0 V 0.08 ICC (mA) 4.5 V 4.0 V 0.06 3.3 V 0.04 2.7 V 1.8 V 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) 358 8059D-AVR-11/09 ATmega1284P Figure 27-47. ATmega1284P: Reset Supply Current vs. Frequency (1 - 20 MHz) 1.6 5.5 V 1.4 5.0 V 1.2 4.5 V ICC (mA) 1 0.8 4.0 V 0.6 3.3 V 0.4 2.7 V 0.2 1.8 V 0 0 2 4 6 8 10 12 14 16 18 20 Frequency (MHz) Figure 27-48. ATmega1284P: Minimum Reset Pulsewidth vs. VCC 1800 1600 Pulsewidth (ns) 1400 1200 1000 800 600 400 85 C 25 C -40 C 200 0 1.5 2 2.5 3 3.5 4 4.5 5 5.5 VCC (V) 359 8059D-AVR-11/09 ATmega1284P 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 - - - (0xC7) Reserved UDR0 (0xC5) UBRR0H - - USART1 I/O Data Register (0xCC) (0xC6) - - 189 USART1 Baud Rate Register High Byte 193/206 USART1 Baud Rate Register Low Byte 193/206 - - - - - UPM11 UPM10 USBS1 UCSZ11 UCSZ10 UCPOL1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 190/204 FE1 DOR1 UPE1 U2X1 MPCM1 189/204 - - - - - USART0 I/O Data Register - - - (0xC4) UBRR0L (0xC3) Reserved - - (0xC2) UCSR0C UMSEL01 UMSEL00 (0xC1) UCSR0B RXCIE0 TXCIE0 Page - 191/205 189 USART0 Baud Rate Register High Byte 193/206 USART0 Baud Rate Register Low Byte 193/206 - - - - - UPM01 UPM00 USBS0 UCSZ01 UCSZ00 UCPOL0 191/205 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 190/204 360 8059D-AVR-11/09 ATmega1284P Address (0xC0) Name UCSR0A Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 189/204 (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 235 (0xB9) TWSR TWS7 TWS6 TWS5 TWS4 TWS3 - TWPS1 TWPS0 234 2-wire Serial Interface Data Register 235 232 234 (0xB8) TWBR (0xB7) Reserved - - - 2-wire Serial Interface Bit Rate Register - - - - - 232 (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) OCR3BH Timer/Counter3 - Output Compare Register B High Byte (0x9A) OCR3BL Timer/Counter3 - Output Compare Register B Low Byte 135 (0x99) OCR3AH Timer/Counter3 - Output Compare Register A High Byte 135 (0x98) OCR3AL Timer/Counter3 - Output Compare Register A Low Byte 135 (0x97) ICR3H Timer/Counter3 - Input Capture Register High Byte 136 (0x96) ICR3L Timer/Counter3 - Input Capture Register Low Byte 136 (0x95) TCNT3H Timer/Counter3 - Counter Register High Byte 135 135 (0x94) TCNT3L (0x93) Reserved - - - Timer/Counter3 - Counter Register Low Byte (0x92) TCCR3C FOC3A FOC3B - - - - - - (0x91) TCCR3B ICNC3 ICES3 - WGM33 WGM32 CS32 CS31 CS30 133 (0x90) TCCR3A COM3A1 COM3A0 COM3B1 COM3B0 - - WGM31 WGM30 131 - - 135 - - 134 (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 135 (0x89) OCR1AH Timer/Counter1 - Output Compare Register A High Byte 135 (0x88) OCR1AL Timer/Counter1 - Output Compare Register A Low Byte 135 (0x87) ICR1H Timer/Counter1 - Input Capture Register High Byte 136 (0x86) ICR1L Timer/Counter1 - Input Capture Register Low Byte 136 (0x85) TCNT1H Timer/Counter1 - Counter Register High Byte 135 135 (0x84) TCNT1L (0x83) Reserved - - - Timer/Counter1 - Counter Register Low Byte (0x82) TCCR1C FOC1A FOC1B - - - - - - 134 (0x81) TCCR1B ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 133 (0x80) TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 - - WGM11 WGM10 131 (0x7F) DIDR1 - - - - - - AIN1D AIN0D 239 - - 135 - - - 361 8059D-AVR-11/09 ATmega1284P 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 259 - - - - - - - - (0x7C) ADMUX REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 255 (0x7B) ADCSRB - ACME - - - ADTS2 ADTS1 ADTS0 238 (0x7A) ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 (0x79) ADCH ADC Data Register High byte 257 258 (0x78) ADCL (0x77) Reserved - - - ADC Data Register Low byte - - - - - 258 (0x76) Reserved - - - - - - - - (0x75) Reserved - - - - - - - - (0x74) Reserved - - - - - - - - (0x73) PCMSK3 PCINT31 PCINT30 PCINT29 PCINT28 PCINT27 PCINT26 PCINT25 PCINT24 (0x72) Reserved - - - - - - - - (0x71) TIMSK3 - - ICIE3 - - OCIE3B OCIE3A TOIE3 137 (0x70) TIMSK2 - - - - - OCIE2B OCIE2A TOIE2 159 (0x6F) TIMSK1 - - ICIE1 - - OCIE1B OCIE1A TOIE1 136 (0x6E) TIMSK0 - - - - - OCIE0B OCIE0A TOIE0 108 (0x6D) PCMSK2 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 68 (0x6C) PCMSK1 PCINT15 PCINT14 PCINT13 PCINT12 PCINT11 PCINT10 PCINT9 PCINT8 68 (0x6B) PCMSK0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 69 (0x6A) Reserved - - - - - - - - (0x69) EICRA - - ISC21 ISC20 ISC11 ISC10 ISC01 ISC00 65 (0x68) PCICR - - - - PCIE3 PCIE2 PCIE1 PCIE0 67 (0x67) Reserved - - - - - - - - (0x66) OSCCAL (0x65) PRR1 - - - - - - - PRTIM3 46 (0x64) PRR0 PRTWI PRTIM2 PRTIM0 PRUSART1 PRTIM1 PRSPI PRUSART0 PRADC 46 (0x63) Reserved - - - - - - - - (0x62) Reserved - - - - - - - - (0x61) CLKPR CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0 38 (0x60) WDTCSR WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 57 8 Oscillator Calibration Register 68 38 0x3F (0x5F) SREG I T H S V N Z C 0x3E (0x5E) SPH SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 9 0x3D (0x5D) SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 9 0x3C (0x5C) Reserved - - - - - - - - 0x3B (0x5B) RAMPZ - - - - - - - RAMPZ0 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/275 0x34 (0x54) MCUSR - - - JTRF WDRF BORF EXTRF PORF 56/275 45 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 12 289 265 257 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 SPI 0 Data Register - - - - 170 26 26 - - - 108 EEPROM Address Register High Byte 21 EEPROM Address Register Low Byte 21 EEPROM Data Register - - EEPM1 - - - EEPM0 EERIE 21 EEMWE EEWE EERE 21 INT2 INT1 INT0 66 General Purpose I/O Register 0 - - 26 362 8059D-AVR-11/09 ATmega1284P 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 66 0x1B (0x3B) PCIFR - - - - PCIF3 PCIF2 PCIF1 PCIF0 67 0x1A (0x3A) Reserved - - - - - - - - 0x19 (0x39) Reserved - - - - - - - - 0x18 (0x38) TIFR3 - - ICF3 - - OCF3B OCF3A TOV3 138 0x17 (0x37) TIFR2 - - - - - OCF2b OCF2A TOV2 160 0x16 (0x36) TIFR1 - - ICF1 - - OCF1B OCF1A TOV1 137 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 ATmega1284P 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. 363 8059D-AVR-11/09 ATmega1284P 29. Instruction Set Summary Mnemonics Operands Description Operation Flags #Clocks ARITHMETIC AND LOGIC INSTRUCTIONS ADD Rd, Rr Add two Registers Rd Rd + Rr Z,C,N,V,H ADC Rd, Rr Add with Carry two Registers Rd Rd + Rr + C Z,C,N,V,H 1 ADIW Rdl,K Add Immediate to Word Rdh:Rdl Rdh:Rdl + K Z,C,N,V,S 2 SUB Rd, Rr Subtract two Registers Rd Rd - Rr Z,C,N,V,H 1 SUBI Rd, K Subtract Constant from Register Rd Rd - K Z,C,N,V,H 1 SBC Rd, Rr Subtract with Carry two Registers Rd Rd - Rr - C Z,C,N,V,H 1 SBCI Rd, K Subtract with Carry Constant from Reg. Rd Rd - K - C Z,C,N,V,H 1 SBIW Rdl,K Subtract Immediate from Word Rdh:Rdl Rdh:Rdl - K Z,C,N,V,S 2 AND Rd, Rr Logical AND Registers Rd Rd * Rr Z,N,V 1 ANDI Rd, K Logical AND Register and Constant Rd Rd * K Z,N,V 1 OR Rd, Rr Logical OR Registers Rd Rd v Rr Z,N,V 1 ORI Rd, K Logical OR Register and Constant Rd Rd v K Z,N,V 1 EOR Rd, Rr Exclusive OR Registers Rd Rd Rr Z,N,V 1 1 COM Rd One's Complement Rd 0xFF - Rd Z,C,N,V 1 NEG Rd Two's Complement Rd 0x00 - Rd Z,C,N,V,H 1 SBR Rd,K Set Bit(s) in Register Rd Rd v K Z,N,V 1 CBR Rd,K Clear Bit(s) in Register Rd Rd * (0xFF - K) Z,N,V 1 INC Rd Increment Rd Rd + 1 Z,N,V 1 DEC Rd Decrement Rd Rd - 1 Z,N,V 1 TST Rd Test for Zero or Minus Rd Rd * Rd Z,N,V 1 CLR Rd Clear Register Rd Rd Rd Z,N,V 1 SER Rd Set Register Rd 0xFF None 1 MUL Rd, Rr Multiply Unsigned R1:R0 Rd x Rr Z,C 2 MULS Rd, Rr Multiply Signed R1:R0 Rd x Rr Z,C 2 MULSU Rd, Rr Multiply Signed with Unsigned R1:R0 Rd x Rr Z,C 2 FMUL Rd, Rr Fractional Multiply Unsigned R1:R0 (Rd x Rr) << 1 R1:R0 (Rd x Rr) << 1 R1:R0 (Rd x Rr) << 1 Z,C 2 Z,C 2 Z,C 2 2 FMULS Rd, Rr Fractional Multiply Signed FMULSU Rd, Rr Fractional Multiply Signed with Unsigned BRANCH INSTRUCTIONS RJMP k IJMP Relative Jump PC PC + k + 1 None Indirect Jump to (Z) PC Z None 2 JMP k Direct Jump PC k None 3 RCALL k Relative Subroutine Call PC PC + k + 1 None 4 Indirect Call to (Z) PC Z None 4 Direct Subroutine Call PC k None 5 RET Subroutine Return PC STACK None 5 RETI Interrupt Return PC STACK I 5 ICALL CALL k CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC PC + 2 or 3 None CP Rd,Rr Compare Rd - Rr Z, N,V,C,H 1 CPC Rd,Rr Compare with Carry Rd - Rr - C Z, N,V,C,H 1 CPI Rd,K Compare Register with Immediate Rd - K Z, N,V,C,H SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC PC + 2 or 3 None 1/2/3 1/2/3 1 SBRS Rr, b Skip if Bit in Register is Set if (Rr(b)=1) PC PC + 2 or 3 None 1/2/3 SBIC P, b Skip if Bit in I/O Register Cleared if (P(b)=0) PC PC + 2 or 3 None 1/2/3 SBIS P, b Skip if Bit in I/O Register is Set if (P(b)=1) PC PC + 2 or 3 None 1/2/3 BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) then PCPC+k + 1 None 1/2 BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then PCPC+k + 1 None 1/2 BREQ k Branch if Equal if (Z = 1) then PC PC + k + 1 None 1/2 BRNE k Branch if Not Equal if (Z = 0) then PC PC + k + 1 None 1/2 BRCS k Branch if Carry Set if (C = 1) then PC PC + k + 1 None 1/2 BRCC k Branch if Carry Cleared if (C = 0) then PC PC + k + 1 None 1/2 BRSH k Branch if Same or Higher if (C = 0) then PC PC + k + 1 None 1/2 BRLO k Branch if Lower if (C = 1) then PC PC + k + 1 None 1/2 BRMI k Branch if Minus if (N = 1) then PC PC + k + 1 None 1/2 BRPL k Branch if Plus if (N = 0) then PC PC + k + 1 None 1/2 BRGE k Branch if Greater or Equal, Signed if (N V= 0) then PC PC + k + 1 None 1/2 BRLT k Branch if Less Than Zero, Signed if (N V= 1) then PC PC + k + 1 None 1/2 BRHS k Branch if Half Carry Flag Set if (H = 1) then PC PC + k + 1 None 1/2 BRHC k Branch if Half Carry Flag Cleared if (H = 0) then PC PC + k + 1 None 1/2 BRTS k Branch if T Flag Set if (T = 1) then PC PC + k + 1 None 1/2 BRTC k Branch if T Flag Cleared if (T = 0) then PC PC + k + 1 None 1/2 BRVS k Branch if Overflow Flag is Set if (V = 1) then PC PC + k + 1 None 1/2 364 8059D-AVR-11/09 ATmega1284P Mnemonics Operands Description Operation Flags #Clocks BRVC k Branch if Overflow Flag is Cleared if (V = 0) then PC PC + k + 1 None 1/2 BRIE k Branch if Interrupt Enabled if ( I = 1) then PC PC + k + 1 None 1/2 BRID k Branch if Interrupt Disabled if ( I = 0) then PC PC + k + 1 None 1/2 BIT AND BIT-TEST INSTRUCTIONS SBI P,b Set Bit in I/O Register I/O(P,b) 1 None 2 CBI P,b Clear Bit in I/O Register I/O(P,b) 0 None 2 LSL Rd Logical Shift Left Rd(n+1) Rd(n), Rd(0) 0 Z,C,N,V 1 LSR Rd Logical Shift Right Rd(n) Rd(n+1), Rd(7) 0 Z,C,N,V 1 ROL Rd Rotate Left Through Carry Rd(0)C,Rd(n+1) Rd(n),CRd(7) Z,C,N,V 1 ROR Rd Rotate Right Through Carry Rd(7)C,Rd(n) Rd(n+1),CRd(0) Z,C,N,V 1 ASR Rd Arithmetic Shift Right Rd(n) Rd(n+1), n=0..6 Z,C,N,V 1 SWAP Rd Swap Nibbles Rd(3..0)Rd(7..4),Rd(7..4)Rd(3..0) None 1 BSET s Flag Set SREG(s) 1 SREG(s) 1 BCLR s Flag Clear SREG(s) 0 SREG(s) 1 BST Rr, b Bit Store from Register to T T Rr(b) T 1 BLD Rd, b Bit load from T to Register Rd(b) T None 1 SEC Set Carry C1 C 1 CLC Clear Carry C0 C 1 SEN Set Negative Flag N1 N 1 CLN Clear Negative Flag N0 N 1 SEZ Set Zero Flag Z1 Z 1 CLZ Clear Zero Flag Z0 Z 1 SEI Global Interrupt Enable I1 I 1 CLI Global Interrupt Disable I0 I 1 SES Set Signed Test Flag S1 S 1 CLS Clear Signed Test Flag S0 S 1 SEV Set Twos Complement Overflow. V1 V 1 CLV Clear Twos Complement Overflow V0 V 1 SET Set T in SREG T1 T 1 CLT Clear T in SREG T0 T 1 SEH CLH Set Half Carry Flag in SREG Clear Half Carry Flag in SREG H1 H0 H H 1 1 Rd Rr Rd+1:Rd Rr+1:Rr None 1 None 1 1 DATA TRANSFER INSTRUCTIONS MOV Rd, Rr Move Between Registers MOVW Rd, Rr Copy Register Word LDI Rd, K Load Immediate Rd K None LD Rd, X Load Indirect Rd (X) None 2 LD Rd, X+ Load Indirect and Post-Inc. Rd (X), X X + 1 None 2 2 LD Rd, - X Load Indirect and Pre-Dec. X X - 1, Rd (X) None LD Rd, Y Load Indirect Rd (Y) None 2 LD Rd, Y+ Load Indirect and Post-Inc. Rd (Y), Y Y + 1 None 2 LD Rd, - Y Load Indirect and Pre-Dec. Y Y - 1, Rd (Y) None 2 LDD Rd,Y+q Load Indirect with Displacement Rd (Y + q) None 2 LD Rd, Z Load Indirect Rd (Z) None 2 LD Rd, Z+ Load Indirect and Post-Inc. Rd (Z), Z Z+1 None 2 LD Rd, -Z Load Indirect and Pre-Dec. Z Z - 1, Rd (Z) None 2 LDD Rd, Z+q Load Indirect with Displacement Rd (Z + q) None 2 LDS Rd, k Load Direct from SRAM Rd (k) None 2 ST X, Rr Store Indirect (X) Rr None 2 ST X+, Rr Store Indirect and Post-Inc. (X) Rr, X X + 1 None 2 ST - X, Rr Store Indirect and Pre-Dec. X X - 1, (X) Rr None 2 ST Y, Rr Store Indirect (Y) Rr None 2 ST Y+, Rr Store Indirect and Post-Inc. (Y) Rr, Y Y + 1 None 2 ST - Y, Rr Store Indirect and Pre-Dec. Y Y - 1, (Y) Rr None 2 STD Y+q,Rr Store Indirect with Displacement (Y + q) Rr None 2 ST Z, Rr Store Indirect (Z) Rr None 2 ST Z+, Rr Store Indirect and Post-Inc. (Z) Rr, Z Z + 1 None 2 ST -Z, Rr Store Indirect and Pre-Dec. Z Z - 1, (Z) Rr None 2 STD Z+q,Rr Store Indirect with Displacement (Z + q) Rr None 2 STS k, Rr Store Direct to SRAM (k) Rr None 2 Load Program Memory R0 (Z) None 3 LPM LPM Rd, Z Load Program Memory Rd (Z) None 3 LPM Rd, Z+ Load Program Memory and Post-Inc Rd (Z), Z Z+1 None 3 Extended Load Program Memory R0 (RAMPZ:Z) None 3 ELPM Rd, Z Extended Load Program Memory Rd (Z) None 3 ELPM Rd, Z+ Extended Load Program Memory Rd (RAMPZ:Z), RAMPZ:Z RAMPZ:Z+1 None 3 ELPM 365 8059D-AVR-11/09 ATmega1284P Mnemonics Operands SPM Description Operation Flags #Clocks Store Program Memory (Z) R1:R0 None - Rd P None 1 IN Rd, P In Port OUT P, Rr Out Port P Rr None 1 PUSH Rr Push Register on Stack STACK Rr None 2 POP Rd Pop Register from Stack Rd STACK None 2 MCU CONTROL INSTRUCTIONS NOP No Operation None 1 SLEEP Sleep (see specific descr. for Sleep function) None 1 WDR BREAK Watchdog Reset Break (see specific descr. for WDR/timer) For On-chip Debug Only None None 1 N/A 366 8059D-AVR-11/09 ATmega1284P 30. Ordering Information 30.1 ATmega1284P Speed (MHz)(3) Power Supply Package(1) Ordering Code (2) 20 Notes: 1.8 - 5.5V ATmega1284P-AU ATmega1284P-PU(2) ATmega1284P-MU(2) 44A 40P6 44M1 Operational Range Industrial (-40oC to 85oC) 1. This device can also be supplied in wafer form. Please contact your local Atmel sales office for detailed ordering information and minimum quantities. 2. Pb-free packaging, complies to the European Directive for Restriction of Hazardous Substances (RoHS directive). Also Halide free and fully Green. 3. For Speed vs. VCC see "Speed Grades" on page 325. Package Type 44A 44-lead, Thin (1.0 mm) Plastic Gull Wing Quad Flat Package (TQFP) 40P6 40-pin, 0.600" Wide, Plastic Dual Inline Package (PDIP) 44M1 44-pad, 7 x 7 x 1.0 mm body, lead pitch 0.50 mm, Quad Flat No-Lead/Micro Lead Frame Package (QFN/MLF) 367 8059D-AVR-11/09 ATmega1284P 31. Packaging Information 31.1 44A PIN 1 B PIN 1 IDENTIFIER E1 e E D1 D C 0~7 A1 A2 A L COMMON DIMENSIONS (Unit of Measure = mm) Notes: 1. This package conforms to JEDEC reference MS-026, Variation ACB. 2. Dimensions D1 and E1 do not include mold protrusion. Allowable protrusion is 0.25 mm per side. Dimensions D1 and E1 are maximum plastic body size dimensions including mold mismatch. 3. Lead coplanarity is 0.10 mm maximum. SYMBOL MIN NOM MAX A - - 1.20 A1 0.05 - 0.15 A2 0.95 1.00 1.05 D 11.75 12.00 12.25 D1 9.90 10.00 10.10 E 11.75 12.00 12.25 E1 9.90 10.00 10.10 B 0.30 - 0.45 C 0.09 - 0.20 L 0.45 - 0.75 e NOTE Note 2 Note 2 0.80 TYP 10/5/2001 R 2325 Orchard Parkway San Jose, CA 95131 TITLE 44A, 44-lead, 10 x 10 mm Body Size, 1.0 mm Body Thickness, 0.8 mm Lead Pitch, Thin Profile Plastic Quad Flat Package (TQFP) DRAWING NO. REV. 44A B 368 8059D-AVR-11/09 ATmega1284P 31.2 40P6 D PIN 1 E1 A SEATING PLANE A1 L B B1 e E 0 ~ 15 C COMMON DIMENSIONS (Unit of Measure = mm) REF MIN NOM MAX A - - 4.826 A1 0.381 - - SYMBOL eB Notes: 1. This package conforms to JEDEC reference MS-011, Variation AC. 2. Dimensions D and E1 do not include mold Flash or Protrusion. Mold Flash or Protrusion shall not exceed 0.25 mm (0.010"). D 52.070 - 52.578 E 15.240 - 15.875 E1 13.462 - 13.970 B 0.356 - 0.559 B1 1.041 - 1.651 L 3.048 - 3.556 C 0.203 - 0.381 eB 15.494 - 17.526 e NOTE Note 2 Note 2 2.540 TYP 09/28/01 R 2325 Orchard Parkway San Jose, CA 95131 TITLE 40P6, 40-lead (0.600"/15.24 mm Wide) Plastic Dual Inline Package (PDIP) DRAWING NO. 40P6 REV. B 369 8059D-AVR-11/09 ATmega1284P 31.3 44M1 D Marked Pin# 1 ID E SEATING PLANE A1 TOP VIEW A3 A K L Pin #1 Corner D2 1 2 3 Option A SIDE VIEW Pin #1 Triangle E2 Option B K Option C b e Pin #1 Chamfer (C 0.30) Pin #1 Notch (0.20 R) BOTTOM VIEW COMMON DIMENSIONS (Unit of Measure = mm) SYMBOL MIN NOM MAX A 0.80 0.90 1.00 A1 - 0.02 0.05 A3 0.20 REF b 0.18 0.23 0.30 D 6.90 7.00 7.10 D2 5.00 5.20 5.40 E 6.90 7.00 7.10 E2 5.00 5.20 5.40 e Note: JEDEC Standard MO-220, Fig. 1 (SAW Singulation) VKKD-3. NOTE 0.50 BSC L 0.59 0.64 0.69 K 0.20 0.26 0.41 9/26/08 Package Drawing Contact: packagedrawings@atmel.com TITLE 44M1, 44-pad, 7 x 7 x 1.0 mm Body, Lead Pitch 0.50 mm, 5.20 mm Exposed Pad, Thermally Enhanced Plastic Very Thin Quad Flat No Lead Package (VQFN) GPC ZWS DRAWING NO. REV. 44M1 H 370 8059D-AVR-11/09 ATmega1284P 32. Errata 32.1 ATmega1284P Rev. A No known Errata. 371 8059D-AVR-11/09 ATmega1284P 33. Datasheet Revision History Please note that the referring page numbers in this section are referred to this document. The referring revision in this section are referring to the document revision. 33.1 Rev. 8059D - 11/09 1. 2. 3. 4. 33.2 Rev. 8059C - 07/09 1. 2. 33.3 Updated "ADC Characteristics" on page 331. Added "Typical Characteristics" on page 334. Rev. 8059B - 05/08 1. 2. 33.4 Added Table 7-8 on page 32. Updated Table 7.5 on page 32 Removed Note 3 from Table 8-1 on page 40. Updated Assembly Code Example in "Watchdog Timer" on page 53. Updated figure "Speed Grades" on page 325. Updated "Ordering Information" on page 367. Rev. 8059A - 04/08 1. Initial revision. 372 8059D-AVR-11/09 ATmega1284P Features ..................................................................................................... 1 1 Pin Configurations ................................................................................... 2 2 Overview ................................................................................................... 3 2.1Block Diagram ...........................................................................................................3 2.2Pin Descriptions ........................................................................................................4 3 Resources ................................................................................................. 6 4 About Code Examples ............................................................................. 6 5 AVR CPU Core .......................................................................................... 7 5.1Overview ...................................................................................................................7 5.2ALU - Arithmetic Logic Unit ......................................................................................8 5.3Status Register ..........................................................................................................8 5.4General Purpose Register File ................................................................................10 5.5Stack Pointer ...........................................................................................................11 5.6Instruction Execution Timing ...................................................................................12 5.7Reset and Interrupt Handling ..................................................................................13 6 AVR Memories ........................................................................................ 16 6.1Overview .................................................................................................................16 6.2In-System Reprogrammable Flash Program Memory .............................................16 6.3SRAM Data Memory ...............................................................................................17 6.4EEPROM Data Memory ..........................................................................................19 6.5I/O Memory ..............................................................................................................20 6.6Register Description ................................................................................................21 7 System Clock and Clock Options ......................................................... 27 7.1Clock Systems and their Distribution .......................................................................27 7.2Clock Sources .........................................................................................................28 7.3Low Power Crystal Oscillator ...................................................................................30 7.4Full Swing Crystal Oscillator ....................................................................................31 7.5Low Frequency Crystal Oscillator ............................................................................32 7.6Calibrated Internal RC Oscillator .............................................................................34 7.7128 kHz Internal Oscillator ......................................................................................35 7.8External Clock .........................................................................................................35 7.9Timer/Counter Oscillator .........................................................................................36 7.10Clock Output Buffer ...............................................................................................36 7.11System Clock Prescaler ........................................................................................36 i 8059D-AVR-11/09 ATmega1284P 7.12Register Description ..............................................................................................38 8 Power Management and Sleep Modes ................................................. 40 8.1Overview .................................................................................................................40 8.2Sleep Modes ...........................................................................................................40 8.3BOD Disable ............................................................................................................41 8.4Idle Mode .................................................................................................................41 8.5ADC Noise Reduction Mode ...................................................................................41 8.6Power-down Mode ..................................................................................................42 8.7Power-save Mode ...................................................................................................42 8.8Standby Mode .........................................................................................................42 8.9Extended Standby Mode .........................................................................................42 8.10Power Reduction Registers ...................................................................................43 8.11Minimizing Power Consumption ............................................................................43 8.12Register Description ..............................................................................................45 9 System Control and Reset .................................................................... 48 9.1Resetting the AVR ...................................................................................................48 9.2Internal Voltage Reference ......................................................................................52 9.3Watchdog Timer ......................................................................................................53 9.4Register Description ................................................................................................56 10 Interrupts ................................................................................................ 59 10.1Overview ...............................................................................................................59 10.2Interrupt Vectors in ATmega1284P .......................................................................59 10.3Register Description ..............................................................................................63 11 External Interrupts ................................................................................. 65 11.1Overview ...............................................................................................................65 11.2Register Description ..............................................................................................65 12 I/O-Ports .................................................................................................. 70 12.1Overview ...............................................................................................................70 12.2Ports as General Digital I/O ...................................................................................71 12.3Alternate Port Functions ........................................................................................76 12.4Register Description ..............................................................................................90 13 8-bit Timer/Counter0 with PWM ............................................................ 92 13.1Features ................................................................................................................92 13.2Overview ...............................................................................................................92 ii 8059D-AVR-11/09 ATmega1284P 13.3Timer/Counter Clock Sources ...............................................................................93 13.4Counter Unit ..........................................................................................................93 13.5Output Compare Unit ............................................................................................94 13.6Compare Match Output Unit ..................................................................................96 13.7Modes of Operation ...............................................................................................97 13.8Timer/Counter Timing Diagrams .........................................................................101 13.9Register Description ............................................................................................103 14 16-bit Timer/Counter1 and Timer/Counter3 with PWM ..................... 110 14.1Features ..............................................................................................................110 14.2Overview .............................................................................................................110 14.3Accessing 16-bit Registers ..................................................................................112 14.4Timer/Counter Clock Sources .............................................................................115 14.5Counter Unit ........................................................................................................116 14.6Input Capture Unit ...............................................................................................117 14.7Output Compare Units .........................................................................................119 14.8Compare Match Output Unit ................................................................................121 14.9Modes of Operation .............................................................................................122 14.10Timer/Counter Timing Diagrams .......................................................................129 14.11Register Description ..........................................................................................131 15 8-bit Timer/Counter2 with PWM and Asynchronous Operation ...... 140 15.1Features ..............................................................................................................140 15.2Overview .............................................................................................................140 15.3Timer/Counter Clock Sources .............................................................................141 15.4Counter Unit ........................................................................................................142 15.5Output Compare Unit ..........................................................................................142 15.6Compare Match Output Unit ................................................................................144 15.7Modes of Operation .............................................................................................145 15.8Timer/Counter Timing Diagrams .........................................................................149 15.9Asynchronous Operation of Timer/Counter2 .......................................................151 15.10Timer/Counter Prescaler ...................................................................................153 15.11Register Description ..........................................................................................153 16 SPI - Serial Peripheral Interface ......................................................... 161 16.1Features ..............................................................................................................161 16.2Overview .............................................................................................................161 16.3SS Pin Functionality ............................................................................................166 iii 8059D-AVR-11/09 ATmega1284P 16.4Data Modes .........................................................................................................166 16.5Register Description ............................................................................................168 17 USART ................................................................................................... 171 17.1Features ..............................................................................................................171 17.2USART1 and USART0 ........................................................................................171 17.3Overview .............................................................................................................171 17.4Clock Generation .................................................................................................172 17.5Frame Formats ....................................................................................................175 17.6USART Initialization ............................................................................................176 17.7Data Transmission - The USART Transmitter ....................................................177 17.8Data Reception - The USART Receiver .............................................................180 17.9Asynchronous Data Reception ............................................................................184 17.10Multi-processor Communication Mode ..............................................................187 17.11Register Description ..........................................................................................189 17.12Examples of Baud Rate Setting ........................................................................194 18 USART in SPI Mode ............................................................................. 198 18.1Features ..............................................................................................................198 18.2Overview .............................................................................................................198 18.3Clock Generation .................................................................................................198 18.4SPI Data Modes and Timing ...............................................................................199 18.5Frame Formats ....................................................................................................199 18.6Data Transfer ......................................................................................................201 18.7AVR USART MSPIM vs. AVR SPI ......................................................................203 18.8Register Description ............................................................................................204 19 2-wire Serial Interface .......................................................................... 207 19.1Features ..............................................................................................................207 19.22-wire Serial Interface Bus Definition ..................................................................207 19.3Data Transfer and Frame Format ........................................................................208 19.4Multi-master Bus Systems, Arbitration and Synchronization ...............................211 19.5Overview of the TWI Module ...............................................................................213 19.6Using the TWI ......................................................................................................215 19.7Transmission Modes ...........................................................................................218 19.8Multi-master Systems and Arbitration ..................................................................231 19.9Register Description ............................................................................................232 20 AC - Analog Comparator ..................................................................... 237 iv 8059D-AVR-11/09 ATmega1284P 20.1Overview .............................................................................................................237 20.2Analog Comparator Multiplexed Input .................................................................237 20.3Register Description ............................................................................................238 21 ADC - Analog-to-digital Converter ..................................................... 240 21.1Features ..............................................................................................................240 21.2Overview .............................................................................................................240 21.3Operation .............................................................................................................241 21.4Starting a Conversion ..........................................................................................242 21.5Prescaling and Conversion Timing ......................................................................243 21.6Changing Channel or Reference Selection .........................................................246 21.7ADC Noise Canceler ...........................................................................................248 21.8ADC Conversion Result ......................................................................................253 21.9Register Description ............................................................................................255 22 JTAG Interface and On-chip Debug System ..................................... 260 22.1Features ..............................................................................................................260 22.2Overview .............................................................................................................260 22.3TAP - Test Access Port ......................................................................................260 22.4TAP Controller .....................................................................................................262 22.5Using the Boundary-scan Chain ..........................................................................263 22.6Using the On-chip Debug System .......................................................................263 22.7On-chip Debug Specific JTAG Instructions .........................................................264 22.8Using the JTAG Programming Capabilities .........................................................264 22.9Bibliography .........................................................................................................265 22.10Register Description ..........................................................................................265 23 IEEE 1149.1 (JTAG) Boundary-scan ................................................... 266 23.1Features ..............................................................................................................266 23.2Overview .............................................................................................................266 23.3Data Registers .....................................................................................................267 23.4Boundary-scan Specific JTAG Instructions .........................................................268 23.5Boundary-scan Chain ..........................................................................................269 23.6ATmega1284P Boundary-scan Order .................................................................272 23.7Boundary-scan Description Language Files ........................................................274 23.8Register Description ............................................................................................275 24 Boot Loader Support - Read-While-Write Self-Programming ......... 276 24.1Features ..............................................................................................................276 v 8059D-AVR-11/09 ATmega1284P 24.2Overview .............................................................................................................276 24.3Application and Boot Loader Flash Sections .......................................................276 24.4Read-While-Write and No Read-While-Write Flash Sections ..............................277 24.5Boot Loader Lock Bits .........................................................................................279 24.6Entering the Boot Loader Program ......................................................................280 24.7Addressing the Flash During Self-Programming .................................................281 24.8Self-Programming the Flash ................................................................................282 24.9Register Description ............................................................................................289 25 Memory Programming ......................................................................... 291 25.1Program And Data Memory Lock Bits .................................................................291 25.2Fuse Bits .............................................................................................................292 25.3Signature Bytes ...................................................................................................294 25.4Calibration Byte ...................................................................................................294 25.5Page Size ............................................................................................................294 25.6Parallel Programming Parameters, Pin Mapping, and Commands .....................294 25.7Parallel Programming ..........................................................................................297 25.8Serial Downloading .............................................................................................306 25.9Serial Programming Instruction set .....................................................................308 25.10Programming via the JTAG Interface ................................................................310 26 Electrical Characteristics .................................................................... 323 26.1DC Characteristics ..............................................................................................323 26.2Speed Grades .....................................................................................................325 26.3Clock Characteristics ...........................................................................................326 26.4System and Reset Characteristics ......................................................................327 26.5External Interrupts Characteristics ......................................................................327 26.6SPI Timing Characteristics ..................................................................................328 26.72-wire Serial Interface Characteristics .................................................................329 26.8ADC Characteristics ............................................................................................331 27 Typical Characteristics ........................................................................ 334 27.1Active Supply Current ..........................................................................................334 27.2Idle Supply Current ..............................................................................................337 27.3Supply Current of I/O modules ............................................................................340 27.4Power-down Supply Current ...............................................................................341 27.5Power-save Supply Current ................................................................................342 27.6Standby Supply Current ......................................................................................342 vi 8059D-AVR-11/09 ATmega1284P 27.7Pin Pull-up ...........................................................................................................343 27.8Pin Driver Strength ..............................................................................................346 27.9Pin Threshold and Hysteresis .............................................................................348 27.10BOD Threshold ..................................................................................................351 27.11Internal Oscillator Speed ...................................................................................353 27.12Current Consumption of Peripheral Units ..........................................................355 27.13Current Consumption in Reset and Reset Pulsewidth ......................................358 28 Register Summary ............................................................................... 360 29 Instruction Set Summary .................................................................... 364 30 Ordering Information ........................................................................... 367 30.1ATmega1284P ....................................................................................................367 31 Packaging Information ........................................................................ 368 31.144A ......................................................................................................................368 31.240P6 ....................................................................................................................369 31.344M1 ...................................................................................................................370 32 Errata ..................................................................................................... 371 32.1ATmega1284P Rev. A .........................................................................................371 33 Datasheet Revision History ................................................................ 372 33.1Rev. 8059D - 11/09 .............................................................................................372 33.2Rev. 8059C - 07/09 .............................................................................................372 33.3Rev. 8059B - 05/08 .............................................................................................372 33.4Rev. 8059A - 04/08 .............................................................................................372 vii 8059D-AVR-11/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-enYvelines 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) and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 8059D-AVR-11/09