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.

MSP430FR5969: How to write two words to FRAM

Part Number: MSP430FR5969
Other Parts Discussed in Thread: MSP430FR2355

Good evening....

I have looked at the User Guide and the TI resource examples but don't seem to quite understand how to write a word to the Data section of FRAM.  Firstly let me establish that I am a hardware guy who has written small C embedded applications over the years.  I would like (if possible) to have a piece of code that will write an ID # (int) into FRAM to be read as necessary at future dates.  I also will be porting this code to MSP430FR2355 when dev boards arrive. 

I am confused bcz I thought I had to just write an UNLOCK (0xA5) to a location and send data, then RELOCK....It appears more complicated than that.  It also appears that cutting and pasting the 2355 example code into the 5969 gets me a bunch of errors.  The 5969 example on long writes doesn't appear to unlock any registers.  Can someone please help?

Sincerely,

Steve

  • Hi,

    You can try to use this example.

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430FR59xx Demo - Long word writes to FRAM
    //
    //   Description: Use long word write to write to 512 byte blocks of FRAM.
    //   Toggle LED after every 100 writes.
    //   NOTE: Running this example for extended periods will impact the FRAM
    //   endurance. MPU is also enabled by default in CCS.
    //   MCLK = SMCLK = default DCO
    //
    //           MSP430FR5969
    //         ---------------
    //     /|\|               |
    //      | |               |
    //      --|RST            |
    //        |               |
    //        |               |
    //        |          P1.0 |---> LED
    //
    //   Kathryn Adamsky
    //   Texas Instruments Inc.
    //   July 2016 (Updated) | August 2012 (Created)
    //   Built with IAR Embedded Workbench V5.40 & Code Composer Studio V5.5
    //******************************************************************************
    #include <msp430.h>
    
    #define WRITE_SIZE 128                           
    
    void FRAMWrite(void);
    
    unsigned char count = 0;
    unsigned long data;
    
    #if defined(__TI_COMPILER_VERSION__)
    #pragma PERSISTENT(FRAM_write)
    unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__IAR_SYSTEMS_ICC__)
    __persistent unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__GNUC__)
    unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0};
    #else
    #error Compiler not supported!
    #endif
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT
    
      // Configure GPIO
      P1OUT &= ~BIT0;                           // Clear P1.0 output latch for a defined power-on state
      P1DIR |= BIT0;                            // Set P1.0 to output direction
    
      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;
    
      // Initialize dummy data
      data = 0x00010001;
    
      while(1)
      {
        data += 0x00010001;
        FRAMWrite();                            
        count++;
        if (count > 100)
        {
          P1OUT ^= 0x01;                        // Toggle LED to show 512K bytes
          count = 0;                            // ..have been written
          data = 0x00010001;
        }
      }
    }
    
    void FRAMWrite(void)
    {
      unsigned int i=0;
    
      for ( i= 0; i< WRITE_SIZE; i++)
      {
        FRAM_write[i] = data;
      }
    }
    
    The reason is that in MSP430FR2355, it use SYSCFG0 to enable or disable FRAM write. In FR5969, it use MPU peripheral to control FRAM write. 

    The difference lies on 

    #pragma PERSISTENT(FRAM_write)

    For description about this cmd please refer to this MSP430 Compiler guide:http://www.ti.com/lit/ug/slau132v/slau132v.pdf on page 108

    Eason

  • Hi Eason....

    I've taken the 5969 example code and whittled it down to the following and it works!

    #pragma PERSISTENT(FRAM_write)
    unsigned FRAM_write[1] = {0};
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT
      FRAM_write[0] = 0xFABA;
    }

    However I literally paste this same code into my application :

    #pragma PERSISTENT(FRAM_write)
    unsigned FRAM_write[1] = {0};
    
    unsigned int CRC_Result, SW_Results, i, k, payload_sw = 0x0000;
    char *pyld, mssg[6], rcv;
    
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
        Fram_write[0] = 0xFABA;
    

    and I get the following build error????

    "../rc.c", line 18: error #20: identifier "Fram_write" is undefined

    Please explain?

    Thanks

    Steve

  • Also....

    Does this technique guarantee that if I remove the batteries from the device and then replace them that the memory will remain intact with the value I wrote to FRAM?

  • >unsigned FRAM_write[1] = {0};
    >    Fram_write[0] = 0xFABA;
    These are not the same name. Pick one or the other.
  • I'm sorry!  UGHHH.....yes that works fine....Thank you!!!  I do have one question though.....When I look at the datasheet it shows FRAM address as Info A, B, etc....0x001800 -0x0019FF....Is this data FRAM or code FRAM?  I find that the above line is writing code at 0x004400 (I found this in the .map file of the project)....Can you explain why the code isn't in the 1800-19FF section and where the 4400 section comes in at?  Secondly is there a way to point to a specific data area and have it write the int there?

    Thanks again for all the support

    Steve

  • 1) The CPU doesn't distinguish code vs data FRAM. The programmer typically wants to keep the two separate (data writable, code not). The MPU can be used to do this. ("Build Settings->CCS General->MPU")

    With code model Large, the linker (.cmd file) preferentially puts code in "high" FRAM.

    2) Eason pointed you at CC User Guide (SLAU132U) Section 5.12.22, which explains the options you have. In particular it has an example of combining PERSISTENT with LOCATION.

**Attention** This is a public forum