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.

CCS/MSP430FR4133: Watchdog timer interrupt handling

Part Number: MSP430FR4133

Tool/software: Code Composer Studio

I would like to toggle an LED at interval of 1 second . Therefore I implemented the coding below . However , I could not observe any toggling most probably due to the fact that WDTIFG  is never raised. I read the documentation of MSP4133 over and over again and I am aware of that WDTIE and GIE have to be set so as to raise WDTIFG.  There must be something I am missing .

Another issue is that I had previously inserted WDTSSEL1 since it is 01b should have corresponded to ACLK(32kHz) .However , I realized that it was set as 10b in the registers window upon that I tried WDTSSEL0 and it  yielded 01b . It did not make sense for me. If anyone could explain it , I would appreciate . Thanks in advance !. 

#include <msp430.h> 
#define LED BIT0

int main(void)
{
	WDTCTL = WDTPW | WDTTMSEL | WDTSSEL0 | WDTCNTCL; 	// interval timer mode is selected,  ACLK selected 32khz  watch dog timer 1/32kHz * 32.768 = 1 second WDT period


	P1DIR |= LED;       //P1.0 is defined as output
	P1OUT &= ~LED;      //LED at P1.0 is turned off initially
	PM5CTL0 &= ~LOCKLPM5;   //previous port settings are activated.

	SFRIE1 |= WDTIE;        // Enable WDT interrupt
	__bis_SR_register(GIE);  //general interrupts enabled.


	for(;;){

	    if((SFRIFG1 & WDTIFG) !=0){
	    //toggle LED once interrupt raised.
	        P1OUT ^= LED ; // toggles LED otherwise
	        WDTCTL = WDTPW | WDTTMSEL | WDTSSEL0 | WDTCNTCL; //watchdog timer starts over counting once again upto limit.
	        //WDTIFG is single source interrupt flag therefore automatically resets when it is serviced.

	    }
	    }

	return 0;
}

  • > SFRIE1 |= WDTIE; // Enable WDT interrupt
    This enables the WDT interrupt, but I don't see an ISR (WDT_VECTOR) for it. If you're going to poll for the WDTIFG, remove this line.

    > I tried WDTSSEL0 and it yielded 01b
    WDTSSEL0 (/1/2/3) are bit names, not field names. To set the field to 1 use WDTSSEL_1 (or WDTSSEL__ACLK). The naming convention here (0/1/2 underbars) is useful to know, since it's used throughout the definitions.
  • Thanks very much for your reply. I corrected my coding according to your sayings. But after I run my code , still my LED is not toggling. Can there be something wrong with my interrupt check ?

     while((SFRIFG1 & WDTIFG) !=0){

  • If you're polling you also need to clear the WDTIFG [Ref User Guide (SLAU445H) Table 1-10]. Something like:
    > SFRIFG1 &= ~WDTIFG; // Clear for next time

    The symptom in this case wouldn't be that it never toggles, but that it toggles too fast to see (on dimly but steadily). Could that be what you're observing?
  • Ah, I missed this before. You're using WDTIS_0, which is a cycle rate of about 18 hours. Try:

    > WDTCTL = WDTPW | WDTTMSEL | WDTSSEL0 | WDTCNTCL |WDTIS_4; // interval timer mode is selected, ACLK selected 32khz watch dog timer 1/32kHz * 32.768 = 1 second WDT period
  • The header file also defines some handy shorthand, e.g.

    > WDTCTL = WDT_ADLY_1000; // Delay using "A"CLK for 1000ms

    [Hint: Right-click on e.g. WDTPW and "go to definition". Then poke around the header file to see what's available.]
  • It worked after changing cycle rate and clearing interrupt flag in the loop ! I had checked WDTIS description in the user guide but I must have misinterpret it. I appreciated . You have been really helpful!

**Attention** This is a public forum