程序是在官方的MSP430FR57xx_adc10_10.c —-ADC10, DMA Sample A2-0, 8-bit Res, Single Sequence, DCO上做了一点点的修改的。原官方的程序能正常运行,我想使用中断的方式读取ADC转换的数据,发现不能正常运行。
程序在仿真的时候只触发了一次中断,不会自动切换到下一通道。看寄存器的值,符合切换 ADC10MSC=1 、 ADC10SHP=1 、x!=0 的条件,但是程序就是不会再触发ADC的中断。
程序:
#include <msp430.h> unsigned int ADC_Result[3];// ADC conversion result array unsigned char i; int main(void) {WDTCTL = WDTPW+WDTHOLD;// Stop WDTP3DIR |= BIT5 +BIT6 + BIT7;// Set LEDs to outputP3OUT |= BIT5 +BIT6 + BIT7;// Configure ADC pinsP1SEL0 |= BIT0 + BIT1 + BIT2;P1SEL1 |= BIT0 + BIT1 + BIT2;// Configure ADC10ADC10CTL0 = ADC10SHT_2 + ADC10MSC + ADC10ON;// 16ADCclks, MSC, ADC ONADC10CTL1 = ADC10SHP + ADC10CONSEQ_1;// sampling timer, s/w trig.,single sequenceADC10MCTL0 =ADC10INCH_2;// A0,A1,A2(EoS), AVCC referenceADC10IE |= ADC10IE0;// Enable ADC conv complete interruptfor (;;){i = 2;while (ADC10CTL1 & BUSY);// Wait if ADC10 core is activeADC10CTL0 |= ADC10ENC + ADC10SC;// Sampling and conversion start__bis_SR_register(CPUOFF + GIE);// LPM0, ADC10_ISR will force exitif (ADC_Result[0] < 0x1FF)P3OUT &= ~BIT5;// Clear LED offelseP3OUT |= BIT5;// Set LED onif (ADC_Result[1] < 0x1FF)P3OUT &= ~BIT6;// Clear LED offelseP3OUT |= BIT6;// Set LED onif (ADC_Result[2] < 0x1FF)P3OUT &= ~BIT7;// Clear LED offelseP3OUT |= BIT7;// Set LED on} } // ADC10 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void) #else #error Compiler not supported! #endif {switch(__even_in_range(ADC10IV,12)){case 0: break;// No interruptcase 2: break;// conversion result overflowcase 4: break;// conversion time overflowcase 6: break;// ADC10HIcase 8: break;// ADC10LOcase 10: break;// ADC10INcase 12:ADC_Result[i] = ADC10MEM0;if(i == 0){__bic_SR_register_on_exit(CPUOFF);}else{i--;}break;default: break;} }
Susan Yang:
建议您先单通道单次试试
灰小子:
仿真的时候有时不准的,可能三次中断都触发了只是没观察到
建议烧写到msp430,独立运行,把采样的三个数打印出来观察
user1867626:
回复 Susan Yang:
单通道没有问题,,还有在这个程序的基础上如果使用DMA做数据传输通道是没有问题的。
user1867626:
回复 灰小子:
多通道独立运行也没有效果,单通道没有问题。