10.3.3 Word Read

A single 16-bit word is read by setting the NVMADR registers to the target address and setting the NVMCMD bits to ‘b000. The word is then transferred from PFM to the NVMDAT registers by starting the read operation by setting the GO bit.

The sequence of events for reading a word of PFM is:

  1. Set the NVMADR registers to the target address.
  2. Set the NVMCMD control bits to ‘b000 (Word Read).
  3. Set the GO bit to start the PFM word read.
  4. Monitor the GO bit or NVMIF interrupt flag to determine when the read has completed.

Reading a Word from Program Flash Memory in C

// Code sequence to read one word from PFM
// PFM target address is specified by WORD_ADDR

// Variable to store the word value from desired location in PFM
uint16_t WordValue; 

// Load NVMADR with the desired word address
NVMADR = WORD_ADDR;
NVMCON1bits.CMD = 0x00;         // Set the word read command
NVMCON0bits.GO = 1;             // Start word read
while (NVMCON0bits.GO);         // Wait for the read operation to complete
WordValue = NVMDAT;             // Store the read value to a variable