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.
工具与软件:
您好!
我尝试了 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; } }
您如何告知它卡住了? ISR 中的断点? "结果"中的变化?
你的程序大部分时间都用在_delay_cycles (),所以如果你暂停它,下一行(通常)将是对 ADC_startConversion()的调用。
您好!
我把制动点放在 ISR 中,但没有命中。 并且我选择了结果的有效值、它始终为0。
"你是我的
Athulya
我在我的 Launchpad 上看不到这种行为——ISR 被重复调用,"结果"改变(没有连接到 P1.7 ),当我暂停时,它在_delay_cycles ()中执行。
我必须为 FR2476提供我自己的 Board.h stanza、据推测您也提供了该设备。 我想不出哪些变化会影响你的症状、但都是一样的:你在那里提供了什么?
[编辑:我应该告诉你我做了什么。 我添加了:
#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
]