使用CH32V035系列CH32V033,PA10是方波輸入,用作外中斷,中斷后再另一腳輸出翻轉(zhuǎn)波形來監(jiān)測中斷,發(fā)現(xiàn)2個(gè)問題:1是無論是上升沿、下降沿、還是雙沿觸發(fā),中斷都可能在雙沿觸發(fā);2是總是有些邊沿不觸發(fā)或觸發(fā)兩次。請(qǐng)教,不知道是否有哪些地方?jīng)]處理到?只用了一個(gè)IO做外中斷。
初始化
/*********************************************************************
?* @fn? ? ? EXTI0_INT_INIT
?*
?* @brief? ?Initializes EXTI0 collection.
?*
?* @return? none
?*/
void EXTI0_INT_INIT(void)
{
? ? GPIO_InitTypeDef GPIO_InitStructure = {0};
? ? EXTI_InitTypeDef EXTI_InitStructure = {0};
? ? NVIC_InitTypeDef NVIC_InitStructure = {0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
? ? GPIO_Init(GPIOA, &GPIO_InitStructure);
? ? /* GPIOA ----> EXTI_Line0 */
? ? GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource10);
? ? EXTI_InitStructure.EXTI_Line = EXTI_Line10;
? ? EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
? ? EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
//? ? EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
? ? EXTI_InitStructure.EXTI_LineCmd = ENABLE;
? ? EXTI_Init(&EXTI_InitStructure);
? ? NVIC_InitStructure.NVIC_IRQChannel = EXTI15_8_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
}
中斷處理
void EXTI15_8_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
?* @fn? ? ? TIM2_CC_IRQHandler
?*
?* @brief? ?This function handles TIM2? Capture Compare Interrupt exception.
?*
?* @return? none
?*/
void EXTI15_8_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line10)!=RESET)
{
? EXTI_ClearITPendingBit(EXTI_Line10); ? /* Clear Flag */
? kk++;
? ? ? ? if (kk&1)
? ? ? ? ? ? his_led_on();
? ? ? ? else {
? ? ? ? ? ? his_led_off();
? ? ? ? }
? ? }
}