int main(void)
{
HAL_Init();
SystemClock_Config();
Uart1_Init();
Uart1_Config();
if(HAL_UART_Receive_IT(&huart,&aRxBuffer,1)!=HAL_OK)
HAL_UART_Transmit(&huart, (uint8_t *)&"ERROR
",7,10);
while (1);
}
void Uart1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void Uart1_Config(void)
{
huart.Instance = USART1;
huart.Init.BaudRate = 9600;
huart.Init.WordLength = UART_WORDLENGTH_8B;
huart.Init.StopBits = UART_STOPBITS_1;
huart.Init.Parity = UART_PARITY_NONE;
huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart.Init.Mode = UART_MODE_TX_RX;
if(HAL_UART_DeInit(&huart) != HAL_OK)
{
}
if(HAL_UART_Init(&huart) != HAL_OK)
{
}
HAL_NVIC_SetPriority(USART1_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART1_IRQn);
}
void USART1_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(huart,&aRxBuffer,1);
}
以上代码用于测试串口接收中断,接收中断能进去,但是回调函数HAL_UART_RxCpltCallback就是进不去,我已经纠结好多天了,请各位高手帮忙看看是哪里出了问题,在线等,谢谢
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
HAL_UART_Receive_IT(&huart1,&Res,1);//该函数会开启接收中断:标志位UART_IT_RXNE,并且设置接收缓冲以及接收缓冲接收最大数据量
一周热门 更多>