– 130 Powerful Instructions – Most Single Clock Cycle Execution
– 32x8GeneralPurposeWorkingRegisters
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-chip 2-cycle Multiplier
• Nonvolatile Program and Data Memories
– 8K Bytes of In-System Self-programmable Flash
Endurance: 1,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
– 512 Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
– 512 Bytes Internal SRAM
– Up to 64K Bytes Optional External Memory Space
– Programming Lock for Software Security
• Peripheral Features
– One 8-bit Timer/Counter with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
– Three PWM Channels
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Three Sleep Modes: Idle, Power-down and Standby
OverviewThe ATmega8515 is a low-powerCMOS8-bit microcontrollerbas ed on theAVR
enhanced RISC architecture. By executing powerful instructions in a single clock cycle,
the ATmega8515 achieves throughputs approaching 1 MIPSperMHzallowing the sys-
tem designer to optimize powerconsumption versusprocessing speed.
Block DiagramFigure 2. Block Diagram
VCC
PA0 - PA7PC0 - PC7
PORTA DRIVERS/BUFFERS
PE0 - PE2
PORTE
DRIVERS/
BUFFERS
PORTC DRIVERS/BUFFERS
GND
PORTA DIGITAL INTERFACE
PROGRAM
COUNTER
PROGRAM
FLASH
INSTRUCTION
REGISTER
INSTRUCTION
DECODER
CONTROL
LINES
AVR CPU
PROGRAMMING
LOGIC
STACK
POINTER
SRAM
GENERAL
PURPOSE
REGISTERS
X
Y
Z
ALU
STATUS
REGISTER
SPI
PORTE
DIGITAL
INTERFACE
PORTC DIGITAL INTERFACE
TIMERS/
COUNTERS
INTERNAL
OSCILLATOR
WATCHDOG
TIMER
MCU CTRL.
& TIMING
INTERRUPT
UNIT
EEPROM
USART
OSCILLATOR
INTERNAL
CALIBRATED
OSCILLATOR
XTAL1
XTAL2
RESET
2512A–AVR–04/02
+
-
PORTB DIGITAL INTERFACE
PORTB DRIVERS/BUFFERS
COMP.
INTERFACE
PORTD DIGITAL INTERFACE
PORTD DRIVERS/BUFFERS
PD0 - PD7PB0 - PB7
3
TheAVRcore combines a rich instruction set with32 generalpurpose working registers.
All the 32 registers are directly connected to theArithmeticLogicUnit (ALU), allowing
twoindependent registers to beaccessed in one singleinstruction executed in one clockcycle. The resulting architectureis more codeefficient whileachieving throughputs up to
ten timesfaster than conventionalCISCmicrocontrollers.
The ATmega8515 provides the following features: 8Kbytes ofIn-System Programmable
Flash with Read-While-Write capabilities, 512 bytesEEPROM, 512 bytesSRAM, an
External memory interface,35generalpurpose I/Olines, 32generalpurpose working
registers, two flexibleTimer/Counters withcomparemodes, Internal andExternal inter-
rupts, a Serial Programmable USART, a programmable Watchdog Timerwith internal
Oscillator, a SPIserialport, and three software selectable powersaving modes.The Idlemode stops the CPUwhileallowing the SRAM, Timer/Counters, SPIport, andInterrupt
system to continue functioning. ThePower-downmode saves the Registercontentsbut
freezes the Oscillator, disabling all otherchipfunctions until thenextinterruptorhard-
ware reset. In Standby mode, the crystal/resonatorOscillator isrunning whilethe restofth e deviceissleeping. This allows very fast start -upcombinedwithlow-power
consumption.
The deviceis manufactured using Atmel’shighdensity nonvolatilememory technology.
The On-chipISP Flash allows the program memory to be reprogrammedIn-System
through an SPIserial interface,bya conventional nonvolatilememory programmer, orby an On-chipBoot program running on the AVR core. The boot program can useany
interfacetodownload theapplication program in theApplication Flash memory. Soft-wareinthe Boot Flash section will continue to run whiletheApplication Flash section is
updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPUwithIn-System Self-programmable Flash onamonolithicchip, theAtmel ATmega8515
is a powerful microcontroller that provides a highly flexibleandcosteffective solution to
many embeddedcontrol applications.
The ATmega8515 issupportedwith a full suite ofprogram andsystem development
tools including:CCompilers, Macroassemblers, Program debugger/simulators, In-cir-cuit Emulators, andEvaluation kits.
DisclaimerTypical valuescontained in thisdata sheet are based on simulations andcharacteriza-
tion of other AVR microcontrollers manufactured on the same process technology. Min
andMax valueswill beavailableafter the deviceischaracterized.
AT90S4414/8515 and
ATmega8515
Compatibility
AT90S4414/8515 Compatibility
Mode
The ATmega8515 provides all the features of theAT90S4414/8515. Inaddition,several
newfeature s a readded .The ATmega8515 isba ckward comp atible with
AT90S4414/8515 in most cases. However, some incompatibilitiesbetween thetwo
microcontrollers exist. To solve thisproblem, an AT90S4414/8515 compatibility mode
can be selectedbyprogramming the S8515CFuse. ATmega8515 is 100%pin compatible with AT90S4414/8515, andcan replacetheAT90S4414/8515 on current printed
circuit boards. However, the location ofFuse bits and theelectricalcharacteristics differs between thetwo devices.
Programming the S8515CFuse will change the following functionality:
•Thetimedsequence forchanging the Watchdog Time-out period isdisabled. See
“TimedSequencesforChanging the Configuration of the Watchdog Timer”onpage
50 fordetails.
•The double buffering of the USART receive registers isdisabled. See “AVR USART
vs. AVR UART – Compatibility”onpage 133 fordetails.
•PORTE(2:1)will be set as output, and PORTE0 will be set as input.
4
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
Pin Descriptions
VCCDigitalsupply voltage.
GNDGround.
Port A (PA7..PA0)PortAis an 8-bit bi-directionalI/Oport with internalpull-upresistors (selectedfor each
bit).ThePort A output buffers have symmetricaldrive characteristics withbothhighsink
andsource capability. When pins PA0toPA7 areused as inputs and areexternally
pulledlow, theywill source current if theinternalpull-upresistors areactivated.ThePort
A pins aretri-statedwhen a reset condition becomes active, even if the clock is not
running.
PortAalso serves the functions of variousspecialfeatures of the ATmega8515 aslisted
on page 64.
Port B (PB7..PB0)Port B is an 8-bit bi-directionalI/Oport with internalpull-upresistors (selectedfor each
bit).ThePort B output buffers have symmetricaldrive characteristics withbothhighsinkandsource capability.As inputs, Port Bpins that areexternally pulledlowwill source
current if the pull-upresistors areactivated.ThePort Bpins aretri-statedwhen a reset
condition becomes active, even if the clock is not running.
Port B also serves the functions of variousspecialfeatures of the ATmega8515 aslisted
on page 64.
Port C (PC7..PC0)Port C is an 8-bit bi-directionalI/Oport with internalpull-upresistors (selectedfor each
bit).ThePort C output buffers have symmetricaldrive characteristics withbothhighsinkandsource capability.As inputs, Port Cpins that areexternally pulledlowwill source
current if the pull-upresistors areactivated.ThePort Cpins aretri-statedwhen a reset
condition becomes active, even if the clock is not running.
Port D (PD7..PD0)Port D is an 8-bit bi-directionalI/Oport with internalpull-upresistors (selectedfor each
bit).ThePort D output buffers have symmetricaldrive characteristics withbothhighsinkandsource capability.As inputs, Port Dpins that areexternally pulledlowwill source
current if the pull-upresistors areactivated.ThePort Dpins aretri-statedwhen a reset
condition becomes active, even if the clock is not running.
Port D also serves the functions of variousspecialfeatures of the ATmega8515 aslisted
on page 69.
Port E(PE2..PE0)Port E is an 3-bit bi-directionalI/Oport with internalpull-upresistors (selectedfor each
bit).ThePort E output buffers have symmetricaldrive characteristics withbothhighsinkandsource capability.As inputs, Port Epins that areexternally pulledlowwill source
current if the pull-upresistors areactivated.ThePort Epins aretri-statedwhen a reset
condition becomes active, even if the clock is not running.
Port E also serves the functions of variousspecialfeatures of the ATmega8515 aslisted
on page 71.
RESET
XTA L1Input to theinverting Oscillator amplifier and input to theinternalclock operating circuit.
XTA L2Output from theinverting Oscillator amplifier.
2512A–AVR–04/02
Reset input. A lowlevel on thispin forlonger than the minimum pulse lengthwill gener-
ate a reset, even if the clock is not running. Theminimumpulse length is given in Table
18 on page 43. Shorterpulses are not guaranteed to generate a reset.
5
About Code
Examples
Thisdocumentation containssimple codeexamples that briefly showhow to usevarious
parts of the device. These codeexamples assume that the part specificheaderfileis
includedbefore compilation. Beawarethat not all C Compiler vendors include bit defini-
tions in the headerfiles and interrupt handling in C iscompilerdependent. Pleaseconfirm with the CCompilerdocumentation for more details.
AVR CPU Cor e
IntroductionThissection discusses the AVR corearchitectureingeneral.Themainfunction of the
CPUcoreis to ensure correct program execution. The CPU musttherefore beableto
access memories, perform calculations, controlperipherals, andhandleinterrupts.
Architectural OverviewFigure 3. Block Diagram of theAVRArchitecture
Data Bus 8-bit
Flash
Program
Memory
Instruction
Register
Instruction
Decoder
Control Lines
Program
Counter
Direct Addressing
Indirect Addressing
Status
and Control
32x8
General
Purpose
Registrers
ALU
Data
SRAM
EEPROM
Interrupt
Unit
SPI
Unit
Watchdog
Timer
Analog
Comparator
I/O Module1
I/O Module 2
I/O Module n
I/O Lines
Inorder to maximize performanceandparallelism, the AVR uses a Harvard architecture
– withseparate memories andbusesforprogram anddata. Instructions in the program
memory areexecutedwith a single levelpipelining. Whileoneinstruction isbeing exe-cuted, thenextinstruction ispre-fetchedfrom the program memory.Thisconcept
enables instructions to beexecuted in every clock cycle. The program memory isIn-System reprogrammable Flash memory.
6
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
The fast-access RegisterFile contains32 x 8-bit generalpurpose working registers with
a single clock cycleaccess time. This allows single-cycleArithmeticLogicUnit (ALU)
operation. Inatypical ALU operation, twooperands areoutput from theRegisterFile,
theoperation is executed, and the resultisstoredback in the RegisterFile – in one
clock cycle.
Six of the 32 registers can beused as three 16-bit indirectaddress registerpointers for
Data Spaceaddressing – enabling efficient address calculations. One of thethese
address pointers can also beused as an address pointerforlook up tables in Flash pro-
gram memory.Theseaddedfunction registers arethe16-bit X-, Y-, andZ-register,describedlater in thissection.
TheALU supports arithmetic andlogic operationsbetween registers orbetween a con-stant and a register. Single register operationscan also beexecuted in theALU.After
an arithmetic operation, the Status Register is updated to reflectinformation about theresultof theoperation.
Program flow isprovidedbyconditional and unconditionaljump andcall instructions,
abletodirectly address the wholeaddress space. Most AVR instructionshave a single
16-bit word format. Every program memory address contains a16- or32-bit instruction.
Program Flash memory spaceisdivided in two sections, the Boot Program section and
theApplication Program section. Bothsectionshave dedicatedLock bitsforwrite and
read/write protection. The SPM instruction that writes into theApplication Flash memory
section must resideinthe Boot Program section.
ALU – Arithmetic Logic
Unit
During interrupts andsubroutine calls, the returnaddress program counter(PC) is
stored on the Stack.The Stack is effectively allocated in thegeneraldata SRAM, and
consequently the stack sizeis only limitedbythetotalSRAMsizeand theusage of the
SRAM.All userprograms mustinitializethe SPinthe reset routine (before subroutinesor interrupts areexecuted).The Stack PointerSPisread/write accessibleinthe I/O
space. The data SRAMcan easily beaccessed through the five different addressing
modessupported in the AVR architecture.
Thememory spaces in theAVRarchitectureareall linear andregular memory maps.
A flexibleinterruptmodule has itscontrolregisters in the I/Ospace with an additionalGlobalInterrupt Enable bit in the Status Register.All interruptshave a separate interrupt
vector in the InterruptVector table. Theinterruptshave priority in accordance with theirInterruptVectorposition. The lower the InterruptVector address, the higher the priority.
The I/O memory space contains64addressesforCPUperipheralfunctions asControl
Registers, SPI, and otherI/Ofunctions.The I/OMemory can beaccesseddirectly, or as
the Data Space locationsfollowing thoseof the RegisterFile,$20 -$5F.
The high-performance AVR ALU operates in direct connection with all the 32generalpurpose working registers. Within a single clock cycle, arithmetic operationsbetween
generalpurpose registers orbetween a register and an immediate areexecuted.The
ALU operations are divided into three main categories –arithmetic, logical, andbit-func-
tions. Some implementations of thearchitecturealso provideapowerful multipliersupporting bothsigned/unsigned multiplication andfractionalformat. See the“Instruc-
tion Set” section for a detaileddescription.
2512A–AVR–04/02
7
Status RegisterThe Status Registercontains information about the resultof themost recently executed
arithmetic instruction. This information can beusedfor altering program flow in order to
perform conditional operations. Note that the statusregister is updated after all ALUoperations, asspecified in the Instruction Set Reference. Thiswill in manycases
remove theneedfor using the dedicatedcompareinstructions, resulting in faster and
more compact code.
The statusregister is not automatically storedwhen enteringaninterrupt routine andrestoredwhen returning from an interrupt. This must be handledbysoftware.
TheAVRstatusregister – SREG –isdefined as:
Bit76543210
I THSVNZCSREG
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7 – I: Global Interrupt Enable
The GlobalInterrupt Enable bit must be set for theinterrupts to be enabled.Theindivid-
ual interrupt enable control is then performed in separate controlregisters. If theglobal
interruptenable register iscleared, none of theinterrupts areenabled independent of
theindividual interrupt enable settings.The I-bit isclearedbyhardwareafter an interrupt
has occurred, and isset by theRETI instruction to enable subsequent interrupts.The I-
bit can also be set andclearedbytheapplication with the SEI andCLIinstructions, as
described in theinstruction set reference.
• Bit 6 – T: Bit Copy Storage
The Bit Copy instructionsBLD(Bit LoaD) andBST (Bit STore) usetheT-bit assourceor
destination for theoperatedbit. A bit from a register in theRegisterFile can be copied
into T by the BSTinstruction, and a bit in T can be copied into a bit in a register in the
RegisterFile 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” fordetailed information.
• Bit 4 – S: Sign Bit, S = N
⊕ V
The S-bit is always an exclusive orbetween the negative flag N and thetwo’scomple-
ment overflowflag V. See the“Instruction Set Description” fordetailed information.
• Bit 3 – V: Two’s Complement Overflow Flag
TheTwo’sComplement OverflowFlag V supports two’scomplement arithmetics. See
the“Instruction Set Description” fordetailed information.
• Bit 2 – N: Negative Flag
The Negative Flag N indicates a negative resultinanarithmetic orlogic operation. See
the“Instruction Set Description” fordetailed information.
•Bit1–Z: Zero Flag
The Zero Flag Z indicates a zero resultinanarithmetic orlogic operation. See the
“Instruction Set Description” fordetailed information.
8
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
• Bit0–C:CarryFlag
The Carry Flag C indicates a carry in an arithmetic orlogic operation. See the“Instruc-
tion Set Description” fordetailed information.
General Purpose
Register File
TheRegisterFileis optimizedfor the AVR Enhanced RISC instruction set. Inorder to
achieve the requiredperformanceandflexibility, the following input/output schemes aresupportedbythe RegisterFile:
•One 8-bit output operand and one 8-bit resultinput
•Two8-bit output operands and one 8-bit resultinput
•Two8-bit output operands and one 16-bit resultinput
•One 16-bit output operand and one 16-bit resultinput
Figure4shows the structureof the 32 generalpurpose working registers in the CPU.
Figure 4. AVR CPUGeneral Purpose Working Registers
70Addr.
R0$00
R1$01
R2$02
…
R13$0D
GeneralR14$0E
PurposeR15$0F
WorkingR16$10
RegistersR17$11
…
R26$1AX-registerLowByte
R27$1BX-registerHighByte
R28$1CY-registerLowByte
R29$1DY-registerHighByte
R30$1EZ-registerLowByte
R31$1FZ-registerHighByte
2512A–AVR–04/02
Mostof theinstructions operatingonthe RegisterFile have directaccess to all registers,
and mostof them are single cycleinstructions.
AsshowninFigure4, each register is alsoassigned a data memory address, mapping
them directly into the first 32 locations of theuserData Space. Although not being phys-
ically implemented asSRAMloc ations, this memory organization provides greatflexibility in access of the registers, as the X-, Y-, andZ-pointer Registers can be set to
index anyregister in the file.
9
The X-register, Y-register, and
Z-register
The registers R26..R31 have some addedfunctions to their generalpurposeusage.
These registers are16-bit address pointers for indirectaddressing of the Data Space.
Thethree indirectaddress registers X, Y, andZare defined asdescribed in Figure5.
Figure 5. The X-, Y-, andZ-registers
15XHXL0
X-register7070
R27($1B)R26($1A)
15YHYL0
Y-register7070
R29($1D)R28 ($1C)
15ZHZL0
Z-register7070
R31 ($1F)R30 ($1E)
Inthe different addressing modes theseaddress registers have functions asfixeddis-
placement, automatic increment, and automaticdecrement (see the Instruction Set
reference fordetails).
Stack PointerThe Stack is mainly usedforstoring temporary data,forstoring local variables andfor
storing returnaddresses after interrupts andsubroutine calls.The Stack Pointer Regis-ter always points to thetop 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 commanddecreases the Stack Pointer.
The Stack Pointerpoints to the data SRAMstack area wherethe Subroutine andInter-
rupt Stacks are located.ThisStack spaceinthe data SRAM must be definedbythe
program beforeanysubroutine calls areexecuted or interrupts areenabled.The StackPointer must be set to point above $60. The Stack Pointer isdecrementedbyone when
data ispushed onto the Stack with thePUSH instruction, and it isdecrementedbytwo
when the returnaddress ispushed onto the Stack withsubroutine call or interrupt. The
Stack Pointer is incrementedbyone when data ispoppedfrom the Stack with thePOPinstruction, and it is incrementedbytwo when address ispoppedfrom the Stack with
return from subroutine RETorreturn from interruptRETI.
The AVR Stack Pointer is implemented as two8-bit registers in the I/Ospace. The num-
ber ofbits actually used is implementation dependent. Note that the data spaceinsomeimplementations of theAVRarchitectureisso small that only SPL is needed. Inthis
case, the SPH Registerwill not be present.
Bit15141312111098
SP15SP14SP13SP12SP11SP10SP9SP8SPH
SP7SP6SP5SP4SP3SP2SP1SP0SPL
76543210
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
R/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
00000000
10
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
Instruction Execution
Timing
Thissection describes the general access timing conceptsfor instruction execution. The
AVR CPU isdriven by the CPUclock clk
,directly generatedfrom the selectedclock
CPU
source for the chip. Nointernalclock division is used.
Figure 6shows the parallel instruction fetches and instruction executions enabledbythe
Harvard architectureand the fast-access Registerfile concept. This is the basicpipelin-ing concepttoobtain up to 1 MIPSperMHzwith the corresponding unique resultsfor
functionspercost,functionsperclocks, andfunctionsperpower-unit.
Figure 7shows theinternal timing concept for the Registerfile. Inasingle clock cyclean
ALU operation using two register operands is executed, and the resultisstoredback to
the destination register.
Reset and Interrupt
Handling
Figure 7. Single CycleALU Operation
T1T2T3T4
clk
CPU
Total Execution Time
Register Operands Fetch
ALU Operation Execute
Result Write Back
The AVR providesseveraldifferent interrupt sources.Theseinterrupts and the separate
Reset Vector each have a separate program vector in the program memory space. All
interrupts areassigned individual enable bitswhich must be written logic one together
with the GlobalInterrupt Enable bit in the Status Register in order to enabletheinterrupt.
Dependingonthe program counter value, interrupts maybe automatically disabled
when Boot Lock bitsBLB02 orBLB12 are programmed.Thisfeatureimprovessoftware
security. See the section “Memory Programming” on page 175 fordetails.
The lowestaddresses in the program memory spaceare by default defined as theReset
andInterruptVectors.The complete listof vectors isshownin“Interrupts”onpage 51.
The listalso determines the prioritylevels of the different interrupts.The lower the
address the higher is the prioritylevel.RESET has the highest priority, and nextisINT0
–the ExternalInterruptRequest0.The InterruptVectors can bemoved to the startof
the Boot Flash section by setting the IVSEL bit in the GeneralInterrupt Control Register(GICR).Refer to “Interrupts”onpage 51 for moreinformation. TheReset Vectorcan
2512A–AVR–04/02
11
also bemoved to the startof the Boot Flash section by programming the BOOTRST
Fuse,see “Boot LoaderSupport–Read-While-Write Self-Programming” on page 162.
When an interruptoccurs, the GlobalInterrupt Enable I-bit iscleared and all interruptsare disabled.Theusersoftware can write logic one to the I-bit to enablenested inter-
rupts.All enabled interruptscan then interruptthe current interrupt routine. The I-bit is
automatically set whenaReturn from Interruptinstruction – RETI –is executed.
Thereare basically twotypes of interrupts.The firsttypeis triggeredbyan event thatsets theinterrupt flag. For theseinterrupts, theProgram Counter is vectored to the
actualInterruptVector in order to execute theinterrupt handling routine, andhardware
clears the corresponding interrupt flag. Interrupt flagscan also be clearedbywriting a
logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs whilethe
corresponding Interrupt Enable bit iscleared, theinterrupt flag will be set andremembered until theinterruptis enabled, or the flag isclearedbysoftware. Similarly, if one or
moreinterrupt conditions occurwhilethe GlobalInterrupt Enable bit iscleared, the corresponding interrupt flag(s) will be set andremembered until the GlobalInterrupt Enable
bit isset, andwill then beexecutedbyorder ofpriority.
The second typeof interruptswill trigger aslong as theinterrupt condition ispresent.
Theseinterruptsdo not necessarily have interrupt flags. If theinterrupt condition disap-
pears beforetheinterruptis enabled, theinterrupt will not betriggered.
When the AVR exitsfrom an interrupt, it will always returntothemainprogram and exe-
cute one moreinstruction beforeanypending interruptisserved.
Note that the Status Register is not automatically storedwhen enteringaninterrupt rou-tine, norrestoredwhen returning from an interrupt routine. This must be handledby
software.
When using the CLI instruction to disableinterrupts, theinterruptswill be immediately
disabled. Nointerrupt will beexecuted after the CLI instruction, even if it occurs simulta-
neously with the CLI instruction. The following example shows how thiscan beused to
avoid interruptsduring thetimedEEPROM write sequence..
Assembly Code Example
in r16, SREG
cli; disable interrupts during timed sequence
sbi EECR, EEMWE
sbi EECR, EEWE
out SREG, r16
; store SREG value
; start EEPROM write
; restore SREG value (I-bit)
CCode Example
char cSREG;
cSREG = SREG;
/*
disable interrupts during timed sequence */
_CLI();
EECR |= (1<<EEMWE);
EECR |= (1<<EEWE);
SREG = cSREG;
/* store SREG value */
/* start EEPROM write */
/* restore SREG value (I-bit) */
12
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
When using the SEI instruction to enableinterrupts, theinstruction following SEI will be
executedbeforeanypending interrupts, asshowninthis example.
Assembly Code Example
sei
; set global interrupt enable
sleep
; enter sleep, waiting for interrupt
; note: will enter sleep before any pending
; interrupt(s)
CCode Example
_SEI();
_SLEEP();
/* note: will enter sleep before any pending interrupt(s) */
Interrupt Response TimeTheinterruptexecution response for all theenabled AVR interrupts isfourclock cycles
minimum. Afterfourclock cycles theProgram Vector address for theactual interrupt
handling routine is executed. During thisfourclock cycle period, theProgram Counter is
pushed onto the Stack.TheVector is normally a jump to theinterrupt routine, and this
jump takes three clock cycles. If an interruptoccurs during execution of amulti-cycle
instruction, this instruction iscompletedbeforetheinterruptisserved. If an interrupt
occurs when the MCU is in sleep mode, theinterruptexecution responsetimeis
increasedbyfourclock cycles.This increase comes in addition to the start-up time from
the selectedsleep mode.
/* set global interrupt enable */
/* enter sleep, waiting for interrupt */
A return from an interrupt handling routine takesfourclock cycles. During these four
clock cycles, theProgram Counter(two bytes) ispoppedback from the Stack, the Stack
Pointer is incrementedbytwo, and the I-bit in SREG isset.
2512A–AVR–04/02
13
AVR ATmega8515
Memories
Thissection describes the different memories in the ATmega8515. The AVR architec-
ture has twomainmemory spaces, the Data Memory and theProgram Memory space.Inaddition, the ATmega8515 features an EEPROM Memory fordata storage. All three
memory spaces are linear andregular.
In-System
Reprogrammable Flash
Program Memory
The ATmega8515 contains 8KbytesOn-chipIn-System Reprogrammable Flash memory forprogram storage. Sinceall AVR instructions are16 or32 bitswide, the Flash is
organized as 4Kx16. Forsoftware security, the Flash Program memory spaceis
divided into two sections, Boot Program section and Application Program section.
The Flash memory has an enduranceof at least1,000 write/erase cycles.Th e
ATmega8515 Program Counter(PC) is 12 bitswide, thus addressing the4Kprogram
memory locations.Theoperation ofBoot Program section and associatedBoot Lock
bitsforsoftware protection are described in detail in “Boot LoaderSupport–Read-
While-Write Self-Programming” on page 162. “Memory Programming” on page 175 con-tains a detaileddescription on Flash data serialdownloading using the SPIpins.
Constant tablescan beallocatedwithin the entireProgram memory address space,see
the LPM – Load Program Memory instruction description.
Timing diagramsfor instruction fetch and execution are presented in “Instruction Execu-
tion Timing” on page 11.
Figure 8. Program Memory Map
$000
Application Flash Section
Boot Flash Section
$FFF
14
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
SRAM Data MemoryFigure 9shows how the ATmega8515 SRAMMemory is organized.
The lower608 Data Memory locations address theRegisterFile, the I/OMemory, and
theinternaldata SRAM.The first 96 locations address the RegisterFileandI/OMemory, and thenext 512 locations address theinternaldata SRAM.
An optional externaldata SRAMcan beusedwith the ATmega8515. ThisSRAMwill
occupy an area in the remaining address locations in the 64K address space. This area
starts at theaddress following theinternalSRAM.TheRegisterfile,I/O, ExtendedI/O
andInternalSRAM occupies the lowest 608 bytes in normal mode,so when using 64KB(65536 bytes) ofExternalMemory, 64928 Bytes ofExternalMemory areavailable. See
“ExternalMemory Interface” on page 22 fordetails on how to takeadvantage of the
external memory map.
When theaddresses accessing the SRAM memory spaceexceeds theinternaldata
memory locations, theexternaldata SRAM is accessed using the same instructions asfor theinternaldata memory access. When theinternaldata memories areaccessed,
the read andwrite strobe pins(PD7 and PD6) areinactive during the wholeaccess
cycle. ExternalSRAM operation is enabledbysetting the SREbit in the MCUCR
register.
Accessing externalSRAM takes one additionalclock cycle perbyte compared to access
of theinternalSRAM.This means that the commands LD, ST,LDS,STS, LDD, STD,
PUSH, and POPtakeoneadditionalclock cycle. If the Stack isplaced in external
SRAM, interrupts, subroutine calls andreturns takethree clock cycles extra becausethe
two-byte program counter ispushed andpopped, and external memory access does not
takeadvantage of theinternalpipe-line memory access. When externalSRAM interface
is usedwithwait-state, one-byte external access takes two, three, orfour additional
clock cyclesfor one, two, and three wait-statesrespectively. Interrupts, subroutine calls
andreturnswill needfive,seven, or nine clock cycles morethan specified in theinstruction set manualfor one, two, and three wait-states.
The five different addressing modesfor the data memory cover: Direct,Indirect withDisplacement,Indirect,Indirect with Pre-decrement, andIndirect with Post-increment. In
the Registerfile,registers R26 to R31 featuretheindirectaddressing pointerregisters.
The directaddressing reaches theentire data space.
The Indirect withDisplacement mode reaches63address locationsfrom the base
address given by the Y- orZ-register.
When using register indirectaddressing modeswith automaticpre-decrement andpost-
increment, theaddress registers X, Y, andZare decremented or incremented.
The 32 generalpurpose working registers, 64 I/Oregisters, and the 512 bytes of internaldata SRAM in the ATmega8515 areall accessiblethrough all theseaddressing modes.
The Registerfileisdescribed in “General Purpose RegisterFile” on page 9.
2512A–AVR–04/02
15
Figure 9. Data Memory Map
Data Memory
32 Registers
64 I/O Registers
Internal SRAM
(512 x 8)
External SRAM
(0 - 64K x 8)
$0000 - $001F
$0020 - $005F
$0060
$025F
$0260
$FFFF
Data Memory Access TimesThissection describes the general access timing conceptsfor internal memory access.
Theinternaldata SRAM access isperformed in two clk
cycles asdescribed in Figure
CPU
10.
Figure 10. On-chipData SRAM Access Cycles
T1T2T3
clk
CPU
Address
Compute Address
Address Valid
Data
WR
Write
Data
RD
Memory Access Instruction
Next Instruction
Read
16
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
EEPROM Data MemoryThe ATmega8515 contains 512 bytes ofdata EEPROM memory. Itis organized as a
separate data space, in which single bytescan be read andwritten. The EEPROM has
an enduranceof at least100,000 write/erase cycles.Theaccess between the EEPROM
and the CPU isdescribed in the following,specifying the EEPROM Address Registers,
the EEPROM Data Register, and the EEPROM Control Register.
For a detaileddescription ofSPIdata downloading to the EEPROM, see page 189.
The write access time for the EEPROM is given in Table1.Aself-timing function,how-
ever, lets theusersoftware detect when thenext byte can be written. If theusercode
contains instructions that write the EEPROM, some precautions must betaken. In
heavily filteredpowersupplies, V
causes the device forsome period of time to run at a voltage lower than specified as
minimum for the clock frequency used. See “Preventing EEPROM Corruption” on page
21. fordetails on how to avoidproblems in these situations.
Inorder to prevent unintentionalEEPROM writes, a specificwrite proceduremust be fol-
lowed.Refer to the description of the EEPROM Control Registerfordetails on this.
When the EEPROM isread, the CPU ishaltedforfourclock cyclesbeforethenext
instruction is executed. When the EEPROM iswritten, the CPU ishaltedfor two clock
cyclesbeforethenextinstruction is executed.
islikely to riseorfall slowly on Power-up/down. This
CC
The EEPROM Address
Register – EEARH and EEARL
The EEPROM Data Register –
EEDR
Bit15141312111098
–––––––EEAR8EEARH
EEAR7EEAR6EEAR5EEAR4EEAR3EEAR2EEAR1EEAR0EEARL
76543210
Read/WriteRRRRRRRR/W
R/WR/WR/WR/WR/WR/WR/WR/W
Initial Value0000000X
XXXXXXXX
• Bits 15..9 – Res: Reserved Bits
These bits are reservedbits in the ATmega8515 andwill always read aszero.
• Bits 8..0 – EEAR8..0: EEPROM Address
The EEPROM Address Registers – EEARH andEEARL – specify the EEPROM
address in the512bytesEEPROM space. The EEPROM data bytes areaddressedlin-
early between0and 511. Theinitial value ofEEAR is undefined.Aproper value must be
written beforethe EEPROM maybeaccessed.
Bit76543210
MSBLSBEEDR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
2512A–AVR–04/02
• Bits 7..0 – EEDR7.0: EEPROM Data
For the EEPROM write operation, the EEDR Registercontains the data to be written to
the EEPROM in theaddress given by the EEAR Register. For the EEPROM read oper-
ation, the EEDR contains the data read out from the EEPROM at theaddress given byEEAR.
17
The EEPROM Control Register
–EECR
Bit76543210
––––EERIEEEMWEEEWEEEREEECR
Read/WriteRRRRR/WR/WR/WR/W
Initial Value00000 0X0
• Bits 7..4 – Res: Reserved Bits
These bits are reservedbits in the ATmega8515 andwill always read aszero.
• Bit 3 – EERIE: EEPROM Ready Interrupt Enable
Writing EERIE to one enables the EEPROM Ready Interruptif the I-bit in SREG isset.
Writing EERIE to zero disables theinterrupt. The EEPROM Ready interrupt generates a
constant interrupt when EEWE iscleared.
• Bit 2 – EEMWE: EEPROM Master Write Enable
The EEMWE bit determineswhethersetting EEWE to one causes the EEPROM to be
written. When EEMWE isset,setting EEWE within fourclock cycleswill write data to the
EEPROM at the selected address If EEMWE iszero,setting EEWE will have no effect.
When EEMWE hasbeen written to one by software,hardware clears the bit to zeroafter
fourclock cycles. See the description of the EEWE bit for an EEPROM write procedure.
• Bit 1 – EEWE: EEPROM Write Enable
The EEPROM Write Enable SignalEEWEis the write strobetothe EEPROM. When
address anddata are correctly set up, the EEWE bit must be written to one to write the
value into the EEPROM.The EEMWE bit must be written to one beforealogical one is
written to EEWE, otherwisenoEEPROM write takesplace. The following procedure
should be followedwhen writing the EEPROM (theorder ofsteps 3 and 4is not
essential):
1. Wait untilEEWEbecomeszero.
2. Wait untilSPMEN in SPMCR becomeszero.
3. Write newEEPROM address to EEAR (optional).
4. Write newEEPROM data to EEDR (optional).
5. Write a logical one to the EEMWE bit while writing a zerotoEEWE in EECR.
6. Within fourclock cycles aftersetting EEMWE, write a logical one to EEWE.
18
The EEPROM can not be programmedduring a CPUwritetothe Flash memory.The
softwaremust check that the Flash programming iscompletedbefore initiating a new
EEPROM write. Step 2is only relevant if the software contains a Boot Loader allowing
the CPU to program the Flash. If the Flash is neverbeing updatedbythe CPU, step 2
can be omitted. See “Boot LoaderSupport–Read-While-Write Self-Programming” on
page 162 fordetails about boot programming.
Caution: An interrupt between step 5andstep6will makethe write cycle fail, sincethe
EEPROM MasterWrite Enable will time-out. If an interrupt routine accessing the
EEPROM is interrupting anotherEEPROM access, the EEAR or EEDR Registerwill be
modified, causing theinterruptedEEPROM access to fail. Itisrecommended to have
theglobal interrupt flag clearedduring all the steps to avoid these problems.
When the write access time has elapsed, the EEWE bit isclearedbyhardware. The
usersoftware can poll thisbit andwait for a zero before writing thenext byte. WhenEEWE hasbeen set, the CPU ishaltedfor two cyclesbeforethenextinstruction is
executed.
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
• Bit 0 – EERE: EEPROM Read Enable
The EEPROM ReadEnable SignalEERE is the readstrobetothe EEPROM. When the
correctaddress isset up in the EEAR Register, the EEREbit must be written to a logic
one to trigger the EEPROM read.The EEPROM read access takes one instruction, and
the requesteddata is availableimmediately. When the EEPROM isread, the CPU ishaltedforfourcyclesbeforethenextinstruction is executed.
Theusershould poll the EEWE bit before starting the read operation. If a write operation
is in progress, it is neitherpossibletoread the EEPROM, nor to change the EEAR
Register.
The calibratedOscillator is used to time the EEPROM accesses.Table1lists thetypicalprogramming time forEEPROM access from the CPU.
Table 1. EEPROM Programming Time
Number of Calibrated RC
Symbol
EEPROM Write (from CPU)84488.5 ms
Note:1. Uses 1 MHz clock, independent of CKSEL Fuse settings.
Oscillator Cycles
(1)
Typ Programming Time
2512A–AVR–04/02
19
The following codeexamplesshow one assembly and one Cfunction forwriting to the
EEPROM.Theexamples assume that interrupts are controlled(e.g.,bydisabling inter-
rupts globally) sothat no interruptswill occurduring execution of these functions.Theexamples alsoassume that no Flash Boot Loader ispresent in the software. If such
codeispresent, the EEPROM write function mustalso wait for any ongoing SPMcom-
mand to finish.
Assembly Code Example
EEPROM_write:
; Wait for completion of previous write
sbic EECR,EEWE
rjmp EEPROM_write
; Set up address (r18:r17) in address register
out EEARH, r18
out EEARL, r17
; Write data (r16) to data register
out EEDR,r16
; Write logical one to EEMWE
sbi EECR,EEMWE
; Start eeprom write by setting EEWE
sbi EECR,EEWE
ret
CCode Example
void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
Wait for completion of previous write
/*
while(EECR & (1<<EEWE))
;
/* Set up address and data registers */
EEAR = uiAddress;
EEDR = ucData;
Write logical one to EEMWE */
/*
EECR |= (1<<EEMWE);
/* Start eeprom write by setting EEWE */
EECR |= (1<<EEWE);
}
*/
20
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
Thenext codeexamplesshow assembly andCfunctionsforreading the EEPROM.The
examples assume that interrupts are controlledsothat no interruptswill occurduring
execution of these functions.
Assembly Code Example
EEPROM_read:
; Wait for completion of previous write
sbic EECR,EEWE
rjmp EEPROM_read
; Set up address (r18:r17) in address register
out EEARH, r18
out EEARL, r17
; Start eeprom read by writing EERE
sbi EECR,EERE
; Read data from data register
inr16,EEDR
ret
CCode Example
unsigned char EEPROM_read(unsigned int uiAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEWE))
;
/* Set up address register */
EEAR = uiAddress;
Start eeprom read by writing EERE */
/*
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
Preventing EEPROM
Corruption
2512A–AVR–04/02
During periods oflow V
, the EEPROM data can be corruptedbecausethe supply volt-
CC
age is too lowfor the CPU and the EEPROM to operate properly.Theseissues arethe
same asforboard levelsystems using EEPROM, and the same design solutionsshould
beapplied.
An EEPROM data corruption can be causedbytwo situationswhen thevoltage is too
low. First, a regularwrite sequencetothe EEPROM requires aminimumvoltage to
operate correctly. Secondly, the CPU itself can execute instructions incorrectly, if the
supply voltage is too low.
EEPROM data c o rruption c an easi ly beavoid edbyfo llo wing th isdes ign
recommendation:
Keep the AVR RESETactive (low) during periods of insufficient powersupply volt-age. Thiscan be done by enabling theinternalBrown-out Detector(BOD). If the
detection level of theinternalBODdoes not match theneededdetection level, an
externallow V
Reset Protection circuit can beused. If aReset occurs whilea
CC
write operation is in progress, the write operation will be completedprovided that the
powersupply voltage issufficient.
21
I/O MemoryThe I/Ospace definition of the ATmega8515 isshown in “RegisterSummary”onpage
209.
All ATmega8515 I/Os andperipherals are placed in the I/Ospace. The I/Olocations are
accessedbythe IN andOUTinstructions, transferring data between the 32 generalpur-
pose working registers and the I/Ospace. I/O Registers within theaddress range $00 -
$1F are directly bit-accessibleusing the SBI andCBIinstructions. Inthese registers, the
value ofsingle bitscan be checkedbyusing the SBIS andSBICinstructions.Refer to
theinstruction set section for more details. When using the I/Ospecificcommands IN
andOUT, the I/O addresses$00 -$3Fmust beused. When addressing I/O Registers as
data spaceusing LD andSTinstructions, $20 must beadded to theseaddresses.
Forcompatibilitywithfuture devices, reservedbitsshould be written to zeroif accessed.ReservedI/O memory addressesshould neverbe written.
Some of the statusflags are clearedbywriting a logical one to them. Note that the CBI
and SBI instructionswill operate on all bits in the I/O Register, writing a one back into
anyflag read asset, thusclearing the flag. The CBI andSBIinstructionswork withreg-
isters $00 to $1F only.
The I/O andperipherals controlregisters areexplained in latersections.
External Memory
Interface
OverviewWhen theeXternalMEMory (XMEM) is enabled, address space outsidetheinternal
With all the features the ExternalMemory Interface provides, it iswell suited to operate
as an interfacetomemory devicessuch as externalSRAM andFlash, andperipheralssuch as LCD-display, A/D, andD/A. Themainfeatures are:
•
Four Different Wait State Settings (Including No wait State)
• Independent Wait State Setting for Different External Memory Sectors (Configurable
Sector Size)
• The Number of Bits Dedicated to Address High Byte is Selectable
• Bus Keepers on Data Lines to Minimize Current Consumption (Optional)
SRAMbecomes availableusing the dedicated external memory pins(see Figure1on
page 2, Table26 on page 63, Table 32onpage 67, and Table 38onpage 71).Thememory configuration isshowninFigure11.
22
ATmega8515(L)
2512A–AVR–04/02
Figure 11. ExternalMemory withSectorSelect
Internal Memory
Lower Sector
SRW01
SRW00
ATmega8515(L)
0x0000
0x25F
0x260
SRL[2..0]
Using the External Memory
Interface
External Memory
(0-64K x 8)
Theinterface consists of:
•AD7:0:Multiplexedlow-order address bus anddata bus
•A15:8:High-order address bus(configurable number ofbits)
•ALE: Address latch enable
•RD
•WR
The controlbitsfor the ExternalMemory Interfaceare located in three registers, the
MCU Control Register – MCUCR, the ExtendedMCUControl Register – EMCUCR, and
the SpecialFunction IO Register – SFIOR.
: Readstrobe
:Write strobe
Upper Sector
SRW11
SRW10
0xFFFF
2512A–AVR–04/02
When the XMEM interfaceis enabled, it will overridethe settings in the data direction
registers correspondingtothe portsdedicated to theinterface. Fordetails about thisportoverride,see thealternate functions in section “I/O Ports”onpage 56.The XMEM inter-
face will auto-detect whether an access is internal or external. If theaccess is external,
the XMEM interface will output address, data, and the controlsignals on the ports
according to Figure13(thisfigure shows the wave formswithout wait states). When
ALE goesfrom high to low, thereis avalid address on AD7:0. ALE islowduring a data
transfer. When the XMEM interfaceis enabled, alsoaninternal access will causeactivity on address-, data-, and ALE ports, but theRD
internal access. When the ExternalMemory Interfaceisdisabled, thenormalpin and
andWR strobeswill not toggle during
23
data direction settings areused. Note that when the XMEM interfaceisdisabled, the
address spaceabove theinternalSRAMboundary is not mapped into theinternal
SRAM. Figure12illustrateshow to connectanexternalSRAM to the AVR using an octal
latch (typically “74x573”or equivalent)which is transparent when G ishigh.
Address Latch RequirementsDue to the high-speed operation of the XRAM interface, theaddress latch must be
selectedwithcare for system frequencies above 8 MHz @ 4V and 4 MHz @ 2.7V.
When operating at conditions above these frequencies, thetypical old style 74HC series
latch becomes inadequate. Theexternal memory interfaceisdesigned in complianceto
the 74AHC serieslatch. However, most latchescan beused aslong theycomply with
themaintimingparameters.Themainparameters for theaddress latch are:
•D to Qpropagation delay(t
•Data setup time before Glow(t
•Data (address) hold time afterGlow(
Theexternal memory interfaceisdesigned to guaranty minimum address hold time afterG is assertedlow of t
201).The D to Qpropagation delay(t
ing theaccess time requirement of theexternalcomponent. The data setup time before
Glow(t
(dependent on the capacitive load).
Figure 12. ExternalSRAMConnected to the AVR
) mustnotexceed address valid to ALE low(t
su
= 5ns(refer to t
h
pd
)
)
su
)
th
LAXX_LD/tLLAXX_ST
) must betaken into consideration when calculat-
pd
in Table 99 to Table106 on page
) minus PCB wiring delay
AVLLC
D[7:0]
AD7:0
ALE
DQ
G
A[7:0]
SRAM
AVR
A15:8
RD
WR
Pull-up and Bus KeeperThe pull-upresistors on theAD7:0 ports maybeactivated if the corresponding Port reg-
ister iswritten to one. To reduce powerconsumption in sleep mode, it isrecommended
to disablethe pull-ups by writing thePort register to zero before entering sleep.
The XMEM interfacealso provides a buskeeper on theAD7:0 lines.The buskeeper
can be disabled and enabled in softwareasdescribed in “SpecialFunction IO Register –
SFIOR” on page 29. When enabled, the buskeeperwill keep the previous value on the
AD7:0 buswhilethese lines aretri-statedbythe XMEM interface.
If neitherbus-keeper norpull-ups are enabled, the XMEM interface will leave theAD7:0tri-statedduring a read access until thenextRAM access (internal or external) appears.
A[15:8]
RD
WR
TimingExternal memory deviceshave various timing requirements. To meet these require-
ments, the ATmega8515 XMEM interface providesfourdifferent wait states asshownin
Table 3. Itis important to consider thetimingspecification of theexternal memorydevice before selecting the wait state. Themostimportant parameters aretheaccess
24
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
time for theexternal memory in conjunction with the set-upreq uirement of the
ATmega8515. Theaccess time for theexternal memory isdefined to bethetimefrom
receiving the chipselect/address until the data of this address actually isdriven on the
bus.Theaccess time cannot exceed thetimefrom theALE pulseis assertedlow until
data must be stable during a readsequence (t
106 on page 201).The different wait states are set up in software. As an additionalfeature, it ispossibletodividetheexternal memory spaceintwo sectors with individualwait
state settings.This makes it possibletoconnecttwo different memory deviceswithdif-
ferent timing requirements to the same XMEM interface. ForXMEMinterface timing
details, please refer to Figure89 to Figure 92, and Table 99 to Table106.
Note that the XMEM interfaceis asynchronous and that the waveforms in the figures
below are related to theinternal system clock.The skewbetween the Internal andExter-
nalclock (XTAL1) is not guaranteed(it variesbetween devices, temperature, andsupply
voltage). Consequently, the XMEM interfaceis not suitedforsynchronous operation.
sector) orSRW00 (lowersector)TheALE pulseinperiod T7 is only present if thenextinstruction accesses theRAM
(internal or external).
Bit76543210
SRESRW10
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
SESM1ISC11ISC10ISC01ISC00MCUCR
Write
Read
Extended MCU Control
Register – EMCUCR
• Bit 7 – SRE: External SRAM/XMEM Enable
Writing SRE to one enables the ExternalMemory Interface.The pin functions AD7:0,
A15:8, ALE, WR
, and RD areactivated as thealternate pin functions.The SREbit over-
rides anypin direction settings in the respective Data Direction Registers. Writing SREto zero,disables the ExternalMemory Interfaceand thenormalpin anddata direction
settings areused.
• Bit 6 – SRW10: Wait State Select Bit
For a detaileddescription,see common description for the SRWn bitsbelow (EMCUCR
description).
Bit76543210
SM0SRL2SRL1SRL0SRW01SRW00SRW11ISC2EMCUCR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 6..4 – SRL2, SRL1, SRL0: Wait State Sector Limit
Itispossibletoconfigure different wait statesfordifferent external memory addresses.
The ExternalMemory address space can be divided in two sectors that have separate
wait state bits.The SRL2,SRL1, andSRL0 bitsselectthe splitting of these sectors, see
Table2andFigure11.By default, the SRL2,SRL1, andSRL0 bits are set to zeroand
theentire ExternalMemory address spaceis treated as one sector. When the entire
2512A–AVR–04/02
27
SRAM address spaceisconfigured as one sector, the wait states are configuredbythe
SRW11 andSRW10 bits.
• Bit 1 and Bit 6 MCUCR – SRW11, SRW10: Wait State Select Bits for Upper
Sector
The SRW11 andSRW10 bitscontrol thenumber ofwait statesfor theuppersector of
the ExternalMemory address space,see Table 3.
• Bit 3..2 – SRW01, SRW00: Wait State Select Bits for Lower Sector
The SRW01 andSRW00 bitscontrol thenumber ofwait statesfor the lowersector of
the ExternalMemory address space,see Table 3.
Table 3. Wait States
SRWn1SRWn0Wait States
00No wait states.
01Wait one cycle during read/write strobe.
10Wait two cyclesduring read/write strobe.
11
Note:1. n = 0or 1 (lower/uppersector).
Forfurtherdetails of thetimingandwait states of the ExternalMemory Interface,see
Figure13 to Figure16how the setting of the SRWbits affects the timing.
(1)
Wait two cyclesduring read/write andwait one cycle before driving outnew address.
28
ATmega8515(L)
2512A–AVR–04/02
ATmega8515(L)
Special Function IO Register –
SFIOR
Bit76543210
–XMBKXMM2XMM1XMM0PUD–PSR10SFIOR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value000000 00
•Bit6–XMBK: External Memory Bus Keeper Enable
Writing XMBK to one enables the BusKeeper on theAD7:0 lines. When the BusKeeper
is enabled, AD7:0 will keep the last driven value on the lines even if the XMEM interface
has tri-stated the lines. Writing XMBK to zero disables the BusKeeper. XMBK is not
qualifiedwithSRE, soevenif the XMEM interfaceisdisabled, the BusKeepers are still
activated aslong asXMBKis one.
• Bit 6..3 – XMM2, XMM1, XMM0: External Memory High Mask
When the ExternalMemory is enabled, all Port Cpins areusedfor the high address
byte by default. If the full 60KB address spaceis not required to access the External
Memory, some, or all, Port Cpinscan be releasedfor normal PortPinfunction as
described in Table4.Asdescribed in “Using all 64KB Locations ofExternalMemory”on
page 30, it ispossibletousethe XMMn bits to access all 64KB locations of the External
Memory.
Table 4. Port C Pins Released asNormal PortPinswhen the ExternalMemory is
Enabled
XMM2XMM1XMM0# Bits for External Memory AddressReleased Port Pins
0008(Full 60 KB space)None
0017PC7
0106PC7 - PC6
0115PC7 - PC5
1004PC7 - PC4
1013PC7 - PC3
1102PC7 - PC2
111NoAddress HighbitsFull Port C
2512A–AVR–04/02
29
Using all 64KB Locations of
External Memory
Sincethe ExternalMemory is mapped after the InternalMemory asshowninFigure11,
only 60KB ofExternalMemory is available by default (address space0x0000 to 0x025F
isreservedforInternalMemory). However, it ispossibletotakeadvantage of the entire
ExternalMemory by masking the higher address bits to zero. Thiscan be done by using
the XMMn bits andcontrolbysoftwarethemost significant bits of theaddress. By setting Port C to output 0x00, andreleasing themost significant bitsfor normal PortPin
operation, the Memory Interface will address 0x0000 - 0x1FFF. See codeexample
below.
Assembly Code Example
; OFFSET is defined to 0x2000 to ensure
; external memory access
; Configure Port C (address high byte) to
; output 0x00 when the pins are released
; for normal Port Pin operation