主机发送0xa2,从机接收主机发送的数据,判断接收到的数据是不是0xa2,如果从机接收到的数据是0xa2,从机发送:0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c给主机.但是主机接到的是:0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b.
```
uint16_t SPI2_ReadWriteByte(uint16_t TxData)
{
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); // 等待发送区空
SPI_I2S_SendData(SPI2, TxData); // 通过外设SPIx发送一个byte数据
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);// 等待接收完一个byte
return SPI_I2S_ReceiveData(SPI2); // 返回通过SPIx最近接收的数据
}
uint8_t SPI_TxBuffer[12] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c};
void SPI2_IRQHandler(void)
{
if(LL_SPI_IsActiveFlag_RXNE(SPI2)==SET){
SPI_IT_Rec=SPI2->DR;
if(SPI_IT_Rec == 0xa2){
for(uint8_t i=0;i<12;++i){
SPI_RxBuffer= ReadWriteData(SPI_TxBuffer);
}
SPI_Flag = 1;
}
}
}
```
|
|