1 void ADC_Configure(void) 2 { 3 ADC_InitTypeDef ADC_InitStructure; 4 GPIO_InitTypeDef GPIO_InitStructure; 5 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); 6 RCC_AHBPeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); 7 8 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; 9 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; 10 GPIO_Init(GPIOA, &GPIO_InitStructure); 11 12 RCC_ADCCLKConfig(RCC_PCLK2_Div4); //配置ADC时钟分频 2,4,6,8 13 ADC_InitStructure.ADC_Mode=ADC_Mode_Independent; //独立工作模式 14 ADC_InitStructure.ADC_ScanConvMode=ENABLE; //工作在扫描模式 15 ADC_InitStructure.ADC_ContinuousConvMode=ENABLE; //连续模式 16 ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; //转换由软件触发启动 17 //ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T1_CC1; //定时器1的捕获比较通道1作为外部触发转换源(T1_2,T1_3,T2_2,T4_4) 18 //ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_Ext_1T11; //外部中断通道11的事件作为外部触发转换源 19 ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; //ADC数据右对齐 20 ADC_InitStructure.ADC_NbrOfChannel =5; //进行规则转换的ADC通道的数目为2 21 ADC_Init(ADC1,&ADC_InitStructure); 22 ADC_RegularChannelConfig(ADC1,ADC_Channel_2,1,ADC_SampleTime_55Cycles5); //选择通道2,转换顺序1,采样时间为1.5周期 23 ADC_RegularChannelConfig(ADC1,ADC_Channel_3,2,ADC_SampleTime_55Cycles5); //选择通道3,转换顺序2,采样时间为1.5周期 24 ADC_RegularChannelConfig(ADC1,ADC_Channel_4,3,ADC_SampleTime_55Cycles5); //选择通道4,转换顺序3,采样时间为1.5周期 25 ADC_RegularChannelConfig(ADC1,ADC_Channel_5,4,ADC_SampleTime_55Cycles5); //选择通道5,转换顺序4,采样时间为1.5周期 26 ADC_RegularChannelConfig(ADC1,ADC_Channel_6,5,ADC_SampleTime_55Cycles5); //选择通道6,转换顺序5,采样时间为1.5周期 27 ADC_DMACmd(ADC1, ENABLE); 28 ADC_Cmd(ADC1,ENABLE); //使能AD1 29 ADC_ResetCalibration(ADC1); //复位ADC1的校准寄存器 30 ADC_StartCalibration(ADC1); //开始ADC1的校准 31 while(ADC_GetCalibrationStatus(ADC1)); //等待ADC1校准完成 32 ADC_SoftwareStartConvCmd(ADC1,ENABLE); //启动ADC1转换 33 } 34 void DMA_Configure(void) 35 { 36 DMA_InitTypeDef DMA_InitStructure; 37 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); 38 DMA_DeInit(DMA1_Channel1); //复位DMA1通道 39 DMA_InitStructure.DMA_PeripheralBaseAddr=DR_ADDRESS; 40 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ad_value; 41 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //外设作为数据传输的来源 42 DMA_InitStructure.DMA_M2M=DMA_M2M_Disable; 43 DMA_InitStructure.DMA_BufferSize = 5; // 44 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址不变 45 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址递增 46 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //外设数据宽度为16位 47 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //内存数据宽度为16位 48 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //循环缓存模式 49 DMA_InitStructure.DMA_Priority = DMA_Priority_High; //高优先级 50 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //没有设置内存到内存的传输 51 DMA_Init(DMA1_Channel1, &DMA_InitStructure); 52 DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); 53 DMA_Cmd(DMA1_Channel1,ENABLE); //开启DMA1通道传输 54 }