4545
Fork of mbed-dev by
Diff: targets/TARGET_STM/TARGET_STM32F4/analogin_api.c
- Revision:
- 153:fa9ff456f731
- Parent:
- 150:02e0a0aed4ec
- Child:
- 160:d5399cc887bb
--- a/targets/TARGET_STM/TARGET_STM32F4/analogin_api.c Thu Dec 15 11:48:27 2016 +0000 +++ b/targets/TARGET_STM/TARGET_STM32F4/analogin_api.c Tue Dec 20 17:27:56 2016 +0000 @@ -183,13 +183,19 @@ 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; }