Hi,
I am trying to write data to flash memory. Below is the code I am using-
Its not giving me any error. But its not even working.
void DevCpuFlashWrite() { if((FCTL & 0x80) != 0x80) //Check FCTL.BUSY { FADDRH = 0x3F; FADDRL = 0xFF; //FADDRH:FADDRL = Page 31, word 511 FCTL = 0xFF; FWDATA = 0x01; //Data FWDATA = 0x03; //Data while((FCTL & 0x40) == 0x40) //Check FCTL.SWBSY { } }}
Please help.
Thanks in advance.
Please verify that your Flash Write Timing is ok, FWT register. The Flash Controller contains a timing generator, which controls the timing sequence of flash write and erase operations. The timing generator uses the information set in the Flash Write Timing register, FWT.FWT[5:0], to set the internal timing. FWT.FWT[5:0] must be set to a value according to the currently selected system clock frequency.
Reset value of FWT is0x11, corresponding to a 13 MHz system clock. What are you CLKCON settings and what are your FWT settings?
-Jonas
Hi Jonas,
I have not changed those registers. Using default settings. Following are the values:
CLKCON = 0xC9 and FWT = 0x11.
I guess CLKCON =0xC9 corresponds to 13Mhz system clock. Please correct me if I am wrong.
Yes, CLKCON = 0xC9 corresponds to 13 MHz System Clock.
Writing data to flash with the CPU can not be done while executing code from flash, so the function that writes to flash must be copied to RAM and executed from there.
Please see this software example for a complete description on how to do it: http://www.ti.com/litv/zip/swrc117
I do not know why I ignored the point "Writing data to flash with the CPU can not be done while executing code from flash".
Now its working. Thanks.
And, those examples were really helpful.
Thank you.