rmrps
Member level 2
Hi Friends I am Using PIC32MX360F512L Controller I am trying to store the data in internal eeprom but i don't know how to do it my example code is here please anybody tell me how to store and read the data from internal eeprom in pic32 series in datasheets mention for erasing flash memory and writing into flash memory and no details available for read the data from eeprom please give me the example code for erase,write,and read the data from pic32mx360f512l internal eeprom thanks in advance
Code:
int main()
{
NVMUnlock (0x0000C001);
Buffer[0]=0xBF80F400;
NVMErasePage(Buffer);
NVMWriteWord(Buffer,0x06);
NVMReadWord(Buffer);
}
unsigned int NVMUnlock (unsigned int nvmop)
{
unsigned int status;
asm volatile ("di %0" : "=r" (status));
// Enable Flash Write/Erase Operations and Select
// Flash operation to perform
NVMCON = nvmop;
// Write Keys
NVMKEY = 0xAA996655;
NVMKEY = 0x556699AA;
// Start the operation using the Set Register
NVMCONSET = 0x8000;
// Wait for operation to complete
while (NVMCON & 0x8000);
// Restore Interrupts
if (status & 0x00000001)
asm volatile ("ei");
else
asm volatile ("di");
// Return NVMERR and LVDERR Error Status Bits
return (NVMCON & 0x3000);
}
unsigned int NVMErasePage(void* address)
{
unsigned int res;
// Set NVMADDR to the Start Address of page to erase
NVMADDR = (unsigned int) address;
// Unlock and Erase Page
res = NVMUnlock(0x4004);
// Return Result
return res;
}
unsigned int NVMWriteWord (void* address, unsigned int data)
{
unsigned int res;
// Load data into NVMDATA register
NVMDATA = data;
// Load address to program into NVMADDR register
NVMADDR = (unsigned int) address;
// Unlock and Write Word
res = NVMUnlock (0x4001);
// Return Result
return res;
}
unsigned int NVMReadWord (void* address)
{
unsigned int res;
// Load data into NVMDATA register
// Load address to program into NVMADDR register
NVMADDR = (unsigned int) address;
// Unlock and Write Word
res=NVMADDR;
// Return Result
return res;
}
Last edited by a moderator: