void USART3_4_IRQHandler(void)
{
/* USER CODE BEGIN USART3_4_IRQn 0 */
/* USER CODE END USART3_4_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
HAL_UART_IRQHandler(&huart4);
/* USER CODE BEGIN USART3_4_IRQn 1 */
/* USER CODE END USART3_4_IRQn 1 */
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART3)
{
HAL_UART_Receive_IT(&huart3, &U3_RxDat_Tmp, 1);
if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) == SET)
{
__HAL_UART_CLEAR_IDLEFLAG(&huart3);
}
if(U3_Rx_Index >= U3_RXBUFFER_SIZE)
U3_Rx_Index = U3_RXBUFFER_SIZE - 1;
U3_RxBuf[U3_Rx_Index] = U3_RxDat_Tmp;
U3_Rx_Index++;
U3_Rx_Delay = 5;
}
else if(huart->Instance == USART4)//RS485
{
HAL_UART_Receive_IT(&huart4, &U4_RxDat_Tmp, 1);
if(U4_Rx_Index >= U4_RXBUFFER_SIZE)
U4_Rx_Index = U4_RXBUFFER_SIZE - 1;
U4_RxBuf[U4_Rx_Index] = U4_RxDat_Tmp;
U4_Rx_Index++;
U4_Rx_Delay = 5;
}
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART3)
{
__HAL_UART_CLEAR_IT(&huart3, UART_CLEAR_TCF);
__HAL_UART_DISABLE_IT(&huart3, UART_IT_TC);
}
else if(huart->Instance == USART4)
{
__HAL_UART_CLEAR_IT(&huart4, UART_CLEAR_TCF);
__HAL_UART_DISABLE_IT(&huart4, UART_IT_TC);
U4_Rx_Enable();
HAL_UART_Receive_IT(&huart4, &U4_RxDat_Tmp, 1);
}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART3)
{
HAL_UART_Receive_IT(&huart3, &U3_RxDat_Tmp, 1);
__HAL_UART_CLEAR_IDLEFLAG(&huart3);
// __HAL_UART_ENABLE_IT(&huart3, UART_IT_ERR);
__HAL_UART_ENABLE_IT(&huart3, UART_IT_RXNE);
}
else if(huart->Instance == USART4)
{
__HAL_UART_CLEAR_IT(&huart4, UART_CLEAR_NEF);
__HAL_UART_CLEAR_IT(&huart4, UART_CLEAR_FEF);
__HAL_UART_CLEAR_IT(&huart4, UART_CLEAR_OREF);
__HAL_UART_CLEAR_IT(&huart4, UART_CLEAR_TCF);
__HAL_UART_DISABLE_IT(&huart4, UART_IT_TC);
U4_Rx_Enable();
HAL_UART_Receive_IT(&huart4, &U4_RxDat_Tmp, 1);
}
} |