1. stm32的spi双机通信问题我的stm32 spi全双工通信,主机可以发送数据,从机可以接收数据,但是主机接受不到从机发送的数据,请大家帮帮忙stmsky 发表于 2010-4-29 08:54
主机接收从机发来的数据的时候,要主动发送DUMMY字节提供时钟 http://www.stmsky.com/bbs/archiver/tid-4048.html
2. http://zhangyang.ip8.jspcn.net/posts/list/476.htm
- 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 */;
-
}
|