MSP430 ADC12_B Module - Read multiple inputs / channels

I had a problem reading multiple channels using a msp430fr5969 which uses the ADC12_B module. I posted to irc the question "Has anyone experience with the ADC12_B module? I'm trying to read multiple channels one at a time and I always get back data from the first channel I selected, it is as if the multiplexer that selects A0-Ax does not work after you select a channel."

Well it turns out that the answer is you, apparently, must turn off the a/d module (Stop Analog Conversions) before you select another channel using the code: ADC12CTL0 = 0;

I've attached a working but not completely fleshed out example below. It is a good enough example that you see exactly what is going on and can modify it for your own needs.

Licensing: Do what you want with it and it would be nice if you gave credit and a link back to this page.

// example: x=readad(1); or x=readad(6);

unsigned int readad(unsigned char port) {
unsigned long v;

// Connect pin to be read to a/d converter
case 1: // This is dev kit button 1.1 which I connected a 10K ratiometric pot to
// Configure Pins to connect to physical a/d converter inputs - yes we do this every time but not necissary :)
P1SEL1 |= BIT1; // Configure P1.1 for ADC
P1SEL0 |= BIT1;
// Connect a/d multiplexer to the physical a/d
ADC12MCTL0 = ADC12INCH_1; // A1 ADC input select; Vref=AVCC

case 6: // CDS Photocell Sense Pin 6, A7, P2.4, System Input 6
P2SEL1 |= BIT4;
P2SEL0 |= BIT4;


// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings

// Configure ADC12
ADC12CTL0 = ADC12SHT0_2 | ADC12ON; // Sampling time, S&H=16, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results
ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt

ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion

while (1)
if (v==0) break;

ADC12CTL0 = 0; // Stop conversions

return(adValue); // This value is stored globally in the interrupt routine


Your Idea Brought To Life Is My Passion

Has your fun project turned into a real product that you need help 'finishing up'?

Microcontroller (MSP430) Consulting, Programming, Research, Design, Prototyping.