u8 SPIx_ReadWriteByte(u8 data)
{
u8 retry=0;
/* Loop while DR register in not emplty */
//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET)
while (SPI1->SR & SPI_I2S_FLAG_TXE == RESET)
{
retry++;
if(retry>200)return 0;
}
// SPI_I2S_SendData(SPI1,data);//??????·?????????
SPI1->DR = data;
/* Wait to receive a byte */
//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) //?ì?é???¨??SPI±ê?????è????·?:????????·???±ê????
retry = 0;
while( SPI1->SR & SPI_I2S_FLAG_RXNE == RESET )
{
retry++;
if(retry>200)return 0;
}
/* Return the byte read from the SPI bus */
return (uint16_t)SPI1->DR; //SPI_I2S_ReceiveData(SPI1); //·????¨??SPIx×??ü??????????
//**********?????????????÷??????????*******************
}
把最后的return语句改成 return SPI1->DR; 总是写不了flash,总是卡住。但是改成SPI_I2S_ReceiveData(SPI1);就可以读写了。
但是SPI_I2S_ReceiveData(SPI1);里面的实现也是 return SPIx->DR啊,为什么会有这样的差别。 |