Skip to content

Commit f510eff

Browse files
committed
DISCO_L496AG : enable ADC
See User Manual, VREF+ is not connected by default NB: Use 2.5V as reference (instead of 3.3V) for internal channels calculation
1 parent 3da606e commit f510eff

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

targets/TARGET_STM/TARGET_STM32L4/analogin_device.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,23 @@ void analogin_init(analogin_t *obj, PinName pin)
8383
obj->handle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; // DR register is overwritten with the last conversion result in case of overrun
8484
obj->handle.Init.OversamplingMode = DISABLE; // No oversampling
8585

86+
#if defined(TARGET_DISCO_L496AG)
87+
/* VREF+ is not connected to VDDA by default */
88+
/* Use 2.5V as reference (instead of 3.3V) for internal channels calculation */
89+
__HAL_RCC_SYSCFG_CLK_ENABLE();
90+
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1); /* VREF_OUT2 = 2.5 V */
91+
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
92+
if (HAL_SYSCFG_EnableVREFBUF() != HAL_OK) {
93+
error("HAL_SYSCFG_EnableVREFBUF issue\n");
94+
}
95+
#endif /* TARGET_DISCO_L496AG */
96+
8697
// Enable ADC clock
8798
__HAL_RCC_ADC_CLK_ENABLE();
8899
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
89100

90101
if (HAL_ADC_Init(&obj->handle) != HAL_OK) {
91-
error("Cannot initialize ADC");
102+
error("Cannot initialize ADC\n");
92103
}
93104

94105
// ADC calibration is done only once

0 commit comments

Comments
 (0)