智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 4302|回复: 4
打印 上一主题 下一主题

XS128写p_flash的问题

[复制链接]

2

主题

3

帖子

0

精华

注册会员

Rank: 2

积分
161
QQ
威望
230
贡献
21
兑换币
0
注册时间
2010-3-18
在线时间
5 小时
跳转到指定楼层
1#
发表于 2010-5-18 22:09:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我想在XS128的P_flash上写点数据。。
在认真看了技术文档之后,我写了如下代码。。

void delayflash(uint j)
{

  uchar i;
  for(;j>0;j--)
  for(i=20;i>0;i--);
}

void Start_Command()
{
  FSTAT_CCIF = 1;//To start the command.
}

void Wait_Complete_Command()
{
  while(FSTAT_CCIF == 0);
}


void Pre_Start()
{

if(FCLKDIV_FDIVLD ==0)
FCLKDIV |= 0x0f;  //设置时钟分频,外部晶振为16Mhz

}


void Write_P_Flash(uint value)
{
  uchar number;
  uchar count=0;
  
  for(number=1;number>0;number--)
  {

     Pre_Start();
     
     if(FSTAT_CCIF)
     {
        if(FSTAT_ACCERR)
        {
         
          FSTAT_ACCERR = 1;
          delayflash(100);   
        }
        if(FSTAT_FPVIOL)
        {
         
          FSTAT_FPVIOL = 1;
          delayflash(100);
        }
        FCCOBIX=0;
        FCCOB=0X067F;
        
        FCCOBIX =1;
        FCCOB = des_addr;
   
        FCCOBIX=2;
        FCCOB=0xee;
  
        FCCOBIX=3;
        FCCOB=0xcc;

        FCCOBIX=4;
        FCCOB=0xdd;

        FCCOBIX=5;
        FCCOB=0xaa;

        des_addr+=8;     
      Start_Command();
      
      Wait_Complete_Command();
     }
   
  }

void main()
{
    ..........
    des_addr=0x4000;
    Write_P_Flash(0xee);
    Write_P_Flash(0xdd);
    ..........
}

参考了pdf文档中的如下描述
关于选频。。
When the FCLKDIV register is written, the FDIVLD bit is set automatically. If the FDIVLD bit is 0, the
FCLKDIV register has not been written since the last reset. If the FCLKDIV register has not been written,
any Flash program or erase command loaded during a command write sequence will not execute and the
ACCERR bit in the FSTAT register will set.
关于写命令。。
NVM command mode uses the indexed FCCOB register to provide a command code and its relevant
parameters to the Memory Controller. The user first sets up all required FCCOB fields and then initiates
the command’s execution by writing a 1 to the CCIF bit in the FSTAT register (a 1 written by the user
clears the CCIF command completion flag to 0). When the user clears the CCIF bit in the FSTAT register
all FCCOB parameter fields are locked and cannot be changed by the user until the command completes
(as evidenced by the Memory Controller returning CCIF to 1). Some commands return information to the
FCCOB register array.
关于写命令前的注意事项。。
Before launching a command, the ACCERR and FPVIOL bits in the FSTAT register must be clear (see
Section 19.3.2.7) and the CCIF flag should be tested to determine the status of the current command write
sequence. If CCIF is 0, the previous command write sequence is still active, a new command write
sequence cannot be started, and all writes to the FCCOB register are ignored.


现在的问题是。。执行一次写操作没问题,(无论是单步调试还是让程序自由运行)

可是如果让他执行两次写操作。。那么。。
再第二次执行 Start_Command()后FSTAT寄存器的MGSTAT[1:0]两位全部至1,并导致写失败。

一度以为是flash地址保护的原因,选了不同的地址段,并查看了FPROT寄存器的值,发现不是。。
另外,在写操作前我也尝试加了不少延时,不过,没什么效果。比较郁闷了。


。。。。

1

主题

8

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
268
威望
234
贡献
28
兑换币
0
注册时间
2010-5-26
在线时间
3 小时
2#
发表于 2010-6-5 15:40:18 | 只看该作者
你好,我刚刚接触flash,用你的这个程序调试时,在memory的哪个区域寻找写入的数据啊??
回复 支持 反对

使用道具 举报

1

主题

8

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
268
威望
234
贡献
28
兑换币
0
注册时间
2010-5-26
在线时间
3 小时
3#
发表于 2010-6-5 21:09:08 | 只看该作者
你好,今天我发现了你的问题所在了,擦出flash的前提是CCIF位为0,希望对你有帮助……
回复 支持 反对

使用道具 举报

0

主题

28

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
266
威望
219
贡献
35
兑换币
6
注册时间
2011-4-16
在线时间
6 小时
4#
发表于 2011-4-17 15:06:03 | 只看该作者
hao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-6-17 09:17 , Processed in 0.048853 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表