定时器触发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)
- {
-
- //ÅäÖÃʱÖÓ120MHz
- g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
- SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
- SYSCTL_CFG_VCO_480), 120000000);
-
- //ÅäÖÃUART0
- ConsoleInit();
- //ÅäÖÃLED
- LED_Init();
-
- //ÅäÖÃ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);
- //ʹÄÜDMAÄ£¿é
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
- uDMAEnable();
- uDMAControlBaseSet(pui8ControlTable);
-
- //ʹÄÜADC0Ä£¿é
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
- //ÅäÖòÉÑùÐòÁеĴ¥·¢Ô´ºÍÓÅÏȼ¶
- ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
- //ÅäÖÃADC´¥·¢
- TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
-
- //ÅäÖÃADCÖжÏ
- ADCIntEnable(ADC0_BASE, 0);
- //ÖжÏÑ¡Ôñ
- ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS0);
- //×¢²áÖжϺ¯Êý
- ADCIntRegister(ADC0_BASE, 0, ADCIntHandler);
- //ʹÄÜADCÖжÏ
- IntEnable(INT_ADC0SS0);
-
- //ÅäÖòÉÑùÐòÁеĽÚÅÄ
- 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);
- //ʹÄܲÉÑùÐòÁеÄDMA´«Êä
- ADCSequenceDMAEnable(ADC0_BASE, 0);
- //ÅäÖÃͨµÀÊôÐÔ
- 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);
- //ÅäÖô«Êä²ÎÊý
- 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);
- //ʹÄÜͨµÀ
- ROM_uDMAChannelEnable(UDMA_CHANNEL_ADC0);
- //ʹÄܲÉÑùÐòÁÐ
- 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);
- }
- }
复制代码
|