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
}