2019-03-24 09:03发布
火火山 发表于 2016-8-17 22:53 没有休眠,不是停在哪里,而是循环第三次之后就停不到造white循环的断点上面,而是直接全速运行了
littleshrimp 发表于 2016-8-17 23:22 是停了还是全速运行? 看你的代码里明明有休眠 时钟你是怎么配置的
huaiqiao 发表于 2016-8-17 22:56 停在哪里,看寄存器的值。 要根据语句找到相应的寄存器啊,然后看寄存器里面位的值,是不是你想要的值。 ...
最多设置5个标签!
还有 你用的那个型号的单片机
能把代码全发出来吗
不对呀,while循环中有唤醒的语句啊,会醒来才对
- #include <msp430.h>
- #include "driverlib.h"
- void main(void)
- {
- // stop watchdog
- WDT_A_hold(WDT_A_BASE);
- PMM_unlockLPM5();
- // 设置内部DCO频率为1MHz
- CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
- // 设置SMCLK时钟源来自DCO
- CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
- GPIO_setAsOutputPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- //Set P1.0 as Output Low.
- /*
- * Select Port 1
- * Set Pin 0 to output Low.
- */
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- //Set P1.1 as Ternary Module Function Output.
- /*
- * Select Port 1
- * Set Pin 1 to output Ternary Module Function, (A1, C1, VREF+, VeREF+).
- */
- GPIO_setAsPeripheralModuleFunctionOutputPin(
- GPIO_PORT_P1,
- GPIO_PIN1,
- GPIO_TERNARY_MODULE_FUNCTION
- );
- //Initialize the ADC12B Module
- /*
- * Base address of ADC12B Module
- * Use internal ADC12B bit as sample/hold signal to start conversion
- * USE MODOSC 5MHZ Digital Oscillator as clock source
- * Use default clock divider/pre-divider of 1
- * Not use internal channel
- */
- ADC12_B_initParam initParam = {0};
- initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
- initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
- initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
- initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
- initParam.internalChannelMap = ADC12_B_NOINTCH;
- ADC12_B_init(ADC12_B_BASE, &initParam);
- //Enable the ADC12B module
- ADC12_B_enable(ADC12_B_BASE);
- /*
- * Base address of ADC12B Module
- * For memory buffers 0-7 sample/hold for 64 clock cycles
- * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
- * Disable Multiple Sampling
- */
- ADC12_B_setupSamplingTimer(ADC12_B_BASE,
- ADC12_B_CYCLEHOLD_16_CYCLES,
- ADC12_B_CYCLEHOLD_4_CYCLES,
- ADC12_B_MULTIPLESAMPLESDISABLE);
- //Configure Memory Buffer
- /*
- * Base address of the ADC12B Module
- * Configure memory buffer 0
- * Map input A1 to memory buffer 0
- * Vref+ = AVcc
- * Vref- = AVss
- * Memory buffer 0 is not the end of a sequence
- */
- ADC12_B_configureMemoryParam configureMemoryParam = {0};
- configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
- configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A1;
- configureMemoryParam.refVoltageSourceSelect =
- ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
- configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
- configureMemoryParam.windowComparatorSelect =
- ADC12_B_WINDOW_COMPARATOR_DISABLE;
- configureMemoryParam.differentialModeSelect =
- ADC12_B_DIFFERENTIAL_MODE_DISABLE;
- ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
- ADC12_B_clearInterrupt(ADC12_B_BASE,
- 0,
- ADC12_B_IFG0
- );
- //Enable memory buffer 0 interrupt
- ADC12_B_enableInterrupt(ADC12_B_BASE,
- ADC12_B_IE0,
- 0,
- 0);
- while(1)
- {
- __delay_cycles(5000);
- //Enable/Start sampling and conversion
- /*
- * Base address of ADC12B Module
- * Start the conversion into memory buffer 0
- * Use the single-channel, single-conversion mode
- */
- ADC12_B_startConversion(ADC12_B_BASE,
- ADC12_B_MEMORY_0,
- ADC12_B_SINGLECHANNEL);
- __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_B_ISR will force exit
- __no_operation(); // For debugger
- }
- }
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector=ADC12_VECTOR
- __interrupt
- #elif defined(__GNUC__)
- __attribute__((interrupt(ADC12_VECTOR)))
- #endif
- void ADC12_ISR(void)
- {
- switch(__even_in_range(ADC12IV,12))
- {
- case 0: break; // Vector 0: No interrupt
- case 2: break; // Vector 2: ADC12BMEMx Overflow
- case 4: break; // Vector 4: Conversion time overflow
- case 6: break; // Vector 6: ADC12BHI
- case 8: break; // Vector 8: ADC12BLO
- case 10: break; // Vector 10: ADC12BIN
- case 12: // Vector 12: ADC12BMEM0 Interrupt
- if(ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0) >= 0x7ff)
- {
- //Set P1.0 LED on
- /*
- * Select Port 1
- * Set Pin 0 to output high.
- */
- GPIO_setOutputHighOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
- else
- {
- //Set P1.0 LED off
- /*
- * Select Port 1
- * Set Pin 0 to output high.
- */
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
- __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
- break; // Clear CPUOFF bit from 0(SR)
- case 14: break; // Vector 14: ADC12BMEM1
- case 16: break; // Vector 16: ADC12BMEM2
- case 18: break; // Vector 18: ADC12BMEM3
- case 20: break; // Vector 20: ADC12BMEM4
- case 22: break; // Vector 22: ADC12BMEM5
- case 24: break; // Vector 24: ADC12BMEM6
- case 26: break; // Vector 26: ADC12BMEM7
- case 28: break; // Vector 28: ADC12BMEM8
- case 30: break; // Vector 30: ADC12BMEM9
- case 32: break; // Vector 32: ADC12BMEM10
- case 34: break; // Vector 34: ADC12BMEM11
- case 36: break; // Vector 36: ADC12BMEM12
- case 38: break; // Vector 38: ADC12BMEM13
- case 40: break; // Vector 40: ADC12BMEM14
- case 42: break; // Vector 42: ADC12BMEM15
- case 44: break; // Vector 44: ADC12BMEM16
- case 46: break; // Vector 46: ADC12BMEM17
- case 48: break; // Vector 48: ADC12BMEM18
- case 50: break; // Vector 50: ADC12BMEM19
- case 52: break; // Vector 52: ADC12BMEM20
- case 54: break; // Vector 54: ADC12BMEM21
- case 56: break; // Vector 56: ADC12BMEM22
- case 58: break; // Vector 58: ADC12BMEM23
- case 60: break; // Vector 60: ADC12BMEM24
- case 62: break; // Vector 62: ADC12BMEM25
- case 64: break; // Vector 64: ADC12BMEM26
- case 66: break; // Vector 66: ADC12BMEM27
- case 68: break; // Vector 68: ADC12BMEM28
- case 70: break; // Vector 70: ADC12BMEM29
- case 72: break; // Vector 72: ADC12BMEM30
- case 74: break; // Vector 74: ADC12BMEM31
- case 76: break; // Vector 76: ADC12BRDY
- default: break;
- }
- }
复制代码嗯呢呢,谢谢哦,经常看见你的哈
你好,时钟使用的是ADC内部的那个MODCLK时钟
你好,我单步调试后,发现程序停在了这个地方,如图所示,从ADC的中断出来后,程序就一直停在箭头所指的地方,等待唤醒。
我的问题是:为什么会一直停在是 __bis_SR_register(LPM0_bits + GIE); 这个地方,而不会进入while循环?
代码已经在原帖的回帖中贴出。
麻烦指导一下,谢谢。
一周热门 更多>