|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
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();
}
|
|