Reputation: 1
I've been trying to write some data to a fixed location on DSPIC33EP512MU814 microcontroller. Despite multiple attempts, I am unable to see any success.
I referred reference manual DS70609. Followed the exact steps, but still I couldn't see any change in the flash memory. First I tried to implement it manually and also tried with some examples from various forums. I am using ICD3 debugger to flash and debug the code. I'll share my implementation
#pragma config FWDTEN = OFF, WDTPOST = PS256, WDTPRE = PR128, WINDIS = OFF
#pragma config FNOSC = FRC, IESO = ON
#pragma config JTAGEN = OFF, ICS = PGD2
#pragma config GWRP = OFF, GSS = OFF, GSSK = OFF
#pragma config FPWRT = PWR128, BOREN = ON
#pragma config RSTPRI = PF, AWRP = OFF, APL = OFF, APLK = OFF
#pragma config FCKSM = CSECMD, OSCIOFNC = OFF, POSCMD = XT
uint16 TestData1 = 0x1234;
uint16 TestData2 = 0x5678;
uint16 TestData3 = 0xABCD;
uint16 TestData4 = 0xEFAB;
static void FlashErase(uint32 address)
{
NVMADR = address; // Load the address to erase
NVMADRU = (address >> 16); // Load the upper bits of the address
NVMCON = 0x4003;
NVMKEY = 0x55;
NVMKEY = 0xAA;
NVMCONbits.WR = 1;
__builtin_nop();
__builtin_nop();
while (NVMCONbits.WR); // Wait for erase to complete
// Check for errors
if (NVMCONbits.WRERR)
{
// Handle erase error
}
}
static void FlashWrite(uint32 address)
{
NVMADR = address; // Load the address to erase
NVMADRU = (address >> 16); // Load the upper bits of the address
NVMCON = 0x4001;
TBLPAG = 0xFA;
__builtin_tblwtl(0, TestData1);
__builtin_tblwth(0, TestData2);
__builtin_tblwtl(2, TestData3);
__builtin_tblwth(2, TestData4);
NVMKEY = 0x55;
NVMKEY = 0xAA;
NVMCONbits.WR = 1;
__builtin_nop();
__builtin_nop();
while (NVMCONbits.WR); // Wait for erase to complete
// Check for errors
if (NVMCONbits.WRERR)
{
// Handle erase error
}
}
The address I am trying to erase is 0x1EE00. From the debugger (ICD3), after stepping over the function, I couldn't see any change in program memory. It is intact. Am I doing something wrong here? Do I need to change any configuration bits to do any unlock procedure?
Upvotes: 0
Views: 29