1 |
|
2 |
|
3 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
4 |
|
5 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
6 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
|
7 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
|
8 |
|
9 | uint32_t getValueADC1(void){
|
10 | /* convert the ADC value (from 0 to 0xFFF) to a voltage value (from 0V to 3.3V)*/
|
11 | return ADC_GetConversionValue(ADC1);
|
12 | }
|
13 | uint32_t getValueADC2(void){
|
14 | /* convert the ADC value (from 0 to 0xFFF) to a voltage value (from 0V to 3.3V)*/
|
15 | return ADC_GetConversionValue(ADC2);
|
16 | }
|
17 | uint32_t getValueADC3(void){
|
18 | /* convert the ADC value (from 0 to 0xFFF) to a voltage value (from 0V to 3.3V)*/
|
19 | return ADC_GetConversionValue(ADC3);
|
20 | }
|
21 |
|
22 | void ADC123_Config(void){
|
23 |
|
24 | /* Configure ADC1 Channel11 pin as analog input */
|
25 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
|
26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
27 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
28 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
29 |
|
30 | /* Configure ADC2 Channel12 pin as analog input */
|
31 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
32 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
33 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
34 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
35 |
|
36 | /* Configure ADC3 Channel13 pin as analog input */
|
37 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
38 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
39 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
40 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
41 |
|
42 | /* ADC Common Init */
|
43 | ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
|
44 | ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div6;
|
45 | ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
46 | ADC_CommonInit(&ADC_CommonInitStructure);
|
47 |
|
48 | /* ADC Init */
|
49 | ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
|
50 | ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
51 | ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
52 | ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
|
53 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
54 | ADC_InitStructure.ADC_NbrOfConversion = 1;
|
55 |
|
56 | ADC_Init(ADC1, &ADC_InitStructure);
|
57 | ADC_Init(ADC2, &ADC_InitStructure);
|
58 | ADC_Init(ADC3, &ADC_InitStructure);
|
59 |
|
60 | /* ADC regular channel configuration */
|
61 | ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_3Cycles);
|
62 | ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
|
63 | ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 1, ADC_SampleTime_3Cycles);
|
64 | /* Enable ADC */
|
65 | ADC_Cmd(ADC1, ENABLE);
|
66 | ADC_Cmd(ADC2, ENABLE);
|
67 | ADC_Cmd(ADC3, ENABLE);
|
68 |
|
69 | /* Start ADC Software Conversion */
|
70 | ADC_SoftwareStartConv(ADC1);
|
71 | ADC_SoftwareStartConv(ADC2);
|
72 | ADC_SoftwareStartConv(ADC3);
|
73 |
|
74 | }
|