STM32F7 ADC internal channels update

pull/7109/head
jeromecoutant 2018-03-22 13:18:55 +01:00 committed by adbridge
parent 4a908e9694
commit 1163f2c7ab
2 changed files with 13 additions and 1 deletions

View File

@ -107,7 +107,7 @@ uint16_t adc_read(analogin_t *obj)
// Configure ADC channel // Configure ADC channel
sConfig.Rank = 1; sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
sConfig.Offset = 0; sConfig.Offset = 0;
switch (obj->channel) { switch (obj->channel) {
@ -161,17 +161,26 @@ 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_480CYCLES;
break; break;
case 17: case 17:
sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
break; break;
case 18: case 18:
sConfig.Channel = ADC_CHANNEL_VBAT; sConfig.Channel = ADC_CHANNEL_VBAT;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
break; break;
default: default:
return 0; 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(&obj->handle, &sConfig); HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
HAL_ADC_Start(&obj->handle); // Start conversion HAL_ADC_Start(&obj->handle); // Start conversion

View File

@ -44,6 +44,9 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal_def.h" #include "stm32f7xx_hal_def.h"
/* Include low level driver */
#include "stm32f7xx_ll_adc.h"
/** @addtogroup STM32F7xx_HAL_Driver /** @addtogroup STM32F7xx_HAL_Driver
* @{ * @{
*/ */