Datasheet

buffer will auto-erase after a page write operation or by writing the RWWSRE bit in SPMCSR. It is also
erased after a system Reset. Note that it is not possible to write more than one time to each address
without erasing the temporary buffer.
If the EEPROM is written in the middle of an SPM page load operation, all data loaded will be lost.
30.1.3 Performing a Page Write
To execute page write, set up the address in the Z-pointer(R30 and R31), write “0x00000101” to
SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is
ignored. The page address must be written to PCPAGE ([Z12:Z6]). Other bits in the Z-pointer must be
written to zero during this operation.
The CPU is halted during the page write operation
30.2 Addressing the Flash During Self-Programming
The Z-pointer (R30 and R31) is used to address the SPM commands.
Bit 15 14 13 12 11 10 9 8
ZH (R31) Z15 Z14 Z13 Z12 Z11 Z10 Z9 Z8
ZL (R30) Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0
7 6 5 4 3 2 1 0
Since the Flash is organized in pages (Refer to page size section in memory programming chapter), 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 the following figure. 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 Load Program Memory (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.
ATmega48PA/88PA/168PA
Self-Programming the Flash
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 338