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.

[Help] Read/Write Variable in Flash Memory

Other Parts Discussed in Thread: MSP430G2553, MSP430G2452

Hi all !!

I have a problem with flash memory in msp430g2553, hope everybody help me !!!

My programing have a variable, I want to store it into flash memory to save value.

I want my variable don't lost after reset or haven't power.

Please training for me known it!!!

I'm sory, this is my first post in forum.

  • Have you tried the search feature in this forum?

    http://e2e.ti.com/search/default.aspx#q=MSP430G2553+saving+data+in+FLASH&qn=&qe=&qa=&t=&g=93&author=&sc=forum&as=0&c=false&pageSize=15&sort=&defaultAskForumId=0&pi1680537405=1&category=forum&categoryVisible=6&group=93&groupVisible=3

  • I;m so sory
    I was read a lot of them, but my problem still don't solved
    please tell me how to read and write to segment A,B,C or D.
    I need to store only a variable.

  • Le Thanh Trieu said:
    please tell me how to read and write to segment A,B,C or D.

    All those threads already in the forum tell how to writ eto flash, in addition to the users guide which explains this in the flash memory controller section.

    And about reading, well flash is just read-only memory. you read it as you would read form any ram location too. This is basic C knowledge (keyword: data pointers)

    Only if you want to write to flash and turn it from read-only memory into difficult-and slow-to-write memory, you need specific code. Which is discussed in all these threads.

  • Thanks for your answer!!

    I was read sample code of TI.And fix it for me, please see below code:

    [code]

    #ifndef FLASH_H_
    #define FLASH_H_

    #include "msp430g2452.h"


    #ifndef TIMER0_A1_VECTOR
    #define TIMER0_A1_VECTOR TIMERA1_VECTOR
    #define TIMER0_A0_VECTOR TIMERA0_VECTOR
    #endif

    void flash_write_segmentC (unsigned char value, unsigned char position)
    {
    char *Flash_ptr; // Flash pointer

    Flash_ptr = (char *) 0x1040; // Initialize Flash pointer
    Flash_ptr += position; // Jump to desired address
    FCTL1 = FWKEY + ERASE; // Set Erase bit
    FCTL3 = FWKEY; // Clear Lock bit
    *Flash_ptr = 0; // Dummy write to erase Flash segment

    FCTL1 = FWKEY + WRT; // Set WRT bit for write operation


    *Flash_ptr = value; // Write value to flash

    FCTL1 = FWKEY; // Clear WRT bit
    FCTL3 = FWKEY + LOCK; // Set LOCK bit
    }
    void flash_read_segmentC (unsigned char *var, unsigned char position)
    {
    char *Flash_ptr; // Segment C pointer

    Flash_ptr = (char *) 0x1040; // Initialize Flash segment C pointer
    Flash_ptr += position; // Jump to desired address

    *var = *Flash_ptr; // copy value segment C to variable

    }
    void flash_write_segmentD (unsigned char value, unsigned char position)
    {
    char *Flash_ptr; // Flash pointer

    Flash_ptr = (char *) 0x1000; // Initialize Flash pointer
    Flash_ptr += position; // Jump to desired address
    FCTL1 = FWKEY + ERASE; // Set Erase bit
    FCTL3 = FWKEY; // Clear Lock bit
    *Flash_ptr = 0; // Dummy write to erase Flash segment

    FCTL1 = FWKEY + WRT; // Set WRT bit for write operation


    *Flash_ptr = value; // Write value to flash

    FCTL1 = FWKEY; // Clear WRT bit
    FCTL3 = FWKEY + LOCK; // Set LOCK bit
    }
    void flash_read_segmentD (unsigned char *var, unsigned char position)
    {
    char *Flash_ptr; // Segment C pointer

    Flash_ptr = (char *) 0x1000; // Initialize Flash segment C pointer
    Flash_ptr += position; // Jump to desired address

    *var = *Flash_ptr; // copy value segment C to variable

    }

    /////////////////////////////////////////////////////////////////////////////

    #endif /* FLASH_H_ */


    void write_alarm_2_flash (void)
    {
    flash_write_segmentC (min_alarm, 0);
    flash_write_segmentD (hour_alarm, 0);
    }
    void read_alarm_from_flash (void)
    {
    flash_read_segmentC (&min_alarm, 0);
    flash_read_segmentD (&hour_alarm, 0);
    if (hour_alarm == 0xFF) hour_alarm = 0x06;
    if (min_alarm == 0xFF) min_alarm = 0x00;
    }

    [/code]

    please tell me about code? it is correct??? In this code, I want to set a time to alarm clock. 

  • I had a similar question, so I searched the forum and found this.  Not surprised.  Every time I search the forum I find nothing but posts like this where the "experts" just yell at the OP to search the forums and then never answer the poor guy.  I think the only question that you can get the answer to by searching the forums is "hey should I search the forums instead of posting my question?"  Guess I'll just figure it out my own, right after I look up the definition of "recursion."

  • CHRISTOPHER HUNT said:
    Every time I search the forum I find nothing but posts like this where the "experts" just yell at the OP to search the forums

    Then I would argue that you are not very skilled in searching. If you search the forum for Variable and Flash:

    http://e2e.ti.com/search/default.aspx#q=variable+flash&g=93&sc=forum

    The second result has a lot of information in it. http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/224545.aspx

    The third result also has good information: http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/18782/630061.aspx#630061

    Do you have a specific question on something you can't get to work?

  • Perhaps I exaggerated when I said I find "nothing but posts like this."  I did find some helpful ones as well.  What I should have said was that it's rather discouraging when the first several posts I find are ones in which long-time members of the "community" snidely berate newcomers for their lack of skills.  Wading through them to get to useful information breeds frustration.  Your links are also quite useful, though, so thank you for that.

  • This only shows how many people are starting a new thread for already answered questions instead of using the forum search first. I agree that it is frustrating to search through a heap of ‘empty’ threads. However, imagine how frustrating it is to have the same question asked again and again – and having to write the same answer again and again. Not to mention the time wasted for repetitions instead of solving problems where there are not dozens of answers already available. Of course I could search my old answers and copy them, but why should I waste my time in using the forum search to answer a thread of someone who could have used the search as well?

    After all, most of us are not paid for our work here. But many of the ones who come and ask are rewarded for the job they then do based on the answers (paid with money or get an university degree at the end, or whatever).

    Sure it would be nice to remove all the noise from the database. I’m sure a good deal of my 14.000 posts could be deleted without losing significant information. But then, who shall do this?

**Attention** This is a public forum