讀取部分:
uint8_t spiFlashReadData(uint32_t spiAddr, uint32_t DataLen, uint32_t *pDataBuf)
{
uint32_t i;
if(TempSpiPort == NULL)
return SPI_FLASH_ERROR;
if(SPI_IsBusy(TempSpiPort)== TRUE)
return SPI_FLASH_ERROR;
// command (8bit)
SPI_SetBitLength(TempSpiPort, 8);
spiTxData[0] = SPI_FLASH_CMD_READ_DATA;
SPI_SetTxRegister(TempSpiPort, &spiTxData[0], 1);
SPI_SetSS(TempSpiPort, SPI_SS0);
SPI_SetGo(TempSpiPort);
while(SPI_IsBusy(TempSpiPort));
// address (24bit)
SPI_SetBitLength(TempSpiPort, 24);
spiTxData[0] = spiAddr;
SPI_SetTxRegister(TempSpiPort, &spiTxData[0], 1);
SPI_SetGo(TempSpiPort);
while(SPI_IsBusy(TempSpiPort));
// data (32bit*n)//更改部分 8->32
SPI_SetBitLength(TempSpiPort, 32);
spiTxData[0] = 0xffffff;
for (i=0; i<DataLen; i++)
{
SPI_SetTxRegister(TempSpiPort, &spiTxData[0], 1);
SPI_SetGo(TempSpiPort);
while(SPI_IsBusy(TempSpiPort));
SPI_DumpRxRegister(TempSpiPort, &spiRxData[0], 1);
*(pDataBuf++) = spiRxData[0]&0xffffff;
}
SPI_ClrSS(TempSpiPort, SPI_SS0);
return SPI_FLASH_DONE;
} |