
489
42073A-MCU Wireless-02/13
ATmega2564/1284/644RFR2
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
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 (E)LPM instruction uses the Z-pointer to store the address. Since this instruction
addresses the Flash byte-by-byte, also bit Z0 of the Z-pointer is used.
Figure 30-3. Addressing the Flash during SPM
PROGRAM MEMORY
0
1
15
Z - REGISTER
BIT
0
ZPAGEMSB
WORD ADDRESS
WITHIN A PAGE
PAGE ADDRESS
WITHIN THE FLASH
ZPCMSB
INSTRUCTION WORD
PAGE
PCWORD[PAGEMSB:0]:
00
01
02
PAGEEND
PAGE
PCWORD
PCPAGE
PCMSB
PAGEMSB
PROGRAM
COUNTER
Note:
30.6 Self-Programming the Flash
The program memory is updated in a page by page fashion. Before programming a
page with the data stored in the temporary page buffer, the page must be erased. The
temporary page buffer is filled one word at a time using SPM. The buffer must be filled
before the Page Write command.
Required sequence for self-programming the Flash:
Perform a Page Erase,
Fill temporary page buffer,
Perform a Page Write;
If only a part of the page needs to be changed, the rest of the page must be stored
before the erase, and then be rewritten. The temporary page buffer can be accessed in
a random sequence. It is essential that the page address used in both the Page Erase