void user_Uart1Handler()
{
if((__HAL_UART_GET_FLAG(&huart1,UART_FLAG_RXNE)!=RESET))
{
if(uart1RxState==UART_RX_STATE_READY) //接收到一帧中的第一个字节
{
uart1RxState=UART_RX_STATE_START;
__HAL_UART_ENABLE_IT(&huart1,UART_IT_IDLE); //打开空闲中断
uart1RxCounter=0; //计数清零
uart1RxBuf[uart1RxCounter]=(uint8_t)(huart1.Instance->DR & (uint8_t)0x00FF);
uart1RxCounter++;
}
else if(uart1RxState==UART_RX_STATE_START)
{
uart1RxBuf[uart1RxCounter]=(uint8_t)(huart1.Instance->DR & (uint8_t)0x00FF);
uart1RxCounter++;
}
__HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_RXNE);
}
if((__HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE)!=RESET)) //进入空闲中断
{
__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_IDLE); //关了空闲中断
__HAL_UART_DISABLE_IT(&huart1,UART_IT_RXNE); //关了接收完成中断
uart1RxState=UART_RX_STATE_DEAL; //状态表明一帧数据接收完成了,需要处理。处理完以后再把接收中断打开
}
}
|