This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432 DriverLib Timer Interrupts

I'm trying to register and enable timer interrupts using DriverLib. I was successfully able to do this for a GPIO interrupt, but I haven't been able to get it working for the timers. The timer registers and clock system registers seem to be being configured correctly. My code is included below. I would greatly appreciate any help or insight.

// Includes
#include "driverlib.h"

// Macros
#define main_BUTTON_PORT	(GPIO_PORT_P1)
#define main_BUTTON_PIN		(GPIO_PIN1)
#define main_GREEN_PORT		(GPIO_PORT_P2)
#define main_GREEN_PIN		(GPIO_PIN1)
#define main_RED_PORT		(GPIO_PORT_P1)
#define main_RED_PIN		(GPIO_PIN0)

#define main_TIMER_ONEMIN_MODULE		(TIMER_A0_MODULE)
#define main_TIMER_ONEMIN_CLOCK			(TIMER_A_CLOCKSOURCE_SMCLK)
#define main_TIMER_ONEMIN_CLOCKDIVIDER		(TIMER_A_CLOCKSOURCE_DIVIDER_64)
#define main_TIMER_ONEMIN_PERIOD		(58594) // Assumes 62.5kHz clock with divider of 64
#define main_TIMER_QUARTERSEC_MODULE		(TIMER_A1_MODULE)
#define main_TIMER_QUARTERSEC_CLOCK		(TIMER_A_CLOCKSOURCE_SMCLK)
#define main_TIMER_QUARTERSEC_CLOCKDIVIDER	(TIMER_A_CLOCKSOURCE_DIVIDER_1)
#define main_TIMER_QUARTERSEC_PERIOD		(15625) // Assumes 62.5kHz clock with divider of 1
#define main_TIMER_ONESEC_MODULE		(TIMER_A2_MODULE)
#define main_TIMER_ONESEC_CLOCK			(TIMER_A_CLOCKSOURCE_SMCLK)
#define main_TIMER_ONESEC_CLOCKDIVIDER		(TIMER_A_CLOCKSOURCE_DIVIDER_1)
#define main_TIMER_ONESEC_PERIOD		(62500) // Assumes 62.5kHz clock with divider of 1

// Local function definitions
void main_buttonInterruptHandler(void);
void main_oneMinuteInterruptHandler(void);
void main_oneSecondInterruptHandler(void);
void main_quarterSecondInterruptHandler(void);

int main(void) 
{
	Timer_A_UpModeConfig TimerConfig;

    WDT_A_holdTimer();

    // Configure SMCLK
    CS_setDCOFrequency(8000000); // Set DCO clock frequency to 8MHz
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_128); // Set SMCLK to DCO/128 (62.5kHz)

    // Initialize timers and timer interrupts
    TimerConfig.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
    TimerConfig.clockSource = main_TIMER_ONEMIN_CLOCK;
    TimerConfig.clockSourceDivider = main_TIMER_ONEMIN_CLOCKDIVIDER;
    TimerConfig.timerClear = TIMER_A_DO_CLEAR;
    TimerConfig.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
    TimerConfig.timerPeriod = main_TIMER_ONEMIN_PERIOD;
    Timer_A_configureUpMode(main_TIMER_ONEMIN_MODULE, &TimerConfig);

    TimerConfig.clockSourceDivider = main_TIMER_QUARTERSEC_CLOCKDIVIDER;
    TimerConfig.timerPeriod = main_TIMER_QUARTERSEC_PERIOD;
    Timer_A_configureUpMode(main_TIMER_QUARTERSEC_MODULE, &TimerConfig);

    TimerConfig.timerPeriod = main_TIMER_ONESEC_PERIOD;
    Timer_A_configureUpMode(main_TIMER_ONESEC_MODULE, &TimerConfig);

    Timer_A_registerInterrupt(main_TIMER_ONEMIN_MODULE, TIMER_A_CCR0_INTERRUPT, main_oneMinuteInterruptHandler);
    Timer_A_registerInterrupt(main_TIMER_ONESEC_MODULE, TIMER_A_CCR0_INTERRUPT, main_oneSecondInterruptHandler);
    Timer_A_registerInterrupt(main_TIMER_QUARTERSEC_MODULE, TIMER_A_CCR0_INTERRUPT, main_quarterSecondInterruptHandler);
    Timer_A_enableInterrupt(main_TIMER_ONEMIN_MODULE);
    Timer_A_enableInterrupt(main_TIMER_ONESEC_MODULE);
    Timer_A_enableInterrupt(main_TIMER_QUARTERSEC_MODULE);

    // Initialize LEDs
    GPIO_setAsOutputPin(main_GREEN_PORT, main_GREEN_PIN);
    GPIO_setAsOutputPin(main_RED_PORT, main_RED_PIN);
    GPIO_setOutputLowOnPin(main_GREEN_PORT, main_GREEN_PIN);
    GPIO_setOutputLowOnPin(main_RED_PORT, main_RED_PIN);

    // Initialize GPIO and interrupt for button
    GPIO_setAsInputPinWithPullUpResistor(main_BUTTON_PORT, main_BUTTON_PIN);
    GPIO_interruptEdgeSelect(main_BUTTON_PORT, main_BUTTON_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
    GPIO_registerInterrupt(main_BUTTON_PORT, main_buttonInterruptHandler);
    GPIO_enableInterrupt(main_BUTTON_PORT, main_BUTTON_PIN);

    while(1);
}

