I have an MSP430G2101 and I need to use the Watchdog to trigger an interrupt. The code I am trying to use is the following:
#include <msp430.h>
#include <stdint.h>
unsigned int cycle = 0;
unsigned int pwmred = 1;
void main(void)
{
WDTCTL = WDT_MDLY_0_5; // WDT as interval timer (period 0,5 ms)
IE1 |= WDTIE; // Enable WDT interrupt
P1DIR |= BIT3 + BIT4 + BIT5;
_BIC_SR(GIE);
while(1)
{
}
}
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
cycle++;
if(cycle >= pwmred) {
P1OUT &= ~BIT3;
}
if (cycle >= 255)
{
if(pwmred > 0)
P1OUT |= BIT3;
cycle = 0;
}
}
The interrupt is not triggering, I am checking using the debugger and it is also not acting as expection. I am using the latest version of code composer studio. Did I forget something important. I would expect the watchdog_timer method being called every 0.5 ms, but that is not working.
Best Answer
Because you disabled global interrupts.
_BIC_SR(GIE);
Is Bit Clear Special register.
You want
_BIS_SR(GIE);
Bit Set special register.
Or use __enable_interrupt(); as mentioned.