Writing to Program Flash Memory

Program memory can be written either one word at a time or a page at a time.

A single word is written by setting the NVMADR to the target address and loading NVMDAT with the desired word. The word is then transferred to Flash memory by setting the NVMCMD bits to 'b011 then executing the unlock sequence.

A page is written by first loading the buffer registers. All buffer registers are then written to PFM by setting the NVMADR to an address within the target PFM address range, setting the NVMCMD bits to 'b101, and then executing the unlock sequence. Refer to the Page Operations section for more detail on writing to the buffer registers.

If the PFM address in the NVMADR is write-protected, or if NVMADR points to an invalid location, the GO bit is cleared without any effect and the WRERR bit is set.

CPU operation is suspended during a page write cycle and resumes when the operation is complete. The page write operation completes in one extended instruction cycle. When complete, the GO bit is cleared by hardware and NVMIF is set. An interrupt will occur if NVMIE is also set. The buffer registers are unchanged. The NVMCMD bits are not changed.

The internal programming timer controls the write time. The write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device.

Important: Individual bytes of program memory may be modified, provided that the modification does not attempt to change any NVM bit from a ‘0’ to a ‘1’. When modifying individual bytes with a page write operation, it is necessary to load all buffer registers with either 0xFF or the existing contents of memory before executing a page write operation. The fastest way to do this is by performing a page read operation.