Write Procedure

The Flash memory is written in a page-by-page fashion. The write function is performed by storing data for an entire page into a temporary page buffer prior to writing the Flash. Which Flash address to write to is decided by the content of the Z-register and RAMPZ-register. A Flash page must be erased before it can be programmed with the data stored in the temporary buffer. The functions contained in this application note use the following procedure when writing a Flash page:

As it is evident in this sequence there is a possibility for loss of data, if a reset or power failure should occur immediately after a page erase. Loss of data can be avoided by taking necessary precautions in software, involving buffering in non-volatile memory. The write functions contained in this application note provide optional buffering when writing. These functions are further described in the firmware section.

Devices that support the read-while-write feature allows the boot loader code to be executed while writing. In such devices, the write functions will not return until the write has completed.