Hi there,
I am attempting to read input from two sensors on my MSP-EXP430FR5969 Launchpad but I am having some issues with the interrupt routine. I am able to successfully read the sensor values and store them in ADC12MEM0 and ADC12MEM1, but my problem is the program never leaves the ISR and I am unable to process the data as I would like to.
Here is my code:
#include <msp430.h> #define CONVERSION_VALUE_1_2 0.29296875 // Vref 1200mV / 4095 (12 bit ADC resolution) unsigned int ADC_value=0; float temp=0, light=0; float calculate_Temp(unsigned int ADC_value); float calculate_Light(unsigned int ADC_value); int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // GPIO Setup P1OUT &= ~BIT0; // Clear LED to start P1DIR |= BIT0; // P1.0 output P1SEL1 |= BIT3 | BIT4; // Configure P1.3 and P1.4 for ADC P1SEL0 |= BIT3 | BIT4; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // By default, REFMSTR=1 => REFCTL is used to configure the internal reference while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT REFCTL0 |= REFVSEL_0 | REFON; // Select internal ref = 1.2V // Internal Reference ON // Configure ADC12 ADC12CTL0 = ADC12SHT0_2 | ADC12ON | ADC12MSC; ADC12CTL1 |= ADC12SHP | ADC12CONSEQ_1; // ADCCLK = MODOSC; sampling timer ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results ADC12IER0 |= ADC12IE1; // Enable ADC conv complete interrupt ADC12MCTL0 |= ADC12INCH_3 | ADC12VRSEL_1; // A3 ADC input select; Vref=1.2V ADC12MCTL1 |= ADC12INCH_4 | ADC12VRSEL_1; // A4 ADC input select; Vref=1.2V while(!(REFCTL0 & REFGENRDY)); // Wait for reference generator // to settle while(1) { __delay_cycles(5000); // Delay between conversions ADC12CTL0 |= ADC12ENC | ADC12SC; // Sampling and conversion start __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC10_ISR will force exit ADC_value = ADC12MEM0; temp = calculate_Temp(ADC_value); ADC_value = ADC12MEM1; light = calculate_Light(ADC_value); __no_operation(); // For debug only } } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector = ADC12_VECTOR __interrupt void ADC12_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void) #else #error Compiler not supported! #endif { switch (__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG)) { case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU case ADC12IV_ADC12IFG1: // Vector 14: ADC12MEM1 Interrupt __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; // Clear CPUOFF bit from 0(SR) default: break; } } float calculate_Temp(unsigned int ADC_value){ // Retrieve voltage measurement, subtract 500mv (thermistor base @ 0C) // Divide by 10 since thermistor reports 10mV per degree C return ((ADC_value*CONVERSION_VALUE_1_2-500)/10); } float calculate_Light(unsigned int ADC_value){ // Retrieve voltage measurement for Light sensor return (ADC_value*CONVERSION_VALUE_1_2); }
Am I missing something inside the ISR in order to exit it? Any help would be greatly appreciated.
Thanks,
Mike