Guys,
I've spent literally 5 hours trying to figure out why my code doesn't work on F5529. It seems that even though I start the ADC12 conversion the ISR isn't triggered and the CPU won't wake up from the LPM. Code snippets are below:
[here set the timer to 0 and call the get_adc_data(), ADC reading to be done on A0, P6.0, ref to AVcc, single samples in the software loop]
int get_adc_data()
{
int adcVal[AS_NUM_OF_ADC_READS];
int i, adcValAvgPrev, adcValAvg;
P6SEL |= BIT0;
ADC12CTL0 = ADC12ON + ADC12SHT02;
ADC12IE = 0x01;
ADC12CTL1 = ADC12CONSEQ_0;
ADC12CTL2 |= ADC12RES_1; // 10-bit resolution
ADC12MCTL0 |= ADC12INCH_0 + ADC12SREF_0; // V(R+) = AVCC and V(R-) = AVSS
ADC12CTL0 |= ADC12ENC;
for (i = 0; i < AS_NUM_OF_ADC_READS; i++)
{
uart_puts("ADC before LPM\n\r");
ADC12IE |= 0x01;
__bis_status_register(LPM0_bits + GIE);
uart_puts("ADC after LPM\n\r");
adcVal[i] = ADC12MEM0;
adcValAvgPrev = !i ? adcVal[i] : adcValAvg; // if it's the first iteration then adcValAvgPrev = adcVal[0]
adcValAvg = adcValAvgPrev + ((adcVal[i] - adcValAvgPrev) / i);
}
ADC12CTL0 &= ~ADC12ENC;
return adcValAvg;
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
__bic_status_register_on_exit(CPUOFF);
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void)
{
if (!(++timer_ms % 5000))
{
am_probe_finished_flag = 1;
__bic_status_register_on_exit(CPUOFF);
}
}
I know that multiple readings can be done better with ADC12MEMx, but this is not a problem here, I will fix it once I have ISR being triggered. Can you please take a short look to see what may be wrong? I have no idea...
Best Regards,
tml