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
  1. static u8 SPI_Read_Byte(void)
  2. {
  3.   //等待发送信号寄存器为非空,然后发送一个字节到spi总线上
  4.   while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  5.   SPI_I2S_SendData(SPI1, 0x00);

  6.   //等待接收信号寄存器为非空,然后从spi总线上接收一个字节
  7.   while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) /* Wait to receive a byte */;
  8.   return SPI_I2S_ReceiveData(SPI1) /* Return the byte read from the SPI bus */;
  9. }

  10. //spi 写一个字节
  11. static void SPI_Write_Byte(u8 byte)
  12. {
  13.   //时序同发生字节一样,只是不返回读取的字节
  14.   while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) /* Loop while DR register in not emplty */;
  15.   SPI_I2S_SendData(SPI1, byte)/* Send byte through the SPI2 peripheral */;

  16.   while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) /* Wait to receive a byte */;
  17.   SPI_I2S_ReceiveData(SPI1) /* Return the byte read from the SPI bus */;
  18. }















09-08 11:36