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();
}
这是对缓冲区进行读写的程序,不知道问题出在哪儿,写进去的数和读出来的数不一致,求各路大神指导指导!