34071417 发表于 2012-12-28 10:54:57

MSP430 information flash 512字节全部使用的操作

FCTL3 = FWKEY;                            // Clear Lock bit
FCTL1 = FWKEY+WRT;                        // Enable byte/word write mode

while (count > 0) {
    while (FCTL3 & BUSY);                   // test busy
    __data20_write_char(Flash_ptr++,*Data_ptr++);
    //*Flash_ptr++ = *Data_ptr++;             // Write to Flash
    count--;
}

FCTL1 = FWKEY;                            // Clear write bit
FCTL3 = FWKEY + LOCK;                     // Set LOCK bit

这个官方代码操作实例的一部分;
__data20_write_char(Flash_ptr++,*Data_ptr++);可以实现对0xFFFF以上地址的读写操作;

但是使用该段代码无法实现对INFO A的写入;
原因就是 FCTL3 中一个LOCKA位,置位就行
FCTL1 = FWKEY+WRT;                        // Enable byte/word write mode

if((FCTL3&LOCKA)==LOCKA)
FCTL3 = FWKEY+LOCKA;                        // Clear Lock bit
        else
FCTL3 = FWKEY;

while (count > 0) {
    while (FCTL3 & BUSY);                   // test busy
    *Flash_ptr++ = *Data_ptr++;             // Write to Flash
    count--;
}

if((FCTL3&LOCKA)!=LOCKA)
FCTL3=FWKEY+LOCK+LOCKA;
else
FCTL3=FWKEY+LOCK;
FCTL1=FWKEY;
这是写入内容功能代码

34071417 发表于 2012-12-28 10:59:19

上帝的佑护 发表于 2014-8-6 16:24:49

正好需要!借鉴下!

gaopmsn 发表于 2014-8-6 16:47:13

顶上去,谢谢分享

苹果520 发表于 2015-4-30 12:56:33

顶上去,谢谢分享。顺便测试下,
页: [1]
查看完整版本: MSP430 information flash 512字节全部使用的操作