Datasheet

241
ATmega48PA/88PA/168PA [DATASHEET]
9223F–AVR–04/14
27.7 Addressing the Flash during Self-programming
The Z-pointer is used to address the SPM commands.
Since the flash is organized in pages (see Table 28-9 on page 255), the program counter can be treated as having two
different sections. One section, consisting of the least significant bits, is addressing the words within a page, while the most
significant bits are addressing the pages. This is1 shown in Figure 27-3. Note that the page erase and page write operations
are addressed independently. Therefore it is of major importance that the boot loader software addresses the same page in
both the page erase and page write operation. Once a programming operation is initiated, the address is latched and the
Z-pointer can be used for other operations.
The only SPM operation that does not use the Z-pointer is setting the boot loader lock bits. The content of the Z-pointer is
ignored and will have no effect on the operation. The LPM instruction does also use the Z-pointer to store the address. Since
this instruction addresses the Flash byte-by-byte, also the LSB (bit Z0) of the Z-pointer is used.
Figure 27-3. Addressing the Flash During SPM
(1)
Note: 1. The different variables used in Figure 27-3 are listed in Table 27-9 on page 247.
Table 27-4. Boot Reset Fuse
(1)
BOOTRST Reset Address
1 Reset vector = Application reset (address 0x0000)
0 Reset vector = Boot loader reset (see Table 27-7 on page 247)
Note: 1. “1” means unprogrammed, “0” means programmed
Bit 151413121110 9 8
ZH (R31) Z15 Z14 Z13 Z12 Z11 Z10 Z9 Z8
ZL (R30) Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0
76543210
BIT
PAGEMSBPCMSB
ZPAGEMSBZPCMSB 0115
Z-REGISTER
PROGRAM
COUNTER
WORD ADDRESS
WITHIN PAGE
PAGE ADDRESS
WITHIN THE FLASH
0
PCWORDPCPAGE
02
01
00
PAGEEND
PCWORD [PAGEMSB:0]
Page
Program Memory
Instruction Word
Page