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 me with MSP430G2233 Flash Memory

Hi,

I am new with this TI processor.  I have a project that have 2 calibration button, high calibration and low calibration.  I just want to save those value into memory after pressed calibration button and whenever the processor restarted, it will load back the value.

your help is much appreciated

Thank you

  • You should start with code examples for the processor - they can be found here:

    This is the example for writing to the info segments in the flash:

    //******************************************************************************
    //  MSP430G2xx3 Demo - Flash In-System Programming, Copy SegC to SegD
    //
    //  Description: This program first erases flash seg C, then it increments all
    //  values in seg C, then it erases seg D, then copies seg C to seg D.
    //  Assumed MCLK 771kHz - 1428kHz.
    //  //* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *//
    //
    //               MSP430G2xx3
    //            -----------------
    //        /|\|              XIN|-
    //         | |                 |
    //         --|RST          XOUT|-
    //           |                 |
    //
    //  D. Dang
    //  Texas Instruments Inc.
    //  December 2010
    //   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************
    
    #include <msp430.h>
    
    char  value;                                // 8-bit value to write to segment A
    
    // Function prototypes
    void write_SegC (char value);
    void copy_C2D (void);
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
      {											
        while(1);                               // do not load, trap CPU!!	
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO to 1MHz
      DCOCTL = CALDCO_1MHZ;
      FCTL2 = FWKEY + FSSEL0 + FN1;             // MCLK/3 for Flash Timing Generator
      value = 0;                                // initialize value
    
      while(1)                                  // Repeat forever
      {
        write_SegC(value++);                    // Write segment C, increment value
        copy_C2D();                             // Copy segment C to D
        __no_operation();                       // SET BREAKPOINT HERE
      }
    }
    
    void write_SegC (char value)
    {
      char *Flash_ptr;                          // Flash pointer
      unsigned int i;
    
      Flash_ptr = (char *) 0x1040;              // Initialize Flash pointer
      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
    
      for (i=0; i<64; i++)
      {
        *Flash_ptr++ = value;                   // Write value to flash
      }
    
      FCTL1 = FWKEY;                            // Clear WRT bit
      FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }
    
    void copy_C2D (void)
    {
      char *Flash_ptrC;                         // Segment C pointer
      char *Flash_ptrD;                         // Segment D pointer
      unsigned int i;
    
      Flash_ptrC = (char *) 0x1040;             // Initialize Flash segment C pointer
      Flash_ptrD = (char *) 0x1000;             // Initialize Flash segment D pointer
      FCTL1 = FWKEY + ERASE;                    // Set Erase bit
      FCTL3 = FWKEY;                            // Clear Lock bit
      *Flash_ptrD = 0;                          // Dummy write to erase Flash segment D
      FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation
    
      for (i=0; i<64; i++)
      {
        *Flash_ptrD++ = *Flash_ptrC++;          // copy value segment C to segment D
      }
    
      FCTL1 = FWKEY;                            // Clear WRT bit
      FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }

    Try to understand that and then build your own code based on this.

  • Thanks Dennis. After i compile it, i receive this error msg. #10099-D program will not fit into available memory. placement with alignment fails for section ".cinit" size 0x20. what does this error mean. thanks
  • What did you compile? Exactly this program from the examples? Or together with other code?

    Dennis
  • I conplied with other codes.  Seem like i need to clear up or reorganize code so it won't use up much of memory.  Or is there another way can solve?  Thanks for you reply

  • Then it seems as if your code size is too large.
    Your processor has only 2k of flash and 0.25k of RAM.

    Dennis
  • I just reduced some code. Should be fine now. Thank you
    however, it is not everytime will write into flash. here is my code.

    one question, why do we need to loop 64 times to copy the flash?


    void flash_write_low(int fLow)
    {
    _DINT(); // Disable interrupts(IAR workbench).
    FCTL2 = FWKEY + FSSEL_1 + FN0; // Clk = SMCLK/4
    FCTL1 = FWKEY + ERASE; // Set Erase bit
    FCTL3 = FWKEY; // Clear Lock bit
    *FlashLow = 0; //Clear Flash
    FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
    *FlashLow = fLow; // copy value to flash

    FCTL1 = FWKEY; // Clear WRT bit
    FCTL3 = FWKEY + LOCK; // Set LOCK bit
    _EINT();
    }

    Please advice. Thank you!

**Attention** This is a public forum