打印
[其他ST产品]

str710读写外部存储器问题

[复制链接]
2313|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
kinke|  楼主 | 2007-7-19 16:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在调试str710对外部存储器操作的程序。发现ID可以正确读出来,但写数据和读数据不行。因为我写数据和读数据子程序在写地址的时候,我是用同一个地址的,所以读出来的数据应该跟写进去的一样。但我发现我的读出来的跟写进去的数据一点联系都没有。不知道是什么原因啊?
沙发
kinke|  楼主 | 2007-7-19 16:58 | 只看该作者

部分代码如下

我用的是K9F2808U0C NAND FLASH芯片。各位大侠,帮忙看看
//*****读单字节子程序
//* Area A Bytes 0-255
//* Area B Bytes 256-511
u8 NandReadData(u32 address)
{
    u8 data_;
    Nand_CE_Active();
    GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS);
    if ( (address % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 )
                NandCommand(Nand_AreaB);           /* First  Half Page -  Area B*/
          else     NandCommand(Nand_AreaA);         /* Second Half Page -  Area A*/
    NandSendAddress(address);
    NOP();                                   //tWB = 100ns.
    mDelay(3);                               //wait tPROG 200~500us;
    while(!Nand_Ready());                // Read RnB Pin, Wait for Ready State
    data_ = NandDataOutput();
    UART_ByteSend(UART0, &data_);           //串口显示
    Nand_CE_noActive();
    return data_;
}

//******写单字节子程序
u8  NandWriteByte (u32 address, u8 data)
{
    Nand_CE_Active();
    GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS);
    if ( (address % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 )
                         NandCommand(Nand_AreaB);           /* Select Area B*/
                           else     NandCommand(Nand_AreaA);     /* Select Area A*/
       NandCommand(Nand_PageProgram);           //80H
    NandSendAddress(address);
    NandDataInput(data);
    NandCommand(Nand_EndPageProg);           //10H
    NOP();                                   //tWB = 100ns.
    mDelay(3);                               //wait tPROG 200~500us;
    while(!Nand_Ready());                // Read RnB Pin, Wait for Ready State
    while(!(NandReadStausRegister()&(NandReady|!NandError)));            //读状态,
    UART_ByteSend(UART0, &data);        //串口显示
    //mDelay(100);
    Nand_CE_noActive();
}
//******块擦除子程序
u32 NandBlockErase(u32 address)
{    
    u8 Staus;
    Nand_CE_Active();
    GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS);
       NandCommand(Nand_BlockErase);                      //60H
    NandSendCAddress(address);                          //address
       NandCommand(Nand_ConfirmErase);                      //D0H
    while(!Nand_Ready());                              //wait R/B=1?
    Staus=NandReadStausRegister();  
    if(Staus&0x1)                                      //判断I/O0状态
    {
       return 0;                                      //擦除不成功
    }
    else
    {
       return 1;                                      //擦除成功
    } 
    Nand_CE_noActive();
}
 

int main(void)
{
RCCU_MCLKConfig(RCCU_DEFAULT);                    // MCLK = RCLK
RCCU_FCLKConfig(RCCU_RCLK_2);                     // FCLK = RCLK/2
RCCU_PCLKConfig(RCCU_RCLK_4);                     // PCLK = RCLK/4
RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2);    // 48MHz PLL @ 16MHz XTAL

while (RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET); // Wait for PLL to Lock
RCCU_RCLKSourceConfig(RCCU_PLL1_Output);   // Select PLL for RCLK
......
......
......
然后在下面程序里调用:

if(NandBlockErase(NFBlcokAddr))                                //判断块擦除是否成功
{
    for(a=0;a<512;a++)
       {
         NandWriteByte (NFBlcokAddr, Wdata);    //成功则开始写数据
    NFBlcokAddr++;
    Wdata++;
       }
       for(a=0;a<512;a++)
      {
       NandReadData(NFBlcokAddr);
       NFBlcokAddr--;
       }                            
}
else
{
      UART_StringSend(UART0, (u8 *)&"BlockErase is Error!");//擦除不成功提示出错。
}
}

使用特权

评论回复
板凳
kinke|  楼主 | 2007-7-20 12:00 | 只看该作者

自己搞错了

不好意思,自己搞错了。是FLASH芯片型号看错了,所以地址送错了。哈哈。。新手。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

34

帖子

1

粉丝