学习用dma不太明白的是我的while循环,只运行了一次,为什么保存采样数据的数组保存了511个数据;用的是官方给的例程;adc10和dma的配置没有改
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.
#include <msp430.h> unsigned int ADC_Result[512]; unsigned int i = 0; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT P6SEL = BIT1; // Configure ADC10 - pulse sample mode; software trigger; ADC10CTL0 = ADC10SHT_2 | ADC10ON | ADC10MSC; // 16ADCclks, ADC on ADC10CTL1 = ADC10SHP | ADC10CONSEQ_2; // pulse sample mode, rpt single ch ADC10CTL2 = ADC10RES; // 10-bits of re;solution ADC10MCTL0 = ADC10INCH_1; // AVCC ref, A1 // Configure DMA (ADC10IFG trigger) DMACTL0 = DMA0TSEL_24; // ADC10IFG trigger __data16_write_addr((unsigned short) &DMA0SA,(unsigned long) &ADC10MEM0); // Source single address __data16_write_addr((unsigned short) &DMA0DA,(unsigned long) &ADC_Result[0]); // Destination array address DMA0SZ = 512; // 64 conversions DMA0CTL = DMADT_4 | DMADSTINCR_3 | DMAEN | DMAIE; // Rpt, inc dest, word access, // enable int after 64 conversions while(1) { ADC10CTL0 |= ADC10ENC | ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF | GIE); // LPM0, ADC10_ISR will force exit i++; } } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=DMA_VECTOR __interrupt void DMA0_ISR (void) #elif defined(__GNUC__) void __attribute__ ((interrupt(DMA_VECTOR))) DMA0_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(DMAIV,16)) { case 0: break; // No interrupt case 2: // sequence of conversions complete __bic_SR_register_on_exit(CPUOFF); ADC10CTL0 &= ~ADC10ENC; // Disable ADC conversion P4OUT ^= BIT3; break; // DMA0IFG case 4: break; // DMA1IFG case 6: break; // DMA2IFG case 8: break; // Reserved case 10: break; // Reserved case 12: break; // Reserved case 14: break; // Reserved case 16: break; // Reserved default: break; } }
这是代码
要理解DMA的机制,对于你的历程来说,是由AD采样触发DMA事件,当DMA事件积累到一定数量,才产生DMA中断,通知处理器去处理数据
对于你的程序DMA0SZ=512;来说也就是产生了512次DMA事件后才中断处理器