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.

Timer Interrupt with LPM3, Debugger problem?

Hello,

I am trying to run a timer interrupt and go back into LPM3. I run into a problem where my code works when debugger is running, but when I "unlink" debugger it stops working.

What happens is when plugged to debugger, with PORT4 set high, and trigger PORT2 it goes into an infinite loop toggling PORT3 BIT0. When its not plugged into debugger, with PORT4 set high, and trigger PORT2 it toggles PORT3 BIT0 once, and then just sits there in LPM3. (The timer doesn't trigger for some reason).

Code:

int main(void)
{
init();
rtc_init(1);
while(1) {

if(writing && ((P4IN & BIT1) == BIT1)) {

init_timer();

while(1){

TimerInt = 0;
while(TimerInt != 1){
P3OUT ^= BIT0;
__bis_SR_register(LPM3_bits + GIE);
P3OUT ^= BIT0;
}

}
}
writing = 0;

UCA1CTL1 |= UCSWRST;REFCTL0 |= REFTCOFF;

REFCTL0 &= ~REFON;

PMMCTL0_H = PMMPW_H;
PMMCTL0_L |= PMMREGOFF;
__bis_SR_register(GIE+CPUOFF+OSCOFF+SCG1+SCG0); // Enter LPM3

}
}

void init() {
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0;
P1OUT = 0;
P1REN = 0;

P2DIR = 0;
P2OUT = 0;
P2REN = BIT2;
P2IES &= ~BIT2; //low to high interrupts
P2IFG &= ~BIT2; // clear interrupt flag
P2IE |= BIT2; // enable interrupts

P3DIR = 0;
P3OUT = 0;
P3REN = 0;

P4DIR = 0;
P4OUT = 0;
P4REN = 0;

writing = 0;
rtc_init(0);
}

void rtc_init(char clear) {
PJSEL0 |= BIT4; // XT1
PJSEL1 &= ~BIT4;
CSCTL0_H = 0xA5;
CSCTL2 = SELA_0 | SELS_3 | SELM_3; // set ACLK = XT1; MCLK = DCO
CSCTL3 = DIVA_0 | DIVS_0 | DIVM_0;
CSCTL4 &= ~XT1OFF;

do {
CSCTL5 &= ~XT1OFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
} while (SFRIFG1 & OFIFG);
CSCTL0_H = 0x01; // Lock Register

if(clear) {
RTCCTL01 = RTCHOLD; // Hold RTC for now..
RTCSEC = 0;
RTCMIN = 0;
RTCHOUR = 0;
}
RTCCTL01 &= ~RTCHOLD; // Turn on RTC
}

void init_timer() {
TA0CTL |= TASSEL_1 | MC_1 | TAIE | TACLR;
TA0CCR0 = 655;
}

void wakeup_init() {
PMMCTL0_H = PMMPW_H; // open PMM
PMMCTL0_H = 0x00; // close PMM
__bic_SR_register(GIE+CPUOFF+OSCOFF+SCG1+SCG0); // needed?
__no_operation();

init();

PM5CTL0 &= ~LOCKLPM5; // Clear LOCKIO and enable ports
}

#pragma vector=PORT2_VECTOR
__interrupt void PORT2(void){
if(P2IFG & BIT2) {
wakeup_init();
writing = 1;
__bic_SR_register_on_exit(CPUOFF+OSCOFF+SCG1+SCG0);

__bis_SR_register_on_exit(GIE);
return;
} else {
P2IFG = 0; // Reset flag
return;
}
}

Thanks!

-Omri

  • Figured it out :)

    I had "PMMCTL0_H = 0x00; // close PMM" on wakeup where it should have been:

    PMMCTL0_L &= ~PMMREGOFF;
    PMMCTL0_L |= SVSLE;

    also needed to add "PMMCTL0_L &= ~SVSLE;" before low power mode 3.5

    -Omri

  • I ran into another problem.

    I read the RTC values and record them in FRAM. When I am plugged into debugger it is reading the correct values, but if I am "unlinked" to the debugger I get just 0s.

    (I store the data to FRAM and read them off there, thats how I know what the data is)

    If I dont clear the registers at the start, I get random values, but the relativity of them is correct (if I record the second measurement 4 seconds after the first measurement I get something like 47149sec and 47153sec for the two data points, 4 seconds off) As soon as I clear the data at the start it just gives me 0 seconds for all data points.

     -Omri

  • As long as teh debugger is attached, the device won't enter LPM3.5

    If you enter LPM3.5, the CPU-visible registers of the RTC are sewered from the RTC logic. After device restart from LPM3.5, they are still not connected to the RTC coutners. You'll have to follow the 'reactivation procedure' as described in the users guide to make them accessible again. the RTC is still counting but unless you properly unlocked them, its coutners are not accessible for the CPU.

**Attention** This is a public forum