************************************************************************/
#include "common.h"
#include "ics.h"
#include "rtc.h"
#include "uart.h"
#include "adc.h"
#include "dma.h"
#include "pmc.h"
#include "sysinit.h"
/**********************************************************************/
uint16_t u16ADC_ConversionBuff[16];
int main (void);
void DMA_Group0_Task(void);
/******************************************************************************/
int main (void)
{
//uint8_t u8Ch = 0;
ADC_ConfigType sADC_Config = {0};
DMAMUX_ConfigType DMAMUX_Config;
DMA_ConfigType DMA_Config={0};
/*系统初始化*/
sysinit();
printf("\nRunning the ADC_DMA_demo project.\r\n");
UART_WaitTxComplete(TERM_PORT);
LED0_Init();
/*DMA初始化*/
DMA_Config.sSetting.bEnableDebug=1; /*在调试模式下,DMA会停新通道启动*/
DMA_int(DMA,&DMA_Config);
/*设置DMAMUX,选择DMA通道,DMA传输触发模式及信号请求源*/
DMAMUX_Config.sSetting.bChannelEnable=1; /*使能DMA通道*/
DMAMUX_Config.sSetting.bChannelTriggerEn=0; /*通过设定的DMA触发源触发DMA传输*/
DMAMUX_Config.u8ChannelSource=ADC0_DMAREQ; /*ADC转换完成信号请求DMA通道传输*/
DMAMUX_ChannelConfig(DMAMUX,&DMAMUX_Config,DMA_CHANNEL0);
/*配置DMA通道TCD*/
DMA_Config.sSetting.bEnRequest=1; /*使能通道硬件请求信号*/
DMA_Config.sSetting.bEnErrIn=1; /*使能DMA通道错误中断*/
DMA_Config.u32Saddr=(uint32_t)(&ADC0->R); /*源地址*/
DMA_Config.u8Ssize=DMA_DATA_TRANSFER_SIZE2; /*每次r/w序列从源地址中读取2个字节*/
DMA_Config.s16Soff=0; /*每次从源地址读取一次数据后,源地址加0*/
DMA_Config.u8Smod=DMA_ModuloDisable; /*禁用源地址模数功能*/
DMA_Config.s32Slast=0; /*主循环结束后源地址偏移量*/
DMA_Config.u32Daddr=(uint32_t)u16ADC_ConversionBuff; /*目标地址*/
DMA_Config.u8Dsize=DMA_DATA_TRANSFER_SIZE2; /*每次向目标地址写入2个字节*/
DMA_Config.s16Doff=2; /*每次向目标地址写入一次数据后目标地址加2*/
DMA_Config.u8Dmod= DMA_ModuloDisable; /*目标地址禁用模数功能*/
DMA_Config.s32Dlastga=-16; /*主循环结束目标地址-16*/
DMA_Config.u32Nbytes=16; /*每次次循环传输16个字节,注:次循环传输字节数,受次循环映射影响*/
DMA_Config.u16Biter=1; /*主循环迭代次数为1,注:主循环迭代次数,受次循环结束后通道链功能影响*/
DMA_Config.u8Bwc=0; /*DMA引擎不停转*/
DMA_Config.sSetting.bDisableRequest=0; /*主循环结束后不禁用通道硬件请求信号*/
DMATCD_ChannelConfig(DMA,&DMA_Config,DMA_CHANNEL0);
DMA_INTConfig(DMA,DMA_INT_Major,DMA_EnInt,DMA_CHANNEL0); /*中断设置*/
DMA_SetCallback(DMA,DMA_IntGroup1,DMA_Group0_Task); /*注册回调函数*/
/*初始化ADC模块*/
sADC_Config.u8ClockDiv = ADC_ADIV_DIVIDE_8; /*!< ADC时钟源分频系数为8*/
sADC_Config.u8ClockSource = CLOCK_SOURCE_ADACK; /*!< ADC时钟源选择异步时钟*/
sADC_Config.u8Mode = ADC_MODE_12BIT; /*!< 12位转换*/
sADC_Config.sSetting.bDmaEn = 1; /*!< ADC转换完成触发DMA搬运数据*/
sADC_Config.sSetting.bIntEn = 1; /*!< 使能中断*/
sADC_Config.u8FiFoLevel = ADC_FIFO_LEVEL8; /*!< 8级FIFO */
ADC_Init( ADC0, &sADC_Config); /*!< 初始化ADC*/
while(1)
{
/*选择通道开始转换*/
ADC_SetChannel(ADC0,ADC_CHANNEL_AD14_TEMPSENSOR);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD29_VREFH);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD30_VREFL);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD14_TEMPSENSOR);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD29_VREFH);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD30_VREFL);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD29_VREFH);
ADC_SetChannel(ADC0,ADC_CHANNEL_AD30_VREFL);
printf("input any character to start a new conversion!\r\n");
UART_GetChar(TERM_PORT);
}
}
|