NVMREG Read Operation

To read a NVM location using the NVMREG interface, the user must:
  1. 1.Clear the NVMREGS bit if the user intends to access program memory locations, or set NMVREGS if the user intends to access User ID or configuration locations.
  2. 2.Write the desired address into the NVMADRH:NVMADRL register pair.
  3. 3.Set the RD bit to initiate the read.

Once the read control bit is set, the CPU operation is suspended during the read and resumes immediately after. The data is available in the very next cycle, in the NVMDATH:NVMDATL register pair; therefore, it can be read as two bytes in the following instructions.

The NVMDATH:NVMDATL register pair will hold this value until another read or until it is written to by the user.

Upon completion, the RD bit is cleared by hardware.

Figure 1. Program Flash Memory Read Sequence

Program Memory Read

// This code block will read 1 word of program memory

NVMCON1bits.NVMREGS = 0;          // Point to PFM
NVMADR = PFM_ADDRESS;             // Load NVMADRH:NVMADRL with PFM address
NVMCON1bits.RD = 1;               // Initiate read cycle
PFM_DATA_LOW = NVMDATL;           // PFM data low byte
PFM_DATA_HIGH = NVMDATH;          // PFM data high byte