1. 串口中斷實(shí)現(xiàn)
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標(biāo)志位
? ? ? ? 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. 調(diào)試現(xiàn)象具體描述:
????USART1_IRQHandler中斷時(shí)進(jìn)入過的,但是USART_IT_IDLE始終無法進(jìn)入,串口發(fā)送功能正常,接收只能時(shí)一個(gè)字節(jié)且是亂碼。