注意到了需要增加void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
但還是只進(jìn)入一次,請問這和編譯優(yōu)化相關(guān)有關(guān)系嗎?或是哪里的問題?
串口源碼如下:
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USARTx_Init(u32 baudRate)
{
? ? GPIO_InitTypeDef? GPIO_InitStructure = {0};
? ? USART_InitTypeDef USART_InitStructure = {0};
? ? NVIC_InitTypeDef? NVIC_InitStructure = {0};
? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
? ? // USART2 RX-->A.3
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
? ? GPIO_Init(GPIOA, &GPIO_InitStructure);
? ? 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_Rx;
? ? USART_Init(USART2, &USART_InitStructure);
? ? USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
? ? NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
? ? USART_Cmd(USART2, ENABLE);
}
void USART2_IRQHandler(void)
{
? ? if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
? ? {
? ? ? ? //......
? ? ? ? USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
? ? }
}