微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > stm32 SPI 读取和写入的问题

stm32 SPI 读取和写入的问题

时间:11-17 来源:互联网 点击:
stm32 SPI读取和写入和USART 一样需要判断标志位

unsigned char SPI1_ReadWrite(unsigned char writedat)

{

/* Loop while DR register in not emplty */

while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET);

/* Send byte through the SPI1 peripheral */

SPI_I2S_SendData(SPI1, writedat);

/* Wait to receive a byte */

while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

/* Return the byte read from the SPI bus */

return SPI_I2S_ReceiveData(SPI1);

}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top