mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: targets/TARGET_STM/TARGET_STM32L0/analogin_device.c
- Revision:
- 186:707f6e361f3e
- Parent:
- 180:96ed750bd169
- Child:
- 188:bcfe06ba3d64
--- a/targets/TARGET_STM/TARGET_STM32L0/analogin_device.c Thu Apr 19 17:12:19 2018 +0100 +++ b/targets/TARGET_STM/TARGET_STM32L0/analogin_device.c Fri Jun 22 16:45:37 2018 +0100 @@ -35,11 +35,9 @@ #include "pinmap.h" #include "mbed_error.h" #include "PeripheralPins.h" -#include <stdbool.h> void analogin_init(analogin_t *obj, PinName pin) { - static bool adc_calibrated = false; uint32_t function = (uint32_t)NC; // ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...) @@ -72,7 +70,7 @@ obj->handle.Init.OversamplingMode = DISABLE; obj->handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1; obj->handle.Init.Resolution = ADC_RESOLUTION_12B; - obj->handle.Init.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; + obj->handle.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; obj->handle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; obj->handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; obj->handle.Init.ContinuousConvMode = DISABLE; @@ -92,9 +90,7 @@ error("Cannot initialize ADC"); } - // ADC calibration is done only once - if (!adc_calibrated) { - adc_calibrated = true; + if (!HAL_ADCEx_Calibration_GetValue(&obj->handle, ADC_SINGLE_ENDED)) { HAL_ADCEx_Calibration_Start(&obj->handle, ADC_SINGLE_ENDED); } @@ -171,7 +167,9 @@ return 0; } - ADC1->CHSELR = 0; // [TODO] Workaround. To be removed after Cube driver is corrected. + /* Reset ADC channel selection register */ + ADC1->CHSELR = 0; + HAL_ADC_ConfigChannel(&obj->handle, &sConfig); HAL_ADC_Start(&obj->handle); // Start conversion