Other Parts Discussed in Thread: MSP430FR2311
Tool/software: Code Composer Studio
I have to put my micro in Low Power Mode after 10 seconds using a Timer interrupt. once its in LPM, I have to wake it up with an extreme value from the accelerometer in any axis using the ADC interrupt. also I have to use the onboard LEDs to indicate the state of the micro, RED for sleep, GREEN for Awake.
what I'm haing trouble with the most is understanding how to invoke the ADC ISR, when does the program go into that ISR??
here is my code:
#include <msp430g2553.h> unsigned int tic = 0, sec = 1; void main (void) { //Setup WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer //Setup LEDs P1DIR |= BIT0 + BIT6; P1OUT |= BIT6; P1OUT &= ~BIT0; //Setup ADC ADC10CTL0 = SREF_0 + ADC10SHT_0 + ADC10SR + ADC10ON + ADC10IE; ADC10CTL1 = SHS_0 + ADC10DF + INCH_3 + ADC10DIV_0 + CONSEQ_0; ADC10AE0 = 0x0E; //set P1.1 P1.2 and P1.3 as ADC inputs //Setup Timer A0 TA0CTL = 0X0210; //Setup Timer/Start Timer TA0CCTL0 = CCIE; //Enable interrupt on TA0.0 TA0CCR0 = 50000; //Period of 50ms or whatever interval you like. __enable_interrupt(); //Enable General Interrupts. Best to do this last. while (1){} //Empty infinite while loop. } // Timer 0 A0 Interrupt Service Routine #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer0_A0_ISR( void ) { tic++; if(tic % 20 == 0) //increase integer 'sec' after every second has passed { sec++; } if(sec % 11 == 0) //after 10 seconds, turn off green LED and turn on red LED to indicate micro sleeping { P1OUT &= ~BIT6; P1OUT |= BIT0; TA0CCR0 = 0; //stop the timer _BIS_SR(LPM4_bits + GIE); } } // ADC10 Interrupt Service Routine #pragma vector = ADC10_VECTOR __interrupt void ADC10_ISR( void ) { if (ADC10MEM < 0x88) { P1OUT &= ~BIT0; P1OUT |= BIT6; } else { TA0CCR0 = 50000; //turn on timer } }