3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ any link to instruction set? \$\endgroup\$ – Flood Gravemind Apr 29 '17 at 23:22
  • \$\begingroup\$ Did you tried to enable all interrupt? ( __enable_interrupt() ) \$\endgroup\$ – M.Ferru Apr 29 '17 at 23:56
3
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

It seems that you forgot to enable the interrupt in your code. You can enable all the interrupt with __enable_interrupt(); or enable specific interrupt with _BIS_SR(name_of_interrupt);

\$\endgroup\$
  • \$\begingroup\$ Specific interrupts cannot be enabled in the SR. \$\endgroup\$ – CL. Apr 30 '17 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.