I'm trying to write the EEPROM (DFM) on a PIC18F27Q83. I copied the sequence from the datasheet exactly and it still fails. The device id is 0x9909 and revision id is 0xA45.
// Save interrupt enable bit value
unsigned char GIEBitValue = INTCON0bits.GIE;
// Load NVMADR with the target address of the byte
NVMADR = 0x380000;
NVMDATL = outgoing_data.data_bytes[0]; // Load NVMDAT with the desired value
NVMCON1bits.CMD = 0x04; // Set the byte write command and post increment
INTCON0bits.GIE = 0; // Disable interrupts
//????????? Required Unlock Sequence ?????????
NVMLOCK = 0x55;
NVMLOCK = 0xAA;
NVMCON0bits.GO = 1; // Start byte write
//???????????????????????????????????????????????
while (NVMCON0bits.GO); // Wait for the write operation to complete
// Verify byte write operation success and call the recovery function if needed
if (NVMCON1bits.WRERR)
{
INTCON0bits.GIE = GIEBitValue; // Restore interrupt enable bit value
NVMCON1bits.CMD = 0;
return false;
}
After the GO bit goes to zero meaning the operation has completed the WRERR bit stays at 1 meaning the operation failed. I have watched the WRERR bit and it is just 1 all the time. I assume that once a successful write occurs it should go to zero.
The chip is running on a 10MHz external oscillator and OFSC is 40MHz. All of that has been verified and I have UART comms with the chip no problem.
INTCON0bits.GIE
whenNVMCON1bits.WRERR
is asserted? \$\endgroup\$