1 | static void Init_ADC1()
|
2 | {
|
3 | GPIO_InitTypeDef GPIO_InitStructure;
|
4 | ADC_InitTypeDef ADC_InitStructure;
|
5 | ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
6 |
|
7 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
8 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
9 |
|
10 |
|
11 | /* Configure ADC1 Channel1 Channel2 Channel3 pin as analog input ******************************/
|
12 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
|
13 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
14 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
15 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
16 |
|
17 |
|
18 | /* ADC Common Init **********************************************************/
|
19 | ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
|
20 | ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
|
21 | ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
|
22 | ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
23 | ADC_CommonInit(&ADC_CommonInitStructure);
|
24 |
|
25 | /* ADC1 Init ****************************************************************/
|
26 | ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
|
27 | ADC_InitStructure.ADC_ScanConvMode = DISABLE; //DISABLE
|
28 | ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //ENABLE
|
29 | ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
|
30 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
31 | ADC_InitStructure.ADC_NbrOfConversion = 2;
|
32 | ADC_Init(ADC1, &ADC_InitStructure);
|
33 |
|
34 | ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);
|
35 | ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_3Cycles);
|
36 |
|
37 | ADC_Cmd(ADC1, ENABLE);
|
38 | ADC_SoftwareStartConv(ADC1);
|
39 | }
|