共2条
1/1 1 跳转至页
FLASH 我的擦写FLASH的程序有什么问题?
问
#include <MSP430x44x.h>
#define FLASH_ADDRESS 0x1080 //信息存储器中的地址
void Flash_ww(int * Data_ptr,int word)
{
FCTL3=FWKEY+WRT; //Lock=0
FCTL1=FWKEY; //WRT=1
*Data_ptr=word; //字编程
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK; //Lock=1
}
void Flash_clr(int * Data_ptr)
{
FCTL1=FWKEY+ERASE; //ERASE=1
FCTL3=FWKEY; //Lock=0
*Data_ptr=0; //段擦除
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK; //Lock=1
}
void display(int disData)
{
.................
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2=FWKEY+FSSEL0+FN0; // 定义FLASH时序发生器输入时钟
firstTime=(int *)FLASH_ADDRESS;
Flash_clr(firstTime);
Flash_ww(firstTime,0x1000);
display(*firstTime);
while(1);
}
请问擦除和写入函数有没有问题?我把Flash_clr(firstTime);去掉就可以显示出来数据,但数据当然不是0x1000。那位帮我看一下,先谢谢了! 答 1: 下面程序供参考!
void SAVE_PARA(void)
{
_DINT();
i_flash_ptr = (int *)0x1000;
FCTL1 = FWKEY + ERASE; //enable erasing
FCTL3 = FWKEY; //unlock
* i_flash_ptr = 0; //empty write to start erasing
FCTL1 = FWKEY + WRT; //enable writing
//-------------------------------------------------------
_NOP();
* i_flash_ptr++ = 0; //write
* i_flash_ptr++ = para_control.temp_set;
* i_flash_ptr++ = para_control.alARM_set;
* i_flash_ptr++ = para_control.comp_set;
* i_flash_ptr++ = para_control.pid_p;
* i_flash_ptr++ = para_control.pid_i;
* i_flash_ptr++ = para_control.pid_d;
* i_flash_ptr++ = para_control.control_t;
* i_flash_ptr++ = para_control.para_lock;
* i_flash_ptr++ = para_control.mv_0;
* i_flash_ptr++ = para_control.mv_400;
//---------------------------------------------------------------
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK; //lock
_EINT();
}
//---------------------------------------------------------------
void READ_PARA(void)
{
_DINT();
i_flash_ptr = (int *)0x1000;
i_flash_ptr ++;
para_control.temp_set = * i_flash_ptr++;
para_control.alARM_set = * i_flash_ptr++;
para_control.comp_set = * i_flash_ptr++;
para_control.pid_p = * i_flash_ptr++;
para_control.pid_i = * i_flash_ptr++;
para_control.pid_d = * i_flash_ptr++;
para_control.control_t = * i_flash_ptr++;
para_control.para_lock = * i_flash_ptr++;
para_control.mv_0 = * i_flash_ptr++;
para_control.mv_400 = * i_flash_ptr++;
_EINT();
} 答 2: 我写的程序跟你一样,是想通过Flash的信息存储区来存储参数,我的想法是在第一次系统启动时写入,以后程序每次运行只是读出。当我在一个程序中实现时,即先写入接着读出,则一切正确。但是我用两个程序实现,先运行一个程序写入,然后用另一个程序读出,则读出都是0xFFFF,不知是何故,是不曾写入还是读出错误? 答 3: 引用:
#define FLASH_ADDRESS 0x1080 //信息存储器中的地址
void Flash_ww(int * Data_ptr,int word)
{
FCTL3=FWKEY+WRT; //Lock=0
FCTL1=FWKEY; //WRT=1
*Data_ptr=word; //字编程
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK; //Lock=1
}
void Flash_clr(int * Data_ptr)
{
FCTL1=FWKEY+ERASE; //ERASE=1
FCTL3=FWKEY; //Lock=0
*Data_ptr=0; //段擦除
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK; //Lock=1
}
void display(int disData)
{
.................
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2=FWKEY+FSSEL0+FN0; // 定义FLASH时序发生器输入时钟
firstTime=(int *)FLASH_ADDRESS;
Flash_clr(firstTime);
Flash_ww(firstTime,0x1000);
display(*firstTime);
while(1);
}
请问擦除和写入函数有没有问题?我把Flash_clr(firstTime);去掉就可以显示出来数据,但数据当然不是0x1000。那位帮我看一下,先谢谢了! 答 1: 下面程序供参考!
void SAVE_PARA(void)
{
_DINT();
i_flash_ptr = (int *)0x1000;
FCTL1 = FWKEY + ERASE; //enable erasing
FCTL3 = FWKEY; //unlock
* i_flash_ptr = 0; //empty write to start erasing
FCTL1 = FWKEY + WRT; //enable writing
//-------------------------------------------------------
_NOP();
* i_flash_ptr++ = 0; //write
* i_flash_ptr++ = para_control.temp_set;
* i_flash_ptr++ = para_control.alARM_set;
* i_flash_ptr++ = para_control.comp_set;
* i_flash_ptr++ = para_control.pid_p;
* i_flash_ptr++ = para_control.pid_i;
* i_flash_ptr++ = para_control.pid_d;
* i_flash_ptr++ = para_control.control_t;
* i_flash_ptr++ = para_control.para_lock;
* i_flash_ptr++ = para_control.mv_0;
* i_flash_ptr++ = para_control.mv_400;
//---------------------------------------------------------------
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK; //lock
_EINT();
}
//---------------------------------------------------------------
void READ_PARA(void)
{
_DINT();
i_flash_ptr = (int *)0x1000;
i_flash_ptr ++;
para_control.temp_set = * i_flash_ptr++;
para_control.alARM_set = * i_flash_ptr++;
para_control.comp_set = * i_flash_ptr++;
para_control.pid_p = * i_flash_ptr++;
para_control.pid_i = * i_flash_ptr++;
para_control.pid_d = * i_flash_ptr++;
para_control.control_t = * i_flash_ptr++;
para_control.para_lock = * i_flash_ptr++;
para_control.mv_0 = * i_flash_ptr++;
para_control.mv_400 = * i_flash_ptr++;
_EINT();
} 答 2: 我写的程序跟你一样,是想通过Flash的信息存储区来存储参数,我的想法是在第一次系统启动时写入,以后程序每次运行只是读出。当我在一个程序中实现时,即先写入接着读出,则一切正确。但是我用两个程序实现,先运行一个程序写入,然后用另一个程序读出,则读出都是0xFFFF,不知是何故,是不曾写入还是读出错误? 答 3: 引用:
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |