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.

MSP430FR2476: ADC Deiverlib example code not working

Part Number: MSP430FR2476

Tool/software:

Hi,

I tried an adc example code from driverlib library. But the code is stuck in ADC Start conversion. Please help me.

Thank you

Athulya


#include "driverlib.h"
#include "Board.h"

uint16_t result =0;

void main (void)
{
//Stop Watchdog Timer
WDT_A_hold(WDT_A_BASE);

//Set ACLK = REFOCLK with clock divider of 1
CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1);
//Set SMCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
//Set MCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);

//Set A7 as an input pin.
//Set appropriate module function
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_ADC7,
GPIO_PIN_ADC7,
GPIO_FUNCTION_ADC7);

// //Set LED1 as an output pin.
// GPIO_setAsOutputPin(
// GPIO_PORT_LED1,
// GPIO_PIN_LED1);
//
// //Set LED2 as an output pin.
// GPIO_setAsOutputPin(
// GPIO_PORT_LED2,
// GPIO_PIN_LED2);

/*
* Disable the GPIO power-on default high-impedance mode to activate
* previously configured port settings
*/
PMM_unlockLPM5();

//Initialize the ADC Module
/*
* Base Address for the ADC Module
* Use internal ADC bit as sample/hold signal to start conversion
* USE MODOSC 5MHZ Digital Oscillator as clock source
* Use default clock divider of 1
*/
ADC_init(ADC_BASE,
ADC_SAMPLEHOLDSOURCE_SC,
ADC_CLOCKSOURCE_SMCLK ,
ADC_CLOCKDIVIDER_1);

ADC_enable(ADC_BASE);

/*
* Base Address for the ADC Module
* Sample/hold for 16 clock cycles
* Do not enable Multiple Sampling
*/
ADC_setupSamplingTimer(ADC_BASE,
ADC_CYCLEHOLD_16_CYCLES,
ADC_MULTIPLESAMPLESDISABLE);

//Configure Memory Buffer
/*
* Base Address for the ADC Module
* Use input A7
* Use positive reference of AVcc
* Use negative reference of AVss
*/
ADC_configureMemory(ADC_BASE,
ADC_INPUT_A7,
ADC_VREFPOS_AVCC,
ADC_VREFNEG_AVSS);

ADC_clearInterrupt(ADC_BASE,
ADC_COMPLETED_INTERRUPT);

//Enable Memory Buffer interrupt
ADC_enableInterrupt(ADC_BASE,
ADC_COMPLETED_INTERRUPT);

for (;;)
{
//Delay between conversions
__delay_cycles(5000);

//Enable and Start the conversion
//in Single-Channel, Single Conversion Mode
ADC_startConversion(ADC_BASE,ADC_SINGLECHANNEL);

//LPM0, ADC10_ISR will force exit
__bis_SR_register(CPUOFF + GIE);
//For debug only
__no_operation();


}
}

//ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(ADC_VECTOR)))
#endif
void ADC_ISR (void)
{
switch (__even_in_range(ADCIV,12)){
case 0: break; //No interrupt
case 2: break; //conversion result overflow
case 4: break; //conversion time overflow
case 6: break; //ADC10HI
case 8: break; //ADC10LO
case 10: break; //ADC10IN
case 12: //ADC10IFG0
//(Automatically clears ADC10IFG0 by reading memory buffer)
result = ADC_getResults(ADC_BASE);
// if (ADC_getResults(ADC_BASE) < 0x1FF){
//
// //Turn LED1 off
// GPIO_setOutputLowOnPin(
// GPIO_PORT_LED1,
// GPIO_PIN_LED1
// );
//
// //Turn LED2 off
// GPIO_setOutputLowOnPin(
// GPIO_PORT_LED2,
// GPIO_PIN_LED2
// );
// }
// else {
// //Turn LED1 on
// GPIO_setOutputHighOnPin(
// GPIO_PORT_LED1,
// GPIO_PIN_LED1
// );
//
// //Turn LED2 on
// GPIO_setOutputHighOnPin(
// GPIO_PORT_LED2,
// GPIO_PIN_LED2
// );
// }

//Clear CPUOFF bit from 0(SR)
//Breakpoint here and watch ADC_Result
__bic_SR_register_on_exit(CPUOFF);
break;
default: break;
}
}

  • How do you tell that it's stuck? Breakpoint in the ISR? Change in "results"?

    Your program spends most of its time in _delay_cycles(), so if you pause it the next line will (usually) be the call to ADC_startConversion().

  • Hi,

    I put brake point in ISR, but not hit .  And I chake the valune of result, it is always 0.

    Thnak you

    Athulya

  • I don't see this behavior on my Launchpad -- the ISR is called repeatedly, "result" changes (nothing is connected to P1.7), and when I pause it is executing in _delay_cycles().

    I had to supply my own Board.h stanza for the FR2476, and you presumably also did. I can't think of what changes would have affected your symptom, but all the same: What did you provide there?

    [Edit: I should have told you what I did. I added:

    #ifdef __MSP430FR2476__ // BMC added
    #define GPIO_PORT_ADC7          GPIO_PORT_P1
    #define GPIO_PIN_ADC7           GPIO_PIN7
    #define GPIO_FUNCTION_ADC7      GPIO_TERNARY_MODULE_FUNCTION
    #endif
    

    ]

**Attention** This is a public forum