I'll get the first statement out of the way: I am a complete beginner when it comes to programming. I have a decent grasp of an Arduino, and have also been using the STM32 (via the Nucleo) and have become quite accustomed to using them.

Recently, I have decided to look at the MSP430 as these (alongside the STM32) are the main microcontrollers used at my place of work, so I would like to get to grips with the basics.

I was surprised to see just how different they are, for example, even blinking an LED example between the STM32 and MSP430 had a vast difference in how they were written and set up. However, I would like to get to a stage where I can use both microcontrollers eventually.

So far, I am following the same learning curve on the MSP as I have with the others. My plan is to blink and LED, then change the time between blinks, then toggle with a button, then toggle 2 LEDs, etc etc. This all comes from using examples as a starting point and editing it to fit my needs. I have now got to the stage where I want to read an ADC value and light up different LEDs as the ADC value increases. Sounds simple enough. I have found a few examples on using the ADC, but I don't want to just copy and paste and be done with it, and there are a few things I am unclear of in the setting up of the ADC, and I don't want to continue without knowing how to use them, otherwise I am setting myself up to fail in the future, so I wanted to get some clarification on what they mean. The examples I have seen have the following ADC setups:

    void main(void)     {       WDTCTL = WDTPW  + WDTHOLD;    // stop WDT       //
 ADC configuration
         // V+ref=3V,V-ref=0V,Channel=A0

         ADC10CTL0  = ADC10ON + ADC10IE; // Vref Vr+=3v,Vr-=VSS,
                                        // S&Htime = 4 X ADCCLK,ADC10 on,ADC interrupts enabled
         ADC10CTL1  = ADC10DIV_7;        // INCH =0000->A0,ADCCLK src = ADC10CLK,
                                        // ADCCLK/8,Single Channel Single Conversion
         ADC10AE0   = INCH_0;            // channel A0 

         ADC10CTL0 |= ENC + ADC10SC;     // Start Conversion
                _BIS_SR(LPM0_bits +GIE);        // Go to LPM0,interrupts enabled    }

And the second:

void main(void)
    WDTCTL = WDTPW + WDTHOLD;                   // Stop watchdog timer
    ADC10CTL1 = INCH_10 + ADC10DIV_3;           // ADC Channel -> 10 (Temp Sensor), CLK/4
    ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
                                                // Ref -> 1.5V, 64 CLK S&H, Interrupt Enabled
    __delay_cycles(100);                        // Wait for reference to settle
        ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
        __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled

        adcValue = ADC10MEM;                    // Fetch ADC conversion result

        // C = ( (adcValue/1024)*1500mV)-986mV)*1/3.55mV
        tempC = ((adcValue - 673) * 423) / 1024;

        __no_operation();                       // Required for breakpoint

I am fine with the watchdog timer disable. My main issue is with the ADC setup, and not knowing what each do. In the examples, both ADC10CTL0 and ADC10CTL1 are used, but both setup differently. Looking for ADC10CTL in the datasheet of the MSP430 I am using only tells me what they are (ADC control), not how to set them up, or what parameters to set up in there, so I would like some clarification on that, because the notes don't make sense to me. For the first example, I get that ADC10ON means to enable the ADC, and ADC10IE is the interrupt enable, so why in the notes is the S&H time mentioned? I can't find that in the datasheet? It also mentions the Vref value, which I can't see referenced. In the second example, ADC10CTL0 references REF)N, ADC10SHT, so I am a bit confused how to actually set this up.

The next is the ADC10CTL1 setup. I get the ADC10DIV is to do with the CLK time (although I would like clarification on how this works), but the 2 examples set up the channel used differently. I see that INCH references the input channel, but the second example has this setup in ADC10CTL1, and the first example uses a separate setup with ADC10AE0, which I cannot find a reference to in the datasheet, so I am unsure what this is.

I am happy with the start conversion, but confused on the second examples use of ADC10MEM, which I assume is where the conversion result is stored, yet I cannot find this in the datasheet either? Unless mine uses the ADC10MCTL0? (Page 92)

Any help understanding the setup of the ADC will be very much appreciated, as I don't feel comfortable with moving on untill I am confident I can set it up without having to copy and paste examples constantly.

If any other information is required, please feel free to ask.


1 Answer 1


You need to find the User Guide for the MSP430 processor you are using.

It can be found on TI's website under the product page for your MCU.

In chapter 27 of the User Guide the registers are explained in detail.

  • \$\begingroup\$ Ahh, thanks for that, I'll have a read through and see if I can get my head around it \$\endgroup\$
    – MCG
    Mar 18, 2019 at 12:21
  • \$\begingroup\$ Ahh, I think there is a typo in the datasheet. ADC10MCTL0 is repeated twice in the table, where according to the user guide, it should only be for memory control, the actual memory should have been ADC10MEM. That'll explain why I was unable to find it when searching! That is at least 1 of my question answered! \$\endgroup\$
    – MCG
    Mar 18, 2019 at 12:34
  • \$\begingroup\$ also look at the example code from TI, should be near where you found the user guide, it should be your go to for basic setup. \$\endgroup\$
    – jsolarski
    Mar 18, 2019 at 18:39
  • 1
    \$\begingroup\$ @jsolarski I have looked up a few bits of example code, I can easily copy and paste and get it working, but I just wanted to find an explanation of it all, as I would much rather understand what I am doing \$\endgroup\$
    – MCG
    Mar 19, 2019 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.