Page Operations

Changing a word in PFM requires erasing the word before it is re-written. However, the PFM cannot be erased by less than a page at a time. Changing a single word requires reading the page, erasing the page, then re-writing the page with the modified word. The NVM command set includes page operations to simplify this task.

In this device a PFM page is 128 words (256 bytes). This is the same size as one bank of general purpose RAM (GPR). This area of GPR space is dedicated as a buffer area for NVM page operations. The buffer areas for each device in the family are shown in the following table.

Table 1. NVM Buffer Banks
Device GPR Bank Number
PIC18Fx7Q43 37
PIC18Fx6Q43 21
PIC18Fx5Q43 13
The steps necessary to change one or more words in PFM space are as follows:
  1. 1.Set the NVMADR registers to the target address.
  2. 2.Set NVMCMD to ‘b010 (Read Page).
  3. 3.Set the GO bit to start the PFM read into the GPR buffer.
  4. 4.Monitor the GO bit or NVMIF interrupt flag to determine when the read has completed.
  5. 5.Make the desired changes to the GPR buffer data.
  6. 6.Set NVMCMD to ’b110 (Erase Page).
  7. 7.Send the unlock sequence to start the erase operation.
  8. 8.Monitor the GO bit or NVMIF interrupt flag to determine when the erase has completed.
  9. 9.Set NVMCMD to ’b101 (Write Page).
  10. 10.Send the unlock sequence to start the Page Write operation.
  11. 11.Monitor the GO bit or NVMIF interrupt flag to determine when the write has completed.
There are several ways to address the data in the GPR buffer space:

Neglecting the bank select bits, the 8 address bits of the GPR buffer space correspond to the 8 LSbs of each PFM page. In other words, there is a one to one correspondence between the NVMADRL register and the FSRxL register, where the x in FSRx is 0, 1, or 2.