CH32V203串口中斷只進(jìn)入一次

注意到了需要增加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);

? ? }

}


您好,根據(jù)代碼,你在中斷函數(shù)中將中斷關(guān)閉了。注意中斷函數(shù)中要注意清除對(duì)應(yīng)的中斷標(biāo)志位,此外,若中斷函數(shù)中有關(guān)中斷的操作,再次使用時(shí)要開啟。

image.png


感謝!確認(rèn)了是開中斷有問題,改用請標(biāo)志位驗(yàn)證,就一直有數(shù)據(jù)了


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频