35
35
#include "error.h"
36
36
37
37
static const PinMap PinMap_ADC [] = {
38
- {PA_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
39
- {PA_1 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
40
- {PA_4 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
41
- {PB_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
42
- {PC_1 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
43
- {PC_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AIN , 0 )},
38
+ {PA_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN0
39
+ {PA_1 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN1
40
+ {PA_4 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN4
41
+ {PB_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN8
42
+ {PC_1 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN11
43
+ {PC_0 , ADC_1 , STM_PIN_DATA (GPIO_Mode_AN , GPIO_OType_PP , GPIO_PuPd_NOPULL , 0xFF )}, // ADC_IN10
44
44
{NC , NC , 0 }
45
45
};
46
46
@@ -72,26 +72,14 @@ void analogin_init(analogin_t *obj, PinName pin) {
72
72
adc = (ADC_TypeDef * )(obj -> adc );
73
73
74
74
// Enable ADC clock
75
- RCC_ADCCLKConfig (RCC_PCLK2_Div4 );
76
75
RCC_APB2PeriphClockCmd (RCC_APB2Periph_ADC1 , ENABLE );
77
76
78
77
// Configure ADC
79
- ADC_InitStructure .ADC_Mode = ADC_Mode_Independent ;
80
- ADC_InitStructure .ADC_ScanConvMode = DISABLE ;
81
- ADC_InitStructure .ADC_ContinuousConvMode = DISABLE ;
82
- ADC_InitStructure .ADC_ExternalTrigConv = ADC_ExternalTrigConv_None ;
83
- ADC_InitStructure .ADC_DataAlign = ADC_DataAlign_Right ;
84
- ADC_InitStructure .ADC_NbrOfChannel = 1 ;
78
+ ADC_StructInit (& ADC_InitStructure );
85
79
ADC_Init (adc , & ADC_InitStructure );
86
80
87
81
// Enable ADC
88
82
ADC_Cmd (adc , ENABLE );
89
-
90
- // Calibrate ADC
91
- ADC_ResetCalibration (adc );
92
- while (ADC_GetResetCalibrationStatus (adc ));
93
- ADC_StartCalibration (adc );
94
- while (ADC_GetCalibrationStatus (adc ));
95
83
}
96
84
}
97
85
@@ -102,28 +90,28 @@ static inline uint16_t adc_read(analogin_t *obj) {
102
90
// Configure ADC channel
103
91
switch (obj -> pin ) {
104
92
case PA_0 :
105
- ADC_RegularChannelConfig (adc , ADC_Channel_0 , 1 , ADC_SampleTime_7Cycles5 );
93
+ ADC_RegularChannelConfig (adc , ADC_Channel_0 , 1 , ADC_SampleTime_4Cycles );
106
94
break ;
107
95
case PA_1 :
108
- ADC_RegularChannelConfig (adc , ADC_Channel_1 , 1 , ADC_SampleTime_7Cycles5 );
96
+ ADC_RegularChannelConfig (adc , ADC_Channel_1 , 1 , ADC_SampleTime_4Cycles );
109
97
break ;
110
98
case PA_4 :
111
- ADC_RegularChannelConfig (adc , ADC_Channel_4 , 1 , ADC_SampleTime_7Cycles5 );
99
+ ADC_RegularChannelConfig (adc , ADC_Channel_4 , 1 , ADC_SampleTime_4Cycles );
112
100
break ;
113
101
case PB_0 :
114
- ADC_RegularChannelConfig (adc , ADC_Channel_8 , 1 , ADC_SampleTime_7Cycles5 );
102
+ ADC_RegularChannelConfig (adc , ADC_Channel_8 , 1 , ADC_SampleTime_4Cycles );
115
103
break ;
116
104
case PC_1 :
117
- ADC_RegularChannelConfig (adc , ADC_Channel_11 , 1 , ADC_SampleTime_7Cycles5 );
105
+ ADC_RegularChannelConfig (adc , ADC_Channel_11 , 1 , ADC_SampleTime_4Cycles );
118
106
break ;
119
107
case PC_0 :
120
- ADC_RegularChannelConfig (adc , ADC_Channel_10 , 1 , ADC_SampleTime_7Cycles5 );
108
+ ADC_RegularChannelConfig (adc , ADC_Channel_10 , 1 , ADC_SampleTime_4Cycles );
121
109
break ;
122
110
default :
123
111
return 0 ;
124
112
}
125
113
126
- ADC_SoftwareStartConvCmd (adc , ENABLE ); // Start conversion
114
+ ADC_SoftwareStartConv (adc ); // Start conversion
127
115
128
116
while (ADC_GetFlagStatus (adc , ADC_FLAG_EOC ) == RESET ); // Wait end of conversion
129
117
0 commit comments