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.
Hi,
I'm having a problem getting the Watchdog interval timer ISR to work while keeping the CPU clock running.
I'm using a msp430g2231 on the Launchpad and compiling using mspgcc
Here's my code:
////////////////////////////////////////////////
#include <msp430.h>
#include<signal.h>
#include "msp430g2231.h"
/*WDT interval timer- code based on msp430 examples*/
//compiler=mspgcc
void main(void) {
P1DIR |=BIT0; // Set the Launchpad redled P1.0 as an output pin
//BCSCTL3 = LFXT1S_2; // use the VLO for ACLK
WDTCTL = (WDTPW+WDTTMSEL+WDTCNTCL); // setup watchdog register as interval timer (same as WDT_MDLY_32)
IE1 |= WDTIE; //enable watchdog interrupt
_BIS_SR(LPM0_bits + GIE); //set LPM0 mode and enable interrupts **** WORKS ****
//_BIS_SR(GIE); //keep cpu running and enable interrupts **** DOES NOT WORK ****
}//end of main
//interrupt service routine
interrupt(WDT_VECTOR) watchdog_timer(void)
{
P1OUT ^= BIT0;
}//end of interrupt
////////////////////////////////////////////////////
The line
_BIS_SR(LPM0_bits + GIE);
works, the interval timer runs and the correctly, but it shuts off the cpu and I want to keep the main cpu running and do other stuff
So if I use
_BIS_SR(GIE);
The interval timer fails to run.
I tried resetting the interrupt flag inside the ISR with
IFG1 &= ~WDTIFG;
But that didn't help.
I couldn't find any reference to this behavior in the documents.
Does anyone know how can I run the watchdog interval timer with the CPU clock still running?
cheers
-mpymike
When you use "_BIS_SR(GIE);" the CPU stays awake and execution of main continues. Unfortunately there's no further code after that point, so he CPU runs off the end of main().
I'm not sure whether that would cause the problems you're seeing, but it's worth eliminating the possibility. Try adding a "while(1);" infinite loop after the "_BIS_SR(GIE);" to see if that fixes the problem.
Thanks for the quick answer Robert! Adding the 'while' loop made it work.
Its sounds obvious now that you explained it.
What confused me is that I just tested out a pin interrupt ISR. It had a _BIS_SR(GIE) and no while loop,
it also must of run off the end of main. But it continued to work and generate interrupts.
I think I will be adding 'while' to all my main's
thanks again
-mpymike
Apparently there is some 'end of operation' code behind main added by your linker (whether there is such code is linker-specific and differs between IDEs). Probably this code deactivates the watchdog , so it won't reset and restart the MSP when main doesn't trigger the WDT anymore. Also, it may enter LPM4 for low power, and having the WDT active would keep the WDT clock active and raise power consumption. But port interrupts will still execute as they don't need and clock.Mike Asker said:What confused me is that I just tested out a pin interrupt ISR. It had a _BIS_SR(GIE) and no while loop,
it also must of run off the end of main. But it continued to work and generate interrupts.
Just a possibility as I never really looked at the different after-main codes of CCS, IAR or MSPGCC.
**Attention** This is a public forum