我有一个单片机读AT45DB041B程序,经常里面的数据丢失,是怎么一回事呀.可以帮我看看吗? #include<AT45DB.h>
void SPI_MasterSend(uchar SData) { SPDAT = SData; while(!(SPSTAT & 0x80)) { ; } SPSTAT = 0xc0; }
uchar AT45DB_SPI_Read(void) { uchar R_Data; SPI_MasterSend(0x00); R_Data = SPDAT; return R_Data; }
uchar AT45DB_Read_State(void) { uchar m_nBusy; AT45DB_CS = 0; SPI_MasterSend(0xd7); m_nBusy =AT45DB_SPI_Read(); AT45DB_CS = 1; return m_nBusy; }
void AT45DB_ContinuousArrayRead(uint Page_Addr,uint Page_InAddr,uchar *R_Data,uchar Length) { uchar i; while(!(AT45DB_Read_State() & 0x80)) { ; } AT45DB_CS = 0; SPI_MasterSend(0xe8); SPI_MasterSend((uchar)(Page_Addr >> 7)); SPI_MasterSend((uchar)((Page_Addr << 1) | (Page_InAddr >> 8))); SPI_MasterSend((uchar)(Page_InAddr)); SPI_MasterSend(0x00); SPI_MasterSend(0x00); SPI_MasterSend(0x00); SPI_MasterSend(0x00); for(i=0;i<Length;i++) { R_Data = AT45DB_SPI_Read(); } AT45DB_CS = 1; return; }
void AT45DB_Write_To_Page_AutoErase(uchar Buffer,uint Buffer_Addr,uint Page_Addr,uchar *W_Data,uchar Length) { uchar i; while(!(AT45DB_Read_State() & 0x80)) { ; } AT45DB_CS = 0; switch (Buffer) { case 1: { SPI_MasterSend(0x82); break; } case 2: { SPI_MasterSend(0x85); break; } default : { AT45DB_CS = 1; return; } } SPI_MasterSend((uchar)(Page_Addr >> 7)); SPI_MasterSend((uchar)((Page_Addr << 1) | (Buffer_Addr >> 8))); SPI_MasterSend((uchar)(Buffer_Addr)); for(i=0;i<Length;i++) { SPI_MasterSend(W_Data); } AT45DB_CS = 1; return; }
|