void main_buttonInterruptHandler(void)
{
	if( GPIO_getInterruptStatus(main_BUTTON_PORT, main_BUTTON_PIN) )
	{
		GPIO_clearInterruptFlag(main_BUTTON_PORT, main_BUTTON_PIN);
		GPIO_toggleOutputOnPin(main_GREEN_PORT, main_GREEN_PIN);
		GPIO_toggleOutputOnPin(main_RED_PORT, main_RED_PIN);
	}
}

void main_oneMinuteInterruptHandler(void)
{
	GPIO_toggleOutputOnPin(main_GREEN_PORT, main_GREEN_PIN);
}

void main_oneSecondInterruptHandler(void)
{
	GPIO_toggleOutputOnPin(main_GREEN_PORT, main_GREEN_PIN);
}

void main_quarterSecondInterruptHandler(void)
{
	GPIO_toggleOutputOnPin(main_GREEN_PORT, main_GREEN_PIN);
}

  • Bradley,

    1. Enable CCR0 interrupts: TimerConfig.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
    2. Start the timers:

    MAP_Timer_A_startCounter(main_TIMER_ONEMIN_MODULE, TIMER_A_UP_MODE);
    MAP_Timer_A_startCounter(main_TIMER_QUARTERSEC_MODULE, TIMER_A_UP_MODE);
    MAP_Timer_A_startCounter(main_TIMER_ONESEC_MODULE, TIMER_A_UP_MODE);

    3. Make sure that the interrupt vector table is initialized properly for main_oneMinuteInterruptHandler, main_quarterSecondInterruptHandler, and main_oneSecondInterruptHandler in place of defaultISR for TA0_0, TA1_0, and TA2_0.

    4. Clear the CCR0 IFG inside of the respective ISR using:

    MAP_Timer_A_clearCaptureCompareInterrupt(main_TIMER_ONEMIN_MODULE,
    TIMER_A_CAPTURECOMPARE_REGISTER_0);
    MAP_Timer_A_clearCaptureCompareInterrupt(main_TIMER_QUARTERSEC_MODULE,
    TIMER_A_CAPTURECOMPARE_REGISTER_0);
    MAP_Timer_A_clearCaptureCompareInterrupt(main_TIMER_ONESEC_MODULE,
    TIMER_A_CAPTURECOMPARE_REGISTER_0);

    You should review the Timer_A driverlib examples for a better understanding of how to initialize the timers.

    Regards,
    Ryan

**Attention** This is a public forum