From: FLASH Self Write Microchip dsPIC33F, PIC24H
Hi sir, I tested the file…its working…I want to change parameter individually…when I write parameter[1]
All parameter is changing…but parameter[1] value is same what I have written …but other value is changing…can you help me…
Hi @aaneesh444 which mcu are you using? Can you share what you changed? and what you want to do…
Please use code blocks (```) pre and post text:
code block
Regards,
When looking at Kevin’s posted code: (programParameters), it is specifically tuned for 3 integers, did you extend this code when you changed it to an array of 8?
/********************************************************************************
* programParameters()
*
* Prototype: int programParameters(unsigned int, unsigned int, unsigned int)
* Passed arguments: unsigned int param1, unsigned int param2, unsigned int param3
* Return value: none
* Dependencies: INTERRUPTS MUST be DISABLED prior to calling this routine.
*
* Description: Erase block of NVM and write data to FLASH memory
********************************************************************************/
void programParameters(unsigned int param1, unsigned int param2, unsigned int param3)
{
unsigned int tbloffset;
//Erase one page of FLASH memory
NVMCON = 0x4042; // Setup NVMCON for Block Erase operation (512 instructions)
TBLPAG = __builtin_tblpage(&iParameters[0]); // Load upper FLASH address
tbloffset = __builtin_tbloffset(&iParameters[0]); // Offset within page
__builtin_tblwtl(tbloffset, 0xFFFF); // Dummy write to select the page
FLASHWrite(); // low level erase/write command sequence
// write single word, param1, to FLASH
// In this case the Page hasn't changed so don't have to load the table
// page register again.
tbloffset = __builtin_tbloffset(&iParameters[0]); // offset within page
__builtin_tblwtl(tbloffset, param1); // load the write buffer
NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
FLASHWrite(); // low level erase/write command sequence
// write single word, param2, to FLASH
tbloffset = __builtin_tbloffset(&iParameters[1]); // offset within page
__builtin_tblwtl(tbloffset, param2); // load the write buffer
NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
FLASHWrite(); // low level erase/write command sequence
// write single word, param3, to FLASH
tbloffset = __builtin_tbloffset(&iParameters[2]); // offset within page
__builtin_tblwtl(tbloffset, param3); // load the write buffer
NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
FLASHWrite(); // low level erase/write command sequence
return;
}