高级会员

- 积分
- 784
- 金钱
- 784
- 注册时间
- 2010-12-19
- 在线时间
- 5 小时
|
发表于 2011-3-27 20:05:51
|
显示全部楼层
static u8 SPI_Read_Byte(void)
{
//等待发送信号寄存器为非空,然后发送一个字节到spi总线上
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, 0x00);
//等待接收信号寄存器为非空,然后从spi总线上接收一个字节
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) /* Wait to receive a byte */;
return SPI_I2S_ReceiveData(SPI1) /* Return the byte read from the SPI bus */;
}
//spi 写一个字节
static void SPI_Write_Byte(u8 byte)
{
//时序同发生字节一样,只是不返回读取的字节
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) /* Loop while DR register in not emplty */;
SPI_I2S_SendData(SPI1, byte)/* Send byte through the SPI2 peripheral */;
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) /* Wait to receive a byte */;
SPI_I2S_ReceiveData(SPI1) /* Return the byte read from the SPI bus */;
} |
|