Other Parts Discussed in Thread: CCSTUDIO, ENERGYTRACE
Tool/software: Code Composer Studio
Hello!
I'm pretty new to MSP430 and ccstudio. I'm trying to read from a moisture sensor connected to the microcontroller, compare the sensor data against a randomly generated set of 10 numbers and then go to the sleep mode. A timer interrupt wakes the microcontroller up and it reads from the sensor again.
The sensor output is connected to Pin 1.1. Pin 1.0 is used to turn the sensor on/off. The sensor data needs to be converted from an analog signal to a digital value for which the ADC is used. I used the ADC code from one of the examples.
I measured the current by hooking up a multimeter between the power supply and the board. The code was flashed on the device and jumpers connecting the debug probe were removed. I see a current of around 400uA in LPM3 mode - does that mean the device isn't going into the low power mode? Is there an issue in the set up I have? Any help in this regard or pointers to where I could check would be greatly appreciated.
Here's the code:
#include <msp430.h>
unsigned int ADC_Result;
int trigger;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1DIR |= BIT0; // Set P1.0/LED to output direction
P1OUT &= ~BIT0; // P1.0 LED off
// Configure ADC A1 pin
P1SEL0 |= BIT1;
P1SEL1 |= BIT1;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Configure ADC
ADCCTL0 |= ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 |= ADCSHP; // ADCCLK = MODOSC; sampling timer
ADCCTL2 &= ~ADCRES; // clear ADCRES in ADCCTL
ADCCTL2 |= ADCRES_2; // 12-bit conversion results
ADCMCTL0 |= ADCINCH_1; // A1 ADC input select; Vref=AVCC
ADCIE |= ADCIE0; // Enable ADC conv complete interrupt
int k, p, in[10], out[10], match[10];
//Initialise input array with random numbers for comparison
for(k=0; k<10; k++)
{
in[k] = k*(k+1);
}
while(1)
{
P1OUT = 1;
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
// P1OUT = 1;
__bis_SR_register(LPM0_bits | GIE); // LPM0, ADC_ISR will force exit
// __no_operation(); // For debug only
for(p=0; p<10; p++)
{
//Compare with array initialised above
out[p] = in[p] ^ ADC_Result;
if(out[p] == 0x00)
{
//P1OUT |= BIT0; //Set P1.0 LED on to indicate match
match[p] = 0x01;
// __delay_cycles(5000);
}
else
{
P1OUT = 1; //Set P1.0 LED on to indicate no match for debug only
match[p] = 0x00;
__delay_cycles(5000);
}
} //end for
//configure timer and start it.
TB0CCTL0 = CCIE;
TB0CTL = MC_1|ID_3|TBSSEL_1|TBCLR; //set up timer and start it
TB0CCR0 = 100000*100000; // Set Timer Period
trigger = 1; //for debug purposes
P1OUT = 0;
//enter lpm3
__bis_SR_register(LPM3_bits | GIE);
//at timer interrupt, ISR takes care of going out of lpm and setting timer off.
} //end while
} //end main
// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
ADC_Result = ADCMEM0;
P1OUT = 0;
__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from LPM0
break;
default:
break;
}
}
#pragma vector = TIMER0_B0_VECTOR
__interrupt void TB0_ISR (void)
{
__bic_SR_register_on_exit(LPM3_bits);
TB0CTL &= ~MC_1; // Turn off Timer
}
Thank you for the help!