Hello,
I have configured the GPIO P1.4 as input of the ADC10 (A4), the ADC10 executes 16 measurements on the A4 pin and the 2.5V internal voltage of is used as reference voltage. The conversion works correctly. The problem is when entering and exiting the LPM0 mode. If before the while loop we enter LPM0 mode (__bis_SR_register (LPM0 + GIE)), the ADC10 ISR is never executed. Why? Thanks in advance.
#include <msp430g2553.h>
int ADC[16] = {0};
int avgADC = 0;
volatile int conversionFlag = 0;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
ADC10CTL1 = CONSEQ_2 + INCH_4; // Repeat single channel, A4
ADC10CTL0 = SREF_1 + REF2_5V + REFON + ADC10SHT_1 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable
ADC10DTC1 = 0x10; // 16 conversions
ADC10AE0 |= BIT4; // P1.4 ADC option select
ADC10CTL0 &= ~ENC; // Disable Conversion
while (ADC10CTL1 & BUSY); // Wait if ADC10 busy
ADC10SA = (int)ADC; // Transfers data to next array
ADC10CTL0 |= ENC + ADC10SC; // Enable and start conversion
__bis_SR_register(LPM0 + GIE); // Low Power Mode 0, ADC10_ISR
while(1){
if (conversionFlag){
avgADC = ((ADC[0]+ADC[1]+ADC[2]+ADC[3]+ADC[4]+ADC[5]+ADC[6]+ADC[7]+
ADC[8]+ADC[9]+ADC[10]+ADC[11]+ADC[12]+ADC[13]+ADC[14]+ADC[15]) >> 4);
conversionFlag = 0;
__bis_SR_register(LPM0 + GIE);// Low Power Mode 0, ADC10_ISR
}
};
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
conversionFlag = 1;
__bic_SR_register_on_exit(CPUOFF);
}
Best regards,
Fran Martin.