STM8 SPI 例程 通信出錯
這是一段發(fā)2字節(jié)收2字節(jié)的代碼,注意如果第二個字節(jié)接收才有效的話,也需要發(fā)送第二個字節(jié)才能提供時鐘進(jìn)行接收:
本文引用地址:http://www.ex-cimer.com/article/201611/317109.htm- GPIO_WriteLow(GPIOA,GPIO_PIN_3);
- while(SPI_GetFlagStatus(SPI_FLAG_TXE)==RESET){}
- SPI_SendData(0x80|0x75);
- while(SPI_GetFlagStatus(SPI_FLAG_BSY)==SET){}
- while(SPI_GetFlagStatus(SPI_FLAG_RXNE)==RESET){}/*¸Ã×Ö½Ú¶ªÆú*/
- ret1=SPI_ReceiveData();
- while(SPI_GetFlagStatus(SPI_FLAG_TXE)==RESET){}
- SPI_SendData(0x75);
- while(SPI_GetFlagStatus(SPI_FLAG_BSY)==SET){}
- while(SPI_GetFlagStatus(SPI_FLAG_RXNE)==RESET){}
- ret2=SPI_ReceiveData();
- GPIO_WriteHigh(GPIOA,GPIO_PIN_3);
評論