解决方案:
中断函数如下:
- void USART1_IRQHandler(void)
- {
- u8 USART1_RX_LEN = 0;
-
- if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //串口1空闲中断
- {
- USART1->DR;
- }else if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
- {
- USART_ITConfig(USART1, USART_IT_IDLE, DISABLE);
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
-
- USART1_RX_LEN = USART1_MAX_RX_LEN - DMA1_Channel5->CNDTR; //接收到的字节数
- DMA_Cmd(DMA1_Channel5, DISABLE ); //关闭USART1 TX DMA1 所指示的通道
- DMA1_Channel5->CNDTR = USART1_MAX_RX_LEN; //DMA通道的DMA缓存的大小,重置CNDTR
- DMA_Cmd(DMA1_Channel5, ENABLE );
- }else
- {
- USART1->SR;
- USART1->DR; //软件序列清除IDLE标志位
- USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
- USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
- }
- }
|