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.
因为程序需要,要存储的数据正好256字节,要将ABCD四段全擦除。
代码:
void Falsh_Erase(char *Addr)
{
while((FCTL3&BUSY) == BUSY);
FCTL1 = FWKEY+ERASE;
FCTL3 = FWKEY;
*Addr=0;
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK;
while((FCTL3&BUSY) == BUSY);
}
//向指定地址写一个字节
void Falsh_WriteB(char *Addr,uint8 nValue)
{
FCTL1 = FWKEY+WRT; // 允许写
FCTL3 = FWKEY; // 解锁
while((FCTL3&BUSY) == BUSY);
*Addr = nValue;
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK; // 锁定
while((FCTL3&BUSY) == BUSY);
}
// 读flash 指定地址的字节
uint8 Flash_ReadB(char *Addr)
{
uint8 RData;
RData = *Addr;
return RData;
}
对ABCD四段flash进行擦除:
Falsh_Erase((char *)0x1000);
Falsh_Erase((char *)0x1040);
Falsh_Erase((char *)0x1080);
Falsh_Erase((char *)0x10C0);//A段
但A段擦不掉啊!BCD段可以擦除
SegmentA of the information memory is locked separately from all other segments with the LOCKA bit.
When LOCKA = 1, SegmentA cannot be written or erased and all information memory is protected from
erasure during a mass erase or production programming. When LOCKA = 0, SegmentA can be erased
and written as any other flash memory segment, and all information memory is erased during a mass
erase or production programming.
参见MSP430G2用户手册,这里对A段要求LOCKA= 0,方可擦除。所有你程序中需要对A段进行特别处理,先解锁然后擦除。但是A段存有IC调校参数,不建议对A段进行擦除。