3.10.11.4 Addressing the Flash During Self-Programming

The Z pointer is used to address the SPM commands.

The Flash is organized in pages; therefore, 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. This instruction addresses the Flash byte by byte; therefore, the LSB (bit Z0) of the Z pointer is also used.

Figure 3-94. Flash Addressing During SPM