STM32F0 ADC internal channels update

pull/7228/head
jeromecoutant 2018-03-22 11:15:44 +01:00 committed by adbridge
parent c4698a5bde
commit 08d8df33c6
2 changed files with 8 additions and 10 deletions

View File

@ -35,11 +35,9 @@
#include "pinmap.h" #include "pinmap.h"
#include "mbed_error.h" #include "mbed_error.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
#include <stdbool.h>
void analogin_init(analogin_t *obj, PinName pin) void analogin_init(analogin_t *obj, PinName pin)
{ {
static bool adc_calibrated = false;
uint32_t function = (uint32_t)NC; uint32_t function = (uint32_t)NC;
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...) // ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
@ -89,9 +87,7 @@ void analogin_init(analogin_t *obj, PinName pin)
error("Cannot initialize ADC"); error("Cannot initialize ADC");
} }
// ADC calibration is done only once if (!LL_ADC_REG_ReadConversionData6(obj->handle.Instance)) {
if (!adc_calibrated) {
adc_calibrated = true;
HAL_ADCEx_Calibration_Start(&obj->handle); HAL_ADCEx_Calibration_Start(&obj->handle);
} }
} }
@ -102,11 +98,7 @@ uint16_t adc_read(analogin_t *obj)
// Configure ADC channel // Configure ADC channel
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
#if defined (TARGET_STM32F091RC) sConfig.SamplingTime = ADC_SAMPLETIME_41CYCLES_5;
sConfig.SamplingTime = ADC_SAMPLETIME_13CYCLES_5;
#else
sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
#endif
switch (obj->channel) { switch (obj->channel) {
case 0: case 0:
@ -159,13 +151,16 @@ uint16_t adc_read(analogin_t *obj)
break; break;
case 16: case 16:
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
break; break;
case 17: case 17:
sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
break; break;
#ifdef ADC_CHANNEL_VBAT #ifdef ADC_CHANNEL_VBAT
case 18: case 18:
sConfig.Channel = ADC_CHANNEL_VBAT; sConfig.Channel = ADC_CHANNEL_VBAT;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
break; break;
#endif #endif
default: default:

View File

@ -44,6 +44,9 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_hal_def.h" #include "stm32f0xx_hal_def.h"
/* Include low level driver */
#include "stm32f0xx_ll_adc.h"
/** @addtogroup STM32F0xx_HAL_Driver /** @addtogroup STM32F0xx_HAL_Driver
* @{ * @{
*/ */