Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32F4 AnalogIn - Clear VBATE and TSVREFE bits before configuring ADC channels #3302

Merged
merged 2 commits into from
Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion targets/TARGET_STM/TARGET_STM32F4/analogin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,19 @@ static inline uint16_t adc_read(analogin_t *obj)
return 0;
}

// Measuring VBAT sets the ADC_CCR_VBATE bit in ADC->CCR, and there is not
// possibility with the ST HAL driver to clear it. If it isn't cleared,
// VBAT remains connected to the ADC channel in preference to temperature,
// so VBAT readings are returned in place of temperature.
ADC->CCR &= ~(ADC_CCR_VBATE | ADC_CCR_TSVREFE);

HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);

HAL_ADC_Start(&AdcHandle); // Start conversion

// Wait end of conversion and get value
if (HAL_ADC_PollForConversion(&AdcHandle, 10) == HAL_OK) {
return (HAL_ADC_GetValue(&AdcHandle));
return (uint16_t)HAL_ADC_GetValue(&AdcHandle);
} else {
return 0;
}
Expand Down