Skip to content

Commit 06bca28

Browse files
committed
STM32F7 ADC internal channels update
1 parent e438bd6 commit 06bca28

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

targets/TARGET_STM/TARGET_STM32F7/analogin_device.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ uint16_t adc_read(analogin_t *obj)
107107

108108
// Configure ADC channel
109109
sConfig.Rank = 1;
110-
sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
110+
sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
111111
sConfig.Offset = 0;
112112

113113
switch (obj->channel) {
@@ -161,17 +161,26 @@ uint16_t adc_read(analogin_t *obj)
161161
break;
162162
case 16:
163163
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
164+
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
164165
break;
165166
case 17:
166167
sConfig.Channel = ADC_CHANNEL_VREFINT;
168+
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
167169
break;
168170
case 18:
169171
sConfig.Channel = ADC_CHANNEL_VBAT;
172+
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
170173
break;
171174
default:
172175
return 0;
173176
}
174177

178+
// Measuring VBAT sets the ADC_CCR_VBATE bit in ADC->CCR, and there is not
179+
// possibility with the ST HAL driver to clear it. If it isn't cleared,
180+
// VBAT remains connected to the ADC channel in preference to temperature,
181+
// so VBAT readings are returned in place of temperature.
182+
ADC->CCR &= ~(ADC_CCR_VBATE | ADC_CCR_TSVREFE);
183+
175184
HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
176185

177186
HAL_ADC_Start(&obj->handle); // Start conversion

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_adc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32f7xx_hal_def.h"
4646

47+
/* Include low level driver */
48+
#include "stm32f7xx_ll_adc.h"
49+
4750
/** @addtogroup STM32F7xx_HAL_Driver
4851
* @{
4952
*/

0 commit comments

Comments
 (0)