本文介绍了如何在stm32的相同回调函数中从不同的uart获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am using the stm32f407 controller. I am using 2 uart - 2&3. I got interrupted the first time, but the second time I got interrupted on uart 2 - I did not get interrupted on uart3.
Below is my callback function:
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart2.Instance == USART2)
{
gsm.RxData[gsm.RxDataCnt]=Uart_Rx_Buffer;
gsm.RxDataCnt=(1+ gsm.RxDataCnt) % MAX_Buff_Size;
HAL_UART_Receive_IT(&huart2,&Uart_Rx_Buffer, 1);
}
else if(huart3.Instance == USART3)
{
lidar.RxData[lidar.RxDataCnt]=uart3_RX_Data;
lidar.RxDataCnt=(1+ lidar.RxDataCnt) % MAX_LIDAR_BUFFER;
HAL_UART_Receive_IT(&huart3,&uart3_RX_Data, 1);
if(lidar.RxDataCnt >MAX_COUNT_BUFFER)
{
lidar.received = true;
}
}
}
解决方案
The conditions in the if
-statements are always true. You need to check the instance of the huart
handle provided in the function argument, i.e.:
if(huart->Instance == USART2)
and
else if(huart->Instance == USART3)
这篇关于如何在stm32的相同回调函数中从不同的uart获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!