/* DMA1 channel1 configuration ----------------------------------------------*/
/* DMA2 channel5 configuration ----------------------------------------------*/
#include "stm32f10x.h"
#include "ADC_Init.h"
#define ConvSuccess (1)
#define ADC1CounvNum (16)
#define ADC3CounvNum (5)
/**************************************************************************
**函数功能 :ADC的配置文件
**入口参数 :无
**出口参数 :无
**调用本函数:main.c
**************************************************************************/
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// RCC_ADCCLKConfig(RCC_PCLK2_Div4);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3| RCC_APB2Periph_GPIOA
| RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOF, ENABLE);
/* Configure PA as analog input -------------------------*/
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|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PB as analog input -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure PC as analog input -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3
|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PF as analog input -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9
|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOF, &GPIO_InitStructure);
ADC_DeInit(ADC1);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = ADC1CounvNum;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel5 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 5, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 6, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 7, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 8, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 9, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 10, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10,11, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11,12, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12,13, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13,14, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14,15, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15,16, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA */
// ADC_DMACmd(ADC1, ENABLE);
ADC_DeInit(ADC3);
/* ADC3 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = ADC3CounvNum;
ADC_Init(ADC3, &ADC_InitStructure);
/* ADC3 regular channel14 configuration */
ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 1, ADC_SampleTime_7Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_5, 2, ADC_SampleTime_7Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 3, ADC_SampleTime_7Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_7, 4, ADC_SampleTime_7Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_8, 5, ADC_SampleTime_7Cycles5);
/* Enable ADC3 DMA */
//ADC_DMACmd(ADC3, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 reset calibration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Enable ADC3 */
ADC_Cmd(ADC3, ENABLE);
ADC_DMACmd(ADC3, ENABLE);
/* Enable ADC3 reset calibration register */
ADC_ResetCalibration(ADC3);
/* Check the end of ADC3 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC3));
/* Start ADC3 calibration */
ADC_StartCalibration(ADC3);
/* Check the end of ADC3 calibration */
while(ADC_GetCalibrationStatus(ADC3));
DMA_Cmd(DMA1_Channel1, ENABLE);
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
DMA_Cmd(DMA2_Channel5, ENABLE);
/* Start ADC3 Software Conversion */
ADC_SoftwareStartConvCmd(ADC3, ENABLE);
}
用户377235 2015-12-22 18:24