Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Timer Interrupt with LPM3, Debugger problem?

$
0
0

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


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>