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.

BT ISR only executing once



Hey there,

Im relatively new to the MSP430 and have a question about the Basic Timer Module.

When I run the code below it works fine for the first loop but sits in LPM3 on the second repetition.

Im debugging with CCE3, and all the appropriate registers seam to be set before I enter LPM, it just doesn’t wake up from it.

Anyone Any Ideas?

Thanks!

Alan

-------------------------------------------------------------------------------------------

 

#include <MSP430xG46x.h>

 

volatile int i=0;

 

void DELAY(void)

{

      i=2000;

      do(i--);

      while(i>0);

}

 

 

void ClockInit(void)

{

FLL_CTL0 |= XCAP18PF + DCOPLUS;           //- FreqDCO = fACLK * (N+1) * D

      SCFI0 |= FN_4 +FLLD_1;        //- D = 2 and Frq range set for 8MHz

      SCFQCTL = 121;          //- FreqDCO = fACLK * (121+1) * 2 = 7.99MHz

      DELAY();                // Delay for FLL to Stabilise

}

 

void B_TimerInit (void)

{

      BTCTL = BTDIV | BT_fCLK2_DIV128;          //Set up Basic Timer with a 2 Second Delay      - (ALK/256)/256 = 0.5

}

 

void PortInit(void)

{

      P2DIR |= 0x04;

      P2OUT = 0x00;

      P1OUT = 0x00;

      P1DIR = 0x00;

      P1SEL |= 0x00;          //Initially all ports are set to outputs.

}

 

 

void TimerAInit(void)

{

      TACTL |= TASSEL_1 + MC_1 + TAIE;                      //Timer_A = ALCK, Up-Mode and cleared

      TACCR0 = 0x00c;                                       //TAR Couts from 0 to 12

                                                                  // Thus Timer_A generates an Interupt Request every 12 cycles of ACLK    

}

 

 

void SystemInit (void)

{

      WDTCTL = WDTPW | WDTHOLD;

      ClockInit();

      B_TimerInit();

      PortInit();

}

 

 

 

 

void main (void)

{

      SystemInit();                                   //Initialise all ports, clocks and BT1 timer

     

      for(;;)

      {    

            IE2 |= BTIE;

            __bis_SR_register(LPM3_bits + GIE);       //Enter Low Power Mode and wait for BT1 Interupt

           

            IE2 &= !BTIE;

            P2OUT = 0x04;

            P1SEL = 0x20;                       //Turn on Port 1.5 to output ALCK

            TimerAInit();                       //Set up Timer_A                                                 

            TACCTL0 |= CCIE;              //Enable Timer_A interupt

            _BIS_SR (LPM0_bits + GIE);    //Enter Low power mode and wait for Timer_A to waken

                                                     

            P1SEL = 0x00;                       //Turn off Port1.5

            TACCTL0 &= !CCIE;             //Disable Timer_A interupts

      }

}

 

 

 

#pragma vector=BASICTIMER_VECTOR

__interrupt void basic_timer_ISR (void)

{

      P2OUT ^= 0x04;

      __bic_SR_register_on_exit (LPM3_bits);          //Disable LPM3 and GIE

}

 

 

#pragma vector=TIMERA0_VECTOR

__interrupt void TimerA_ISR (void)

{    

      __bic_SR_register_on_exit (LPM0_bits + GIE);          //Disable LPM3 and GIE

}

 

 

 

  •  

    After a day of going at it I got something that works,

    Found the problem existed in the Timer Set-up so changed TimerAInit to

    TACTL |= TASSEL_1 | MC_1 | TACLR | TAIE;

    This seamed to get it looping as I wanted.

    Honestly im not 100% why this was the problem, but if anyone could tell me I would really appreciate it..

    Alan

  • The problem is that TimerA is not stopped before you configure it. So once you program it to UP mode and set the CCR0 value, there's already an interrupt pending (timerA>CCR0), which is executed immediately, when enabling CCIE, before entering LPM.

    If you clear TimerA before programming CCR0, there's enough time for finishing the setup and entering LMP before the timer expires.

    There may be a racing condition at this point (clearing GIE inside the ISR while executing the command that enters LPM and sets GIE). I think the erratum SYS8 (?) could be related to this.

  • Thanks for the explination Jens, what your saying make sence!..

    Alan

**Attention** This is a public forum