24.14 Row Programming
The largest block of data that can be programmed is a row.
Unlike Word and Quad Word Programming where the data source is stored in SFR memory, Row programming source data is stored in SRAM. The NVMSRCADDR register is a pointer to the physical location of the source data for Row programming.
Like other Non-Volatile Memory (NVM) programming commands, the NVMADDR register points to the target address of the operation. Row programming always occurs on row boundaries with the row size of 1024, bits 0 through 9 of the NVMADDR register are ignored.
Row Word programming will only succeed if the target address is in a page that is not write-protected. When a row is programmed, it must be erased before any Word in it can be programmed again, even if changing a bit from an erased ‘1
’ state to a ‘0
’ state.
Array rowbuff
is populated with data and programmed into a row located at physical address 0x1008000
.
…
unsigned long rowbuff[256]; // example is for a 256 Word row size.
int x; // loop counter
// put some data in the source buffer
for (x = 0; x < (sizeof(rowbuff) * sizeof (int)); x++)
((char *)rowbuff)[x] = x;
// set destination row address
NVMADDR = 0x1008000; // row physical address
// set source address. Must be converted to a physical address.
NVMSRCADDR = (unsigned int)((int)rowbuff & 0x1FFFFFF);
// define Flash operation
NVMCONbits.NVMOP = 0x3; // NVMOP for Row programming
// Enable Flash Write
NVMCONbits.WREN = 1;
// commence programming
NVMInitiateOperation(); // see Initiate NVM Operation (Unlock Sequence Example)
// Wait for WR bit to clear
while(NVMCONbits.WR);
// Disable future Flash Write/Erase operations
NVMCONbits.WREN = 0;
// Check Error Status
if(NVMCON & 0x3000) // mask for WRERR and LVDERR bits
{
// process errors
}
…