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.

MSP430G2553 E2PROM



请问这个单片机就上有EEPROM模块吗? 有的话该如何配置,能附个例程吗?谢谢了

  • Hi, 

    MSP430带有内部Information Flash, 可以存储数据,其掉电不会丢失。其功能同EEPROM。

    例程同你上一个问题,去TI官网下一个MSP430ware.

    Regards!

    Maka

  • 你好,

    这个2553内部的Flash被分成很多个Segment,每个Segment是最小的擦除单元,写的时候可以以字节为单位写入。如果程序运行在Flash中,并调用擦写函数擦写另外一个segment的数据,那么MCU会被halt直到擦写完成。

  •  

    这个是430ware中Flash的例程

    #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
        _NOP();                                 // 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
    }