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.

TM4C1294使用ADC和DMA,怎样配置DMA传输结束中断

定时器触发ADC采样,之后用DMA把数据传出去,问题出在中断函数是由ADC采样触发的,而不是由DMA传输完成触发,所以请帮忙看一下,怎样配置为DMA传输结束触发中断,代码如下

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
 
#include "utils/uartstdio.h"
 
#include "myfunctions/led.h"
#include "myfunctions/delay.h"
 
#include "driverlib/timer.h"
#include "driverlib/udma.h"
#include "driverlib/adc.h"
#include "driverlib/adc.c"
 
//****************************************************************************
 
// System clock rate in Hz.
 
//****************************************************************************
uint32_t g_ui32SysClock;
 
 
uint32_t ADCBufferA[1024];
uint32_t ADCBufferB[1024];
 
uint32_t ADCBufferACount=0;
uint32_t ADCBufferBCount=0;
 
uint32_t TimeCount;
 
//*****************************************************************************
//
// The control table used by the uDMA controller.  This table must be aligned
// to a 1024 byte boundary.
//
//*****************************************************************************
#if defined(ewarm)
#pragma data_alignment=1024
uint8_t pui8ControlTable[1024];
#elif defined(ccs)
#pragma DATA_ALIGN(pui8ControlTable, 1024)
uint8_t pui8ControlTable[1024];
#else
uint8_t pui8ControlTable[1024] __attribute__ ((aligned(1024)));
#endif
 
//*****************************************************************************
 
// Configure the UART and its pins.  This must be called before UARTprintf().
 
//*****************************************************************************
void
ConsoleInit(void)
{
    // Enable the GPIO Peripheral used by the UART.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
 
    // Enable UART0.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
 
    // Configure GPIO Pins for UART mode.
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
 
    // Initialize the UART for console I/O.
    UARTStdioConfig(0, 115200, g_ui32SysClock);
}
 
void
Timer0AIntHandler()
{
        TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        TimeCount++;
}
 
 
void
ADCIntHandler()
{
        uint32_t ui32Mode;      
        LED_SET(4);
        ADCIntClearEx(ADC0_BASE, ADC_INT_DMA_SS0);
     
        ui32Mode = uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT);
    if(ui32Mode == UDMA_MODE_STOP)
    {
        ADCBufferACount++;
                ADCBufferACount &= 1024;
                ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
                                                                     UDMA_MODE_PINGPONG,
                                                                     (void *)(ADC0_BASE+ADC_O_SSFIFO0),
                                                                     &ADCBufferA[ADCBufferACount*16], 8);
    }   
     
        ui32Mode = uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT);
    if(ui32Mode == UDMA_MODE_STOP)
    {
        ADCBufferBCount++;
                ADCBufferBCount &= 1024;
                ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
                                                                     UDMA_MODE_PINGPONG,
                                                                     (void *)(ADC0_BASE+ADC_O_SSFIFO0),
                                                                     &ADCBufferB[ADCBufferBCount*16], 8);
    }       
         
    if(!ROM_uDMAChannelIsEnabled(UDMA_CHANNEL_ADC0))
    {
                LED_SET(4);
        ROM_uDMAChannelEnable(UDMA_CHANNEL_ADC0);
             
    }
//              UARTprintf("\nBuffer A\n");
        //              UARTprintf("Value:%dmV\t",(ADCBufferA[Index] * 3300)/4096);
                        UARTprintf("\nBuffer A  Value%d:%d\n",ADCBufferACount,ADCBufferA[ADCBufferACount]);
//              UARTprintf("\nBuffer B\n"); 
        //              UARTprintf("Value:%dmV\t",(ADCBufferB[Index] * 3300)/4096);
                        UARTprintf("\nBuffer B  Value%d:%d\n",ADCBufferBCount,ADCBufferB[ADCBufferBCount]);
        if(TimeCount>5)
                ADCIntDisableEx(ADC0_BASE, ADC_INT_DMA_SS0);
        LED_CLR(4);
}
 
