Hi Wolfgang,
A few things...
Have you set FCTL2 correctly? ie what frequency is the FLASH clock?

Also, and I don't remember the FLASH register bits here, as I wrote this stuff once and it's just worked ever since.
Wouldn't you want it to ERASE the segment before re-writing it?
When erasing the segment, you'd generally want the data to be erased in a different segment than possible code, so just having it as a const might not ensure this. Would pay to check I believe. My non-volatile data has generally been stored in the infomem section, so I just erase those sectors.

Regards,
Bevan

Hi,

I tried to write some data into FLASH memory. I used the following code example:

const uint16_t test_var = 5;

int main()
{
.
.
.
FCTL3 = FWKEY;        // Unlock the flash.
FCTL1 = FWKEY | WRT;  // Enable flash write.
test_var56++;      // Write the data to the flash.
do {
   _NOP();
} while(FCTL3 & BUSY);
FCTL1 = FWKEY;        // Disable flash write.
FCTL3 = FWKEY | LOCK; // Lock the flash.*/
.
.
.
}

However, it does not work. The value of "test_var" after the first run is always "4". A second reset does not change value at all.

It seems that only the least significant bit is written to the flash.

Any ideas?

Thanks a lot.

Greetings,

     Wolfgang




Reply via email to