我对SPI同步有问题。同步总是搞砸了。在逻辑分析仪上,我看到信号不在正确的位置。我真的不知道有什么问题。任何想法都欢迎。
听觉是用于同步的主代码:
#define SPI_SLAVE_SYNBYTE 0x53
#define SPI_MASTER_SYNBYTE 0xAC
uint8_t txackbytes = SPI_MASTER_SYNBYTE;
uint8_t rxackbytes = 0;
do
{
if(HAL_SPI_TransmitReceive_IT(&hspi1,(uint8_t *)&txackbytes, (uint8_t *)&rxackbytes, 1) != HAL_OK)
{
Error_Handler();
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY){}
}while (rxackbytes!= SPI_SLAVE_SYNBYTE);
从站代码:
uint8_t txackbyte = SPI_SLAVE_SYNBYTE;
uint8_t rxackbyte = 0;
do
{
if (HAL_SPI_TransmitReceive_IT(&hspi1, (uint8_t *)&txackbyte, (uint8_t *)&rxackbyte, 1) != HAL_OK)
{
Error_Handler();
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY){}
}while (rxackbyte != SPI_MASTER_SYNBYTE);