请教MSP430F5438有关flash操作的问题,代码见下,为什么固定地址的flash没有改变?
代码:
void main(void)
{
unsigned long SEGMENT = 0x20000ul;
WriteFlash(SEGMENT);
FlashErase(SEGMENT);
while(1);
}
代码:
//擦除Flash指定地址:adr指定地址Y
void FlashErase(unsigned long pAddr)
{
uchar * Flash_ptr = (uchar *)pAddr;
_DINT();
while(BUSY & FCTL3);
FCTL3 = FWKEY;
FCTL1 = FWKEY+ERASE;
*Flash_ptr = 0;
while(BUSY & FCTL3);
FCTL3 = FWKEY+LOCK;
_EINT();
}
代码:
//写入Flash指定地址:adr指定地址,
void WriteFlash(unsigned long pAddr)
{
_DINT();
unsigned int i;
uchar * Flash_ptr = (uchar *)pAddr;
while (FCTL3&BUSY);
FCTL3 = FWKEY;
FCTL1 = FWKEY+WRT;
for(i = 0; i < 128; i++)
{
*(Flash_ptr++) = record1[i];
while(!(WAIT & FCTL3));
}
while (FCTL3&BUSY);
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK;
_EINT();
}
|