Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DISCO_L496AG : enable ADC #8168

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion targets/TARGET_STM/TARGET_STM32L4/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,23 @@ void analogin_init(analogin_t *obj, PinName pin)
obj->handle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; // DR register is overwritten with the last conversion result in case of overrun
obj->handle.Init.OversamplingMode = DISABLE; // No oversampling

#if defined(TARGET_DISCO_L496AG)
/* VREF+ is not connected to VDDA by default */
/* Use 2.5V as reference (instead of 3.3V) for internal channels calculation */
__HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1); /* VREF_OUT2 = 2.5 V */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
if (HAL_SYSCFG_EnableVREFBUF() != HAL_OK) {
error("HAL_SYSCFG_EnableVREFBUF issue\n");
}
#endif /* TARGET_DISCO_L496AG */

// Enable ADC clock
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);

if (HAL_ADC_Init(&obj->handle) != HAL_OK) {
error("Cannot initialize ADC");
error("Cannot initialize ADC\n");
}

// ADC calibration is done only once
Expand Down