所以使用 SPI 读写我们可以写为:
uint8_t SPI2_WriteReadData(uint8_t dat)
{
uint16_t i = 0;
/* 当发送缓冲器空 */
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET)
{
i++;
if(i > 10000)
{
eturn 0xFF;
}
}
/* 发送数据 */
SPI_I2S_SendData(SPI2, dat);
/* 等待接收缓冲器为非空 */
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) ==
RESET);
/* 将读取到的数值返回 */
return SPI_I2S_ReceiveData(SPI2);
}
|