pic18f47q43 Reading from program flash memory problem

0

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;
}
microcontroller
flash-memory
pic18
asked on Stack Overflow Nov 22, 2020 by Shady Abd El Kader • edited Nov 24, 2020 by Mike

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0