I am using MPLAB X IDE and MPLAB Code Configurator (MCC).
i generated the library of the flash read/write and erase with MCC.
then when i used "FLASH_ReadPage
" built in function created from the MCC its not working, and after debugging i found it stucked in a while loop that is checking for "NVMCON0bits.GO
" to be cleared and its never cleared thats why its stucked.
here is the function:
void FLASH_ReadPage(uint32_t flashAddr)
{
uint8_t GIEBitValue = INTCON0bits.GIE; // Save interrupt enable
//Set NVMADR with the target word address
NVMADRU = (uint8_t) ((flashAddr & 0x00FF0000) >> 16);
NVMADRH = (uint8_t) ((flashAddr & 0x0000FF00) >> 8);
NVMADRL = (uint8_t) (flashAddr & 0x000000FF);
//Set the NVMCMD control bits for Page Read operation
NVMCON1bits.NVMCMD = 0b010;
//Disable all interrupt
INTCON0bits.GIE = 0;
//Perform the unlock sequence
NVMLOCK = 0x55;
NVMLOCK = 0xAA;
//Start page read and wait for the operation to complete
NVMCON0bits.GO = 1;
while (NVMCON0bits.GO); **<----- Stucked here**
//Restore the interrupts
INTCON0bits.GIE = GIEBitValue;
//Set the NVMCMD control bits for Word Read operation to avoid accidental writes
NVMCON1bits.NVMCMD = 0b000;
}
User contributions licensed under CC BY-SA 3.0