본문 바로가기

[MSP430]/MSP430_EVM

[MSP430] Falsh Write - EEPOM 처럼 사용하기

[MSP430] Falsh Write - EEPOM 처럼 사용하기

 

MSP430은 EEPROM이 없고 대신 Flash 영역에 데이터를 저장할 수 있다. 실행 중에 Flash 영역에  저장할 수 있기 때문에 변경 될수 있는 설정 파라미터를 저장하기에 좋을것 같다.

 

#define _SEG_C_ADDR                     0x1040

 


void falsh_wrte(unsigned char *pBuf, int Size)
{
  char *Flash_ptr;                          // Flash pointer
  unsigned int i;

  Flash_ptr = (char *)_SEG_C_ADDR;              // Initialize Flash pointer
  FCTL2 = FWKEY + FSSEL0 + FN1;             // MCLK/3 for Flash Timing Generator
    
  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<Size; i++)
  {
    *Flash_ptr++ = pBuf[i];                   // Write value to flash
  }

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

 

void flash_read(unsigned char *pBuf, int Size)
{
  char *Flash_ptrC;                         // Segment C pointer
  unsigned int i;

  Flash_ptrC = (char *)_SEG_C_ADDR;             // Initialize Flash segment C pointer

  for (i=0; i<Size; i++)
  {
    pBuf[i] = *Flash_ptrC++;          // copy value segment C to segment D
  }

}

반응형