File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
targets/TARGET_STM/TARGET_STM32F4 Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -183,13 +183,19 @@ static inline uint16_t adc_read(analogin_t *obj)
183
183
return 0 ;
184
184
}
185
185
186
+ // Measuring VBAT sets the ADC_CCR_VBATE bit in ADC->CCR, and there is not
187
+ // possibility with the ST HAL driver to clear it. If it isn't cleared,
188
+ // VBAT remains connected to the ADC channel in preference to temperature,
189
+ // so VBAT readings are returned in place of temperature.
190
+ ADC -> CCR &= ~(ADC_CCR_VBATE | ADC_CCR_TSVREFE );
191
+
186
192
HAL_ADC_ConfigChannel (& AdcHandle , & sConfig );
187
193
188
194
HAL_ADC_Start (& AdcHandle ); // Start conversion
189
195
190
196
// Wait end of conversion and get value
191
197
if (HAL_ADC_PollForConversion (& AdcHandle , 10 ) == HAL_OK ) {
192
- return (HAL_ADC_GetValue (& AdcHandle ) );
198
+ return (uint16_t ) HAL_ADC_GetValue (& AdcHandle );
193
199
} else {
194
200
return 0 ;
195
201
}
You can’t perform that action at this time.
0 commit comments