I am using the following code to blink LEDs using a timer interrupt:
#include <msp430.h>
#define LED1 BIT0 //define LED1 as bit 0 (0x00)
#define LED2 BIT6 //define LED2 as bit 6 (0x40)
int main(void)
{
//stop watchdog timer
WDTCTL = WDTPW | WDTHOLD;
//P1 initialization code
P1OUT &= 0x00; //clear all bits on P1
P1DIR |= (LED1|LED2); //set P1.0 and P1.6 to output direction
//Timer_0A3 initialization
TA0CCR0 = 12e3; //count limit (16 bit)
TA0CCTL0 = 0x10; //enable counter interrupts, set bit 4 high
TA0CTL = TASSEL_1 + MC_1; //Timer A0 with ACLK @ 12KHz (TASSEL_1), count UP (MC_1)
//low power mode
_BIS_SR(LPM0_bits + GIE); //LPM0 (low power mode) with interrupts enabled
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void) //service routine for Timer0 A0 interrupt
{
P1OUT ^= (LED1|LED2); //toggle P1.0 using exclusive-OR
}
And guess what, it works! But only when I'm running the debugger. When I close the debugger, it stops what it's doing and whichever LED was lit at the time remains lit. Resetting the board doesn't help at all.
After a bit of research online, I have tried going to Tools -> Debugger Options -> MSP430 Debugger Options -> Clock Control
to uncheck the box for my corresponding timer. I have these options: []ACLK []SMCLK []TACLK
. I have tried every combination of checks/unchecks and nothing seems to allow my interrupts to function after the debugger stops running.
If I had to guess, I would say that the timer is running, but somehow the interrupt flags aren't getting set properly. Any idea what is going on here?