int
main(void)
{
     
        //&Aring;&auml;&Ouml;&Atilde;&Ecirc;±&Ouml;&Oacute;120MHz
        g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                SYSCTL_CFG_VCO_480), 120000000);
     
        //&Aring;&auml;&Ouml;&Atilde;UART0
        ConsoleInit();  
        //&Aring;&auml;&Ouml;&Atilde;LED
        LED_Init();
     
        //&Aring;&auml;&Ouml;&Atilde;TIMER 0
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
        TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock);
        TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler);
        IntEnable(INT_TIMER0A);
        TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        TimerEnable(TIMER0_BASE, TIMER_A);
 
        //&Ecirc;&sup1;&Auml;&Uuml;DMA&Auml;&pound;&iquest;é
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
        uDMAEnable();
        uDMAControlBaseSet(pui8ControlTable);       
         
        //&Ecirc;&sup1;&Auml;&Uuml;ADC0&Auml;&pound;&iquest;é
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        //&Aring;&auml;&Ouml;&Atilde;&sup2;&Eacute;&Ntilde;ù&ETH;ò&Aacute;&ETH;&micro;&Auml;&acute;&yen;·&cent;&Ocirc;&acute;&ordm;&Iacute;&Oacute;&Aring;&Iuml;&Egrave;&frac14;&para;
        ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
        //&Aring;&auml;&Ouml;&Atilde;ADC&acute;&yen;·&cent;
        TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
         
        //&Aring;&auml;&Ouml;&Atilde;ADC&Ouml;&ETH;&para;&Iuml;
        ADCIntEnable(ADC0_BASE, 0);
        //&Ouml;&ETH;&para;&Iuml;&Ntilde;&iexcl;&Ocirc;&ntilde;
        ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS0);
        //×&cent;&sup2;á&Ouml;&ETH;&para;&Iuml;&ordm;&macr;&Ecirc;&yacute;
        ADCIntRegister(ADC0_BASE, 0, ADCIntHandler);
        //&Ecirc;&sup1;&Auml;&Uuml;ADC&Ouml;&ETH;&para;&Iuml;
        IntEnable(INT_ADC0SS0);     
         
        //&Aring;&auml;&Ouml;&Atilde;&sup2;&Eacute;&Ntilde;ù&ETH;ò&Aacute;&ETH;&micro;&Auml;&frac12;&Uacute;&Aring;&Auml;
        ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH0 | ADC_CTL_END);
        //&Ecirc;&sup1;&Auml;&Uuml;&sup2;&Eacute;&Ntilde;ù&ETH;ò&Aacute;&ETH;&micro;&Auml;DMA&acute;&laquo;&Ecirc;&auml;
        ADCSequenceDMAEnable(ADC0_BASE, 0);
 
        //&Aring;&auml;&Ouml;&Atilde;&Iacute;¨&micro;&Agrave;&Ecirc;&ocirc;&ETH;&Ocirc;     
        ROM_uDMAChannelControlSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
                                                            UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_32 |
                                                            UDMA_ARB_4);
    ROM_uDMAChannelControlSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
                              UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_32 |
                              UDMA_ARB_4);          
        //&Aring;&auml;&Ouml;&Atilde;&acute;&laquo;&Ecirc;&auml;&sup2;&Icirc;&Ecirc;&yacute;    
    ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
                               UDMA_MODE_PINGPONG,
                               (void *)(ADC0_BASE+ADC_O_SSFIFO0),
                               ADCBufferA, 8);
    ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
                               UDMA_MODE_PINGPONG,
                               (void *)(ADC0_BASE+ADC_O_SSFIFO0),
                               ADCBufferB, 8);
        //&Ecirc;&sup1;&Auml;&Uuml;&Iacute;¨&micro;&Agrave;
        ROM_uDMAChannelEnable(UDMA_CHANNEL_ADC0);
        //&Ecirc;&sup1;&Auml;&Uuml;&sup2;&Eacute;&Ntilde;ù&ETH;ò&Aacute;&ETH;
        ADCSequenceEnable(ADC0_BASE, 0);
         
        IntMasterEnable();
         
        LED_SET(1);
        while(1)
        {
                LED_SET(2); 
                Delay_ms(200);
                LED_CLR(2);
                Delay_ms(200);
                if(TimeCount>6)
                        break;
        }
        uint32_t Index;
        UARTprintf("\nBuffer A\n");
        for(Index=0;Index<128;Index++)
//              UARTprintf("Value:%dmV\t",(ADCBufferA[Index] * 3300)/4096);
                UARTprintf("Value:%d\t",ADCBufferA[Index]);
        UARTprintf("\nBuffer B\n"); 
        for(Index=0;Index<128;Index++)
//              UARTprintf("Value:%dmV\t",(ADCBufferB[Index] * 3300)/4096);
                UARTprintf("Value:%d\t",ADCBufferB[Index]);
        while(1)
        {
                LED_SET(3); 
                Delay_ms(500);
                LED_CLR(3);
                Delay_ms(500);
        }
}
x 出现错误。请重试或与管理员联系。