This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432 ADC Sample A1 Example

Hello,

I have been trying to get the MSP432 ADC example code, msp432p401_adc14_01, to work on my MSP432P401R. Been through the Family Guide on most of the script and it seems to be written correctly. Not sure if the ADCCTL0 or ADCCTL1 registers are missing something. When I run it I change the voltage on P5.4 and the LED never changes. When decoding, if run for any length of time it gets stuck in the startup_script defaultISR infinite loop. The only thing that seems of interest to me is that its using A1 but MEM0. Don't know enough yet about the MSP432 but it doesn't seem that should be a problem. A lot of the comments seem out of order and it never seems to get to the ADC ISR at all. Any help is greatly appreciated, I'm likely missing something simple.

Thank You, Joshua

//******************************************************************************
//  MSP432P401 Demo - ADC14, Sample A1, AVcc Ref, Set P1.0 if A1 > 0.5*AVcc
//
//   Description: A single sample is made on A1 with reference to AVcc.
//   Software sets ADC14SC to start sample and conversion - ADC14SC
//   automatically cleared at EOC. ADC14 internal oscillator times sample (16x)
//   and conversion. In Mainloop MSP432 waits in LPM0 to save power until ADC14
//   conversion complete, ADC14_ISR will force exit from LPM0 in Mainloop on
//   reti. If A0 > 0.5*AVcc, P1.0 set, else reset. The full, correct handling of
//   and ADC14 interrupt is shown as well.
//
//
//                MSP432p401rpz
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//        >---|P5.4/A1      P1.0|-->LED
//
//   Dung Dang
//   Texas Instruments Inc.
//   November 2013
//   Built with Code Composer Studio V6.0
//******************************************************************************
#include "msp.h"
#include "stdint.h"

int main(void) {
	volatile unsigned int i;
    WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT

    // GPIO Setup
    P1OUT &= ~BIT0;                           // Clear LED to start
    P1DIR |= BIT0;                            // Set P1.0/LED to output
    P5SEL1 |= BIT4;                           // Configure P5.4 for ADC
    P5SEL0 |= BIT4;

    __enable_interrupt();
    NVIC_ISER0 = 1 << ((INT_ADC14 - 16) & 31);         // Enable ADC interrupt in NVIC module

    // Configure ADC14
    ADC14CTL0 = ADC14SHT0_2 | ADC14SHP | ADC14ON;          // Sampling time, S&H=16, ADC14 on
    ADC14CTL1 = ADC14RES_2;                   // Use sampling timer, 12-bit conversion results

    ADC14MCTL0 |= ADC14INCH_1;                // A1 ADC input select; Vref=AVCC
    ADC14IER0 |= ADC14IE0;                    // Enable ADC conv complete interrupt

    SCB_SCR &= ~SCB_SCR_SLEEPONEXIT;           // Wake up on exit from ISR

    while (1)
    {
      for (i = 20000; i > 0; i--);            // Delay
      ADC14CTL0 |= ADC14ENC | ADC14SC;        // Start sampling/conversion
      __sleep();

//      __bis_SR_register(LPM0_bits | GIE);     // LPM0, ADC14_ISR will force exit
      __no_operation();                       // For debugger
    }




}

// ADC14 interrupt service routine

void ADC14IsrHandler(void) {
//    ADC14CLRIFGR0 |= CLRADC14IFG0;        //Attempt at clearing flag
    if (ADC14MEM0 >= 0x7FF)               // ADC12MEM0 = A1 > 0.5AVcc?
      P1OUT |= BIT0;                      // P1.0 = 1
    else
      P1OUT &= ~BIT0;                     // P1.0 = 0


}

  • Hello Joshua,

    I copied your code excerpt and was able to get it working from the start with CCS V6.1 and TI Compiler V5.2.2. I tested it by wiring the MSP-EXP432P401R 3V3 pin to P5.4, in which case LED1 would turn on. Upon disconnection the LED would turn off. So your firmware is fine, the problem lies somewhere in the hardware. Make sure that the voltage you are supplying to P5.4 is greater than half of AVcc (1.65 V) and you could even try a continuity test between the P5.4 header and pin on the MSP432P401R device to make sure that the connection is sound. You could also make sure that the LED header is properly connected, but seeing as how you aren't able to enter the ADC ISR at all I doubt that this is the issue.

    Guns up,
    Ryan
  • Ryan, thank you for testing it, and for your help. Physically tested the pinout against the header, definitely have continuity between the two. Using the 3V3 pin to drive it, tested that too. The LED works in other programs so I'm sure that's not the issue. Maybe because I'm using the Cloud tools?

    Thanks, Joshua

    P.S. TTU fan, Alumni, or current student?

  • Perhaps so but I'm not entirely sure what would be causing it, that would indicate that something is wrong with the Cloud compiler. Have you experienced proper device operation when using the Cloud tool for other demos? Can you try running the program on a local CCS version instead?

    Regards,
    Ryan

    TTU grad class of '14
  • I have flashed other demos using the cloud developer with no problem. I have not been able to flash via a local version yet. That is my next step.

    Thanks,
    Joshua

    TTU Undergrad
  • Finally got a chance to run it on a local CCS version. It still just gets stuck in the default ISR loop within the startup file.

    Thank you,

    Joshua MacFie

  • hy guys I have a question why do we have to set the P5SEL1 and the P5SEL0 register to run the ADC14.
    I found the table with the settings of these registers and the mentioned 3 different functions.
    Could the ADC14 run by the one of the other 3 functions in the table?
  • Did you ever get this work? I am getting the same results as you have detailed and I can't seem to find out why the ISR isn't triggering.

  • I confirmed that if I check ADC14MEM0 before the __sleep() code LED0 is controlled properly.

    What's odd is that it only works once and if I pause the debugger it is caught in the defaultISR routine of the msp432_startup_ccs.

    I'm running the latest CCS 6.1.2 with all updates applied and working with the sample code so I'm at a loss as to why it seems the USR is not being handled properly.

    **Update** After doing a little more searching I ran across this thread,  which gave me the clus that the startup file didn't get copied over when the project was created. I thought that would be the answer but unfortunately after making that change I am now not able to connect to the board. I don't think it's directly related to this but until I can fix this new error I am no longer able to debug code

  • So I started with a fresh startup file and added in the ADC14IsrHandler reference calls and now the code is working. Not being able to connect was also related to the startup file that I initially copied over from the example directory on my hard drive. I'm not sure what was causing the problems but both issues are now solved.
  • Hi Ryan,

    how did you get running that code?
    Joshua wrote about "the MSP432 ADC example code". I don't know from where he got it and if there is more information how to compile and flash.

    What I did is to create a new project for my MSP432P401R board, c&p the code and tried to compile.
    It failed, because every single label or reference (what ever you call it) is unknown.
    NVIC_ISER0 is unknown, INT_ADC14 is unknown, and so on.

    What do I have to do, to get the code compiled?

    thanks
    Fabian

**Attention** This is a public forum