1. 串口中断实现
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
//hwUart_Callback();
}
if (USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
{
USART1->STATR;
USART1->DATAR;//清除IDLE标志位
hwUart_Callback();
}
}
2. 注册中断
USART_ITConfig((USART_TypeDef*)UARTN[uartn], USART_FLAG_IDLE, ENABLE);//注册IDLE中断
USART_ITConfig((USART_TypeDef*)UARTN[uartn], USART_FLAG_RXNE, ENABLE);//注册RXNE中断
3. gpio初始化
gpio_init(A9, GPO, 0, SPEED_50MHZ|OUT_AF_PP);
gpio_init(A10, GPI, 0, IN_FLOAT);
4. 串口配置
USART_InitStructure.USART_BaudRate = baud;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
// USART_InitStructure.USART_Mode = USART_Mode_Rx;
//使能串口
USART_Init((USART_TypeDef*)UARTN[uartn], &USART_InitStructure);
USART_Cmd((USART_TypeDef*)UARTN[uartn], ENABLE);
5. 调试现象具体描述:
USART1_IRQHandler中断时进入过的,但是USART_IT_IDLE始终无法进入,串口发送功能正常,接收只能时一个字节且是乱码。