我在T0_EXT(PA7)上装了一个按键,每次按键触发CAPIF中断好几次,并且捕获值一直为零 主函数代码如下:int32_t main(void) { //初始始化部份省略 NVIC_EnableIRQ(TMR0_IRQn); tiMER_Open(TIMER0, TIMER_CONTINUOUS_MODE, 1); TIMER_SET_PRESCALE_VALUE(TIMER0, 0); TIMER_SET_CMP_VALUE(TIMER0, 0xFFFFFF); TIMER_EnableEventCounter(TIMER0, TIMER_COUNTER_FALLING_EDGE);//使能事件计 数模式 TIMER_EnableCapture(TIMER0, TIMER_CAPTURE_FREE_COUNTING_MODE, TIMER_CAPTURE_FALLING_EDGE);//使能捕获模式 TIMER_EnableCaptureDebounce(TIMER0); TIMER_EnableInt(TIMER0); TIMER_EnableCaptureInt(TIMER0); TIMER_Start(TIMER0); for(;;); return 0; } 中断函数 static int cnt=0; void TMR0_IRQHandler(void) { if(TIMER_GetCaptureIntFlag(TIMER0) == 1) { uint32_t au32CAPValue; /* Clear Timer0 capture trigger interrupt flag */ au32CAPValue = TIMER_GetCaptureData(TIMER0) TIMER_ClearCaptureIntFlag(TIMER0); printf("capture int_cnt=%d , captureVal=%d \n",cnt++,au32CAPValue); } } |
更多回帖