File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
targets/TARGET_STM/TARGET_STM32F7 Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ uint16_t adc_read(analogin_t *obj)
107
107
108
108
// Configure ADC channel
109
109
sConfig .Rank = 1 ;
110
- sConfig .SamplingTime = ADC_SAMPLETIME_15CYCLES ;
110
+ sConfig .SamplingTime = ADC_SAMPLETIME_56CYCLES ;
111
111
sConfig .Offset = 0 ;
112
112
113
113
switch (obj -> channel ) {
@@ -161,17 +161,26 @@ uint16_t adc_read(analogin_t *obj)
161
161
break ;
162
162
case 16 :
163
163
sConfig .Channel = ADC_CHANNEL_TEMPSENSOR ;
164
+ sConfig .SamplingTime = ADC_SAMPLETIME_480CYCLES ;
164
165
break ;
165
166
case 17 :
166
167
sConfig .Channel = ADC_CHANNEL_VREFINT ;
168
+ sConfig .SamplingTime = ADC_SAMPLETIME_480CYCLES ;
167
169
break ;
168
170
case 18 :
169
171
sConfig .Channel = ADC_CHANNEL_VBAT ;
172
+ sConfig .SamplingTime = ADC_SAMPLETIME_480CYCLES ;
170
173
break ;
171
174
default :
172
175
return 0 ;
173
176
}
174
177
178
+ // Measuring VBAT sets the ADC_CCR_VBATE bit in ADC->CCR, and there is not
179
+ // possibility with the ST HAL driver to clear it. If it isn't cleared,
180
+ // VBAT remains connected to the ADC channel in preference to temperature,
181
+ // so VBAT readings are returned in place of temperature.
182
+ ADC -> CCR &= ~(ADC_CCR_VBATE | ADC_CCR_TSVREFE );
183
+
175
184
HAL_ADC_ConfigChannel (& obj -> handle , & sConfig );
176
185
177
186
HAL_ADC_Start (& obj -> handle ); // Start conversion
Original file line number Diff line number Diff line change 44
44
/* Includes ------------------------------------------------------------------*/
45
45
#include "stm32f7xx_hal_def.h"
46
46
47
+ /* Include low level driver */
48
+ #include "stm32f7xx_ll_adc.h"
49
+
47
50
/** @addtogroup STM32F7xx_HAL_Driver
48
51
* @{
49
52
*/
You can’t perform that action at this time.
0 commit comments