void USARTx_Init(USART_TypeDef *USARTx, uint32_t baudrate) { USART_InitTypeDef USART_InitStructure = {0}; USART_InitStructure.USART_BaudRate = baudrate; 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_Init(USARTx, &USART_InitStructure); USART_ITConfig(USARTx, USART_IT_IDLE, ENABLE); USART_ClearFlag(USARTx, USART_IT_IDLE); USART_Cmd(USARTx, ENABLE); } void USART2_IRQHandler(void) { if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET) { com2_info.rx_flag = 1; com2_info.rx_len = com2_info.rx_max - DMA_GetCurrDataCounter(DMA1_Channel6); DMA_Cmd(DMA1_Channel6, DISABLE);\ USART_ClearFlag(USART2, USART_IT_IDLE); } }
使能了空闲中断,可是不进串口中断
热门产品 :
CH641: PD及无线充电专用MCU