Merge pull request #5210 from bcostm/L4_add_adc_calib

STM32: add ADC calibration for L4, F1, F3 devices
pull/5283/merge
Jimmy Brisson 2017-10-09 11:15:31 -05:00 committed by GitHub
commit 80ff7071b4
3 changed files with 14 additions and 1 deletions

View File

@ -33,6 +33,7 @@
#include "mbed_wait_api.h" #include "mbed_wait_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "mbed_error.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
int adc_inited = 0; int adc_inited = 0;
@ -93,7 +94,13 @@ void analogin_init(analogin_t *obj, PinName pin)
obj->handle.Init.DiscontinuousConvMode = DISABLE; obj->handle.Init.DiscontinuousConvMode = DISABLE;
obj->handle.Init.NbrOfDiscConversion = 0; obj->handle.Init.NbrOfDiscConversion = 0;
obj->handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; obj->handle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
HAL_ADC_Init(&obj->handle);
if (HAL_ADC_Init(&obj->handle) != HAL_OK) {
error("Cannot initialize ADC\n");
}
// Calibrate ADC
HAL_ADCEx_Calibration_Start(&obj->handle);
} }
} }

View File

@ -130,6 +130,9 @@ void analogin_init(analogin_t *obj, PinName pin)
if (HAL_ADC_Init(&obj->handle) != HAL_OK) { if (HAL_ADC_Init(&obj->handle) != HAL_OK) {
error("Cannot initialize ADC"); error("Cannot initialize ADC");
} }
// Calibrate ADC
HAL_ADCEx_Calibration_Start(&obj->handle, ADC_SINGLE_ENDED);
} }
static inline uint16_t adc_read(analogin_t *obj) static inline uint16_t adc_read(analogin_t *obj)

View File

@ -96,6 +96,9 @@ void analogin_init(analogin_t *obj, PinName pin)
if (HAL_ADC_Init(&obj->handle) != HAL_OK) { if (HAL_ADC_Init(&obj->handle) != HAL_OK) {
error("Cannot initialize ADC\n"); error("Cannot initialize ADC\n");
} }
// Calibrate ADC
HAL_ADCEx_Calibration_Start(&obj->handle, ADC_SINGLE_ENDED);
} }
} }