Other Parts Discussed in Thread: MSP430FR6989
I am using MSP430FR6989 Timer B for Capture interrupt.
Initialization:
void init_timer() {
Timer_A_initContinuousModeParam initContParam = { 0 }; //Timer A
initContParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK; //32.768KHz clock used for timer
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;//No divider
initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; //Compare interrupt used
initContParam.timerClear = TIMER_A_DO_CLEAR;//clear previous interrupts, if any
initContParam.startTimer = false; //dont start immediately
Timer_B_initContinuousModeParam initContParamb = { 0 }; //Timer B
initContParamb.clockSource = TIMER_B_CLOCKSOURCE_ACLK; //32.768KHz clock used for timer
initContParamb.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1;//No divider
initContParamb.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_DISABLE; //Compare interrupt used
initContParamb.timerClear = TIMER_B_DO_CLEAR;//clear previous interrupts, if any
initContParamb.startTimer = false; //dont start immediately
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam); //Base 1
Timer_A_initContinuousMode(TIMER_A0_BASE, &initContParam); //Base 0
Timer_A_initContinuousMode(TIMER_A2_BASE, &initContParam); //Base 2
Timer_B_initContinuousMode(TIMER_B0_BASE, &initContParamb); //Timer B
//Initiaze compare mode
Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE, //Base 1
TIMER_A_CAPTURECOMPARE_REGISTER_0);
Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, //Base 0
TIMER_A_CAPTURECOMPARE_REGISTER_0);
Timer_A_clearCaptureCompareInterrupt(TIMER_A2_BASE, //Base 2
TIMER_A_CAPTURECOMPARE_REGISTER_0);
Timer_B_clearCaptureCompareInterrupt(TIMER_B0_BASE, //Timer B
TIMER_B_CAPTURECOMPARE_REGISTER_2);
Timer_A_initCompareModeParam initCompParam_b_1 = { 0 }; //Base 1
initCompParam_b_1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0;
initCompParam_b_1.compareInterruptEnable =
TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
initCompParam_b_1.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
initCompParam_b_1.compareValue = COMPARE_VALUE_B_1;
Timer_A_initCompareModeParam initCompParam_b_0 = { 0 }; //Base 0 //Button debounce timer(20ms)
initCompParam_b_0.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0;
initCompParam_b_0.compareInterruptEnable =
TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
initCompParam_b_0.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
initCompParam_b_0.compareValue = DEBOUNCE_20MS;
Timer_A_initCompareModeParam initCompParam_b_2 = { 0 }; //Base 2
initCompParam_b_2.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0;
initCompParam_b_2.compareInterruptEnable =
TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
initCompParam_b_2.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
initCompParam_b_2.compareValue = COMPARE_VALUE_B_2;
Timer_B_initCaptureModeParam initCapParam_b_3 ={ 0 }; //Timer b
initCapParam_b_3.captureRegister = TIMER_B_CAPTURECOMPARE_REGISTER_2;
initCapParam_b_3.captureMode = TIMER_B_CAPTUREMODE_FALLING_EDGE;
initCapParam_b_3.captureInputSelect = TIMER_B_CAPTURE_INPUTSELECT_CCIxA;
initCapParam_b_3.captureInterruptEnable = TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLE;
initCapParam_b_3.synchronizeCaptureSource = TIMER_B_CAPTURE_SYNCHRONOUS;
Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam_b_1); //Base 1
Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam_b_0); //Base 0
Timer_A_initCompareMode(TIMER_A2_BASE, &initCompParam_b_2); //Base 2
Timer_B_initCaptureMode(TIMER_B0_BASE, &initCapParam_b_3); //Timer b
Timer_A_startCounter(TIMER_A1_BASE, //Base 1
TIMER_A_UP_MODE);
Timer_B_startCounter(TIMER_B0_BASE, //Timer B
TIMER_B_CONTINUOUS_MODE);
//Timer_A_startCounter(TIMER_A0_BASE, //Base 0
//TIMER_A_UP_MODE);
//Timer_A_startCounter(TIMER_A2_BASE, //Base 2
//TIMER_A_UP_MODE);
}
I am taking the capture interrupt on Pin 3.6 (CCIA2).
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,GPIO_PIN6,GPIO_SECONDARY_MODULE_FUNCTION);
Below is the ISR handler:
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERB2_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMERB2_VECTOR)))
#endif
void TIMERB2_ISR(void)
{
/* Any access, read or write, of the TBIV register automatically resets the
highest "pending" interrupt flag. */
switch(__even_in_range(TBIV,14))
{
case 0: break; // No interrupt
case 2: break; // CCR1 not used
case 4: __no_operation();
break; // CCR2 not used
case 6: break; // CCR3 not used
case 8: break; // CCR4 not used
case 10: break; // CCR5 not used
case 12: break; // CCR6 not used
case 14: // overflow
break;
default: break;
}
}
The issue is that every time a pulse arrives on the P3.6 capture pin, uC goes into Trap ISR.
Is there any error in ISR declaration?