请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430FR2476 工具与软件:
您好!
我尝试了 driverlib 库中的 ADC 示例代码。 但代码卡在 ADC 启动转换中。 请帮帮我。
谢谢你
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; } }