在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 4575|回复: 2

45DB041B读写问题!!!!!!!

[复制链接]
发表于 2009-6-26 09:43:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
高手帮我看一下为什么读到这段指令while((AT45DB041B_StatusRegisterRead()&0x80)==0);死循环????

unsigned char SPI_HostReadByte(void) //读出
{
  unsigned char i,rByte=0;

  for(i=0;i<8;i++)
  {
    SPI_SCK0();
    SPI_SCK1();
    rByte<<=1;
  if((IOPIN0&SPI_SO)==1)rByte|=1;
  }
  return rByte;
}  

void SPI_HostWriteByte(unsigned char wByte)   //写入
{
  unsigned char i;
  for(i=0;i<8;i++)
  {
    if((wByte<<i)&0x80) {SPI_SI1();}
    else {SPI_SI0();
  }
    SPI_SCK0();
    SPI_SCK1();
  }
}

unsigned char AT45DB041B_StatusRegisterRead(void)
{
  unsigned char i;

  SPI_CS0();
  SPI_HostWriteByte(0xd7);
  i=SPI_HostReadByte();
  SPI_CS1();

  return i;
}

void AT45DB041B_ContinuousArrayRead(BOOL PA,BOOL BFA,unsigned char *pHeader,BOOL len){
  unsigned int i;

   while((AT45DB041B_StatusRegisterRead()&0x80)==0);
//   while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
  SPI_CS0();
  SPI_HostWriteByte(0xe8);
  SPI_HostWriteByte((unsigned char)(PA>>7));
  SPI_HostWriteByte((unsigned char)((PA<<1)|(BFA>>8)));
  SPI_HostWriteByte((unsigned char)BFA);
  for(i=0;i<4;i++){SPI_HostWriteByte(0x00);}

  for(i=0;i<len;i++){pHeader=SPI_HostReadByte();}
  SPI_CS1();

}
void AT45DB041B_BufferWrite(BYTE buffer,BOOL BFA,BYTE *pHeader,BOOL len){
  unsigned int i;

   while((AT45DB041B_StatusRegisterRead()&0x80)==0);
  //while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
  SPI_CS0();

  switch(buffer){
    case 1:SPI_HostWriteByte(0x84);break;
    case 2:SPI_HostWriteByte(0x87);break;
  }
  SPI_HostWriteByte(0x00);
  SPI_HostWriteByte((unsigned char)(BFA>>8));
  SPI_HostWriteByte((unsigned char)BFA);

  for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);}
  SPI_CS1();

}
void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(BYTE buffer,BOOL PA,BOOL BFA,BYTE *pHeader,BOOL len){
//   unsigned int i;

  AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
   while((AT45DB041B_StatusRegisterRead()&0x80)==0);
//   while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}

  SPI_CS0();
  switch(buffer){
    case 1:SPI_HostWriteByte(0x83);break;
    case 2:SPI_HostWriteByte(0x86);break;
  }
  SPI_HostWriteByte((unsigned char)(PA>>7));
  SPI_HostWriteByte((unsigned char)(PA<<1));
  SPI_HostWriteByte(0x00);
  SPI_CS1();

}
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(BYTE buffer,BOOL PA,BOOL BFA,BYTE *pHeader,BOOL len){
  unsigned int i=0;

  AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
   while((AT45DB041B_StatusRegisterRead()&0x80)==0);
//   while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}

  SPI_CS0();
  SPI_HostWriteByte(0x87+buffer);
  SPI_HostWriteByte((unsigned char)(PA>>7));
  SPI_HostWriteByte((unsigned char)(PA<<1));
  SPI_HostWriteByte(0x00);

//   for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);}
  SPI_CS1();

}
发表于 2009-7-4 20:28:26 | 显示全部楼层
应该进一步跟一下具体死在哪了
发表于 2009-7-5 10:02:23 | 显示全部楼层
AT45DB041B_StatusRegisterRead()函数里,不应该反复对片选操作,只要不断发送CLK,读取新状态数据就行了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-3-11 01:05 , Processed in 0.018320 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表