Part Number: MSP430FR5994
Tool/software:
I am trying to read from A3 and A4 inputs to the processor. I can read A3 fine, but when I try and read A4, I get the same value. With the debugger I can see that I am correctly changing ADC12MCTL0 depending on which parameter I call the function with, so I am assuming there is something else wrong with how I am reading the result registers? Any help would be greatly appreciated.
uint16_t adcResult = 0x0000;
void initADC(){
while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT
REFCTL0 |= REFVSEL_2 | REFON; // Select internal ref = 2.5V
ADC12CTL0 = ADC12SHT0_2 | ADC12ON;
ADC12CTL1 = ADC12SHP; // ADCCLK = MODOSC; sampling timer
ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results
}
uint16_t sampleADC(ADC_Input channel){
//select right channels from the ADC
switch(channel){
case ADC_CH_REG_3V3:
ADC12MCTL0 = ADC12INCH_4 | ADC12VRSEL_1; // A1 ADC input select; Vref=+VRef
break;
case ADC_CH_INA241:
ADC12MCTL0 = ADC12INCH_3 | ADC12VRSEL_1;
break;
}
while(!(REFCTL0 & REFGENRDY)); //make sure reference has settled
ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt
ADC12CTL0 |= ADC12ENC | ADC12SC; // Enable and start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
return adcResult;
}
//**********************************************************************************************
//** ADC Interrupt routine *********************************************************************
//** Called when the corresponding ADC12MEMx memory register is loaded with a conversion result
//**********************************************************************************************
#pragma vector = ADC12_B_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV, ADC12IV__ADC12RDYIFG))
{
case ADC12IV__ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt
adcResult = ADC12MEM0;
// Exit from LPM0 and continue executing main
__bic_SR_register_on_exit(LPM0_bits);
break;
}
}