串口发数据正常,对方也有回复,但就是单片机收不到,收数据中断也不进,回掉函数更没反应,怎么办?
void USARTx_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_USART2_CLK_ENABLE();
// __HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
/**USART2 引脚配置
PF0 ------> USART2_TX
PF1 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_USART2;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
// HAL_UART_Receive_IT(&huart2,(uint8_t *)&aRxBuffer,1);
}
/* USART2 init function */
void USART2_Init(u16 baud)
{
huart2.RxCpltCallback=UART2_RcvCpltCallBack;
huart2.Instance = USART2;
huart2.Init.BaudRate = baud;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
HAL_NVIC_ClearPendingIRQ(USART2_IRQn);
}