Datasheet

ATmega48PA/88PA/168PA [DATASHEET]
9223F–AVR–04/14
232
26.2 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 is shown in Figure 27-3 on page 241. Note that the page erase and page
Write operations are addressed independently. Therefore it is of major importance that the software addresses the same
page in both the page erase and page write operation.
The LPM instruction uses 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 26-1. Addressing the Flash During SPM
(1)
Note: 1. The different variables used in Figure 27-3 are listed in Table 28-9 on page 255.
26.2.1 EEPROM Write Prevents Writing to SPMCSR
Note that an EEPROM write operation will block all software programming to flash. Reading the fuses and lock bits from
software will also be prevented during the EEPROM write operation. It is recommended that the user checks the status bit
(EEPE) in the EECR register and verifies that the bit is cleared before writing to the SPMCSR register.
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
Instructions Word
Page