
149
ATtiny40 [DATASHEET]
8263B–AVR–01/2013
1.
Perform a Flash section erase or perform a Chip erase
2.
Write the Flash section four words at a time
19.4.3.1
Chip Erase
The Chip Erase command will erase the entire code section of the Flash memory and the NVM Lock Bits. For
security reasons, however, the NVM Lock Bits are not reset before the code section has been completely erased.
The Configuration, Signature and Calibration sections are not changed.
Before starting the Chip erase, the NVMCMD register must be loaded with the CHIP_ERASE command. To start
the erase operation a dummy byte must be written into the high byte of a word location that resides inside the Flash
code section. The NVMBSY bit remains set until erasing has been completed. While the Flash is being erased nei-
ther Flash buffer loading nor Flash reading can be performed.
The Chip Erase can be carried out as follows:
1.
Write the CHIP_ERASE command to the NVMCMD register
2.
Start the erase operation by writing a dummy byte to the high byte of any word location inside the code
section
3.
Wait until the NVMBSY bit has been cleared
19.4.3.2
Erasing the Code Section
The algorithm for erasing all pages of the Flash code section is as follows:
1.
Write the SECTION_ERASE command to the NVMCMD register
2.
Start the erase operation by writing a dummy byte to the high byte of any word location inside the code
section
3.
Wait until the NVMBSY bit has been cleared
19.4.3.3
Writing Flash Code Words
The algorithm for writing four words to the code section is as follows:
1.
Write the CODE_WRITE command to the NVMCMD register
2.
Write the low byte of the 1st word to the low byte of a target word location
3.
Write the high byte of the 1st word to the high byte of the same target word location
4.
5.
Write the low byte of the 2nd word to the low byte of the next target word location
6.
Write the high byte of the 2nd word to the high byte of the same target word location.
7.
8.
Write the low byte of the 3rd word to the low byte of a target word location
9.
Write the high byte of the 3rd word to the high byte of the same target word location
11. Write the low byte of the 4th word to the low byte of the next target word location
12. Write the high byte of the 4th word to the high byte of the same target word location. This will start the
Flash write operation
13. Wait until the NVMBSY bit has been cleared