This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SM470对AT45DB642进行读写,但写进去的数和读出来的数不一致

uint8 SPI_FLASH_SendByte(uint8 byte)   //SPI.pdf
{
    SPI_FLASH_CS_HIGH();
   

    SPI2DAT0 = byte;                    //send the byte to the slave device
    while(!(SPI2CTRL3 & 0x01));        // Wait for RxFlag to get set   // Read SPIBUF
    return SPI2DAT0;  
}

void FLASH8MB_BUFFER_WRITE(uint8 *pBuffer,uint32 WriteAddress )
{
    uint16 i;
    if(FlashWaitBusy()==0)return;                                           
    SPI_FLASH_CS_LOW();             //selected the Flash chip: chip select low
    SPI_FLASH_SendByte(0x84);
    SPI_FLASH_SendByte(((WriteAddress & 0xFF0000) >> 16));
    SPI_FLASH_SendByte((WriteAddress& 0xFF00) >> 8);
    SPI_FLASH_SendByte((WriteAddress & 0xFF));
    for(i=0;i<10;i++)
    {
      SPI_FLASH_SendByte(*pBuffer);
      pBuffer++  ;
      printf("%d\r\n",(*pBuffer));
    }
    SPI_FLASH_CS_HIGH();

}

 

void FLASH8MB_BUFFER_READ(uint32 ReadAddress )
{
 
    uint16 i;
    uint16 buffer[10];
    if(FlashWaitBusy()==0)return;                                           
    SPI_FLASH_CS_LOW();             //selected the Flash chip: chip select low
    SPI_FLASH_SendByte(0xD1);
    SPI_FLASH_SendByte(((ReadAddress & 0xFF0000) >> 16));
    SPI_FLASH_SendByte((ReadAddress& 0xFF00) >> 8);
    SPI_FLASH_SendByte((ReadAddress & 0xFF));
       
    for(i=0;i<10;i++)
    {
   while(!(SPI2CTRL3_bit.RXINTFLAG));
   buffer[i]=SPI2BUF;
   printf("%d\r\n",buffer[i]);

    }
   SPI_FLASH_CS_HIGH();
}

 这是对缓冲区进行读写的程序,不知道问题出在哪儿,写进去的数和读出来的数不一致,求各路大神指导指导!

  • uint8 SPI_FLASH_SendByte(uint8 byte)   //SPI.pdf
    {
        SPI_FLASH_CS_HIGH();
       

        SPI2DAT0 = byte;                    //send the byte to the slave device
        while(!(SPI2CTRL3 & 0x01));        // Wait for RxFlag to get set   // Read SPIBUF
        return SPI2DAT0;   
    }

    这个是关键点吧?这个标志寄存器是如何清零的呢?建议在进入这个函数第一个指令对该位清零,然后在拉高,发送数据,反正在发送数据前确保清零,这样只会判断时候才是正确的。试试看。