
148
ATtiny40 [DATASHEET]
8263B–AVR–01/2013
19.4.1
Addressing the Flash
The data space uses byte accessing but since the Flash sections are accessed as words and organized in pages,
the byte-address of the data space must be converted to the word-address of the Flash section. This is illustrated
Figure 19-1. Addressing the Flash Memory
The most significant bits of the data space address select the NVM Lock bits or the Flash section mapped to the
data memory. The word address within a page (WADDR) is held by the bits [WADDRMSB:1], and the page
address (PADDR) is held by the bits [PADDRMSB:WADDRMSB+1]. Together, PADDR and WADDR form the
absolute address of a word in the Flash section.
The least significant bit of the Flash section address is used to select the low or high byte of the word.
19.4.2
Reading the Flash
The Flash can be read from the data memory mapped locations one byte at a time. For read operations, the least
significant bit (bit 0) is used to select the low or high byte in the word address. If this bit is zero, the low byte is read,
and if it is one, the high byte is read.
19.4.3
Programming the Flash
The Flash can be written four words at a time. Before writing a Flash words, the Flash target location must be
erased. Writing to an un-erased Flash word will corrupt its content.
The Flash is written four words at a time but the data space uses byte-addressing to access Flash that has been
mapped to data memory. It is therefore important to write the four words in the correct order to the Flash, namely
low bytes before high bytes. The low byte of the first word is first written to the temporary buffer, then the high byte.
Writing the low byte and then the high byte to the buffer latches the four words into the Flash write buffer, starting
the actual Flash write operation.
The Flash erase operations can only performed for the entire Flash sections.
The Flash programming sequence is as follows:
00
PAGE
01
02
SECTIONEND
WORD
00
01
PAGEEND
FLASH
SECTION
FLASH
PAGE
0/1
WADDR
PADDR
1
WADDRMSB
PADDRMSB
16
ADDRESS POINTER
...
PAGE ADDRESS
WITHIN A FLASH
SECTION
WORD ADDRESS
WITHIN A FLASH
PAGE
LOW/HIGH
BYTE SELECT
WADDRMSB+1