This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430,data in flash is lost after taking out the battery



Hi,

Every time I take out the battery and reinstall it. I found that the data in the flash is lost. Aren't they supposed to stay in the flash even after losing battery? I am using

MSP430 F249. I define a array starting at 0x3100 of the memory, which should be in the flash. Could someone help me out? Thanks.

 

Si

  • Si,

    Yes, address 0x3100 is in the flash, and flash contents are retained when power is removed from the device.  No ands, ifs, or buts about this.  So, something else is going on here.

    How did you declare the array, and how did you locate it into the flash at address 0x3100?  How do you know it was programmed into the flash correctly in the first place?

    Regards,

    David

  • David,

    Thanks for your help. I think the data were written to a struct beginning at 0x3100, as I checked the memory map when runing it with CCS.  I can see the right data showing at that address.

    I declare the array as following:

    struct TemperatureLog  {     char byte1;     char byte0;     char day;     char hour;     char minute;     char second; };

    struct TemperatureLog *Log1;

     Log1 = (void *) 0x3100;

    I also thought something is going wrong while feell kind of confused as all the data were lost. Is that caused by the fact that I reprogram the chip? I reprogram the board in CCS without running any lines of code. And at that time, I went to check the memory and found everything is lost. Thanks for your help.

    Si

     

  • Si,

    Your code will not place the structure in the flash.  What you've done is declare a pointer of the structure type, and assign the pointer the value of 0x3100.  In fact, it doesn't even look like you declared the structure itself.

    There are two basic types of data values: VARIABLES, and CONSTANTS.  Variables cannot be linked to non-volatile memory (e.g., flash).  They must be linked to RAM.  Only constants can be linked to flash.

    Try the following:

    const struct TemperatureLog MyLog={put your values here};

    Then in the linker command file, you need to link the .const section to the flash.

    Regards,

    David

  • David,

    Thanks for your help. I would try that way. However, why all my data are in the space whose address starts from 0x3100. I can see correct data in that adress and new data stored following the previous one starting from 0x3100.

    Thanks.

  • You are probably looking at the .cinit section.  That is, the initialization values for variables.  If you do this:

    int x=5;

    The '5' gets put in the .cinit section (this is for CCS tools) and will get copied to the RAM location for 'x' during the C-environment startup routine (part of the rts library, gets called automatically before getting to main()).  But 'x' is a variable and is located in RAM so its value can change.

    If you do this:

    const int x=5;

    'x' will be put in the .const section and the '5' will be in the same place (the '5' is put where 'x' is).  You link .const to flash, and you are good to go so far as constant data goes.

    Regards,

    David