2021-07-23 05:51 AM
I am trying to use the internal voltage reference on the STM32WL MCU. When I enable the VREBUFF, it always times out and the VREFBUF->VRR bit is not ready.
On other STM32 MCU family, I read that it is required to enable the clock for SYSCFG and VREFBUFF. But I cannot find the relevant clock for either SYSCFG or VREFBUFF in the STM32WL registers. APB1ENR and APB2ENR do not have a clock enable pin for neither.
Below is the ADC init function I am using.
On the hardware level, VREF+ is connected to VCC in my design. Would that cause a problem ? I read in the user manual section 18.2 that when VREFBUF is enabled, VREF+ pin is connected to VREFBUF. Since in my design VREF+ is connected to VCC, would that cause the problem ?
hadc.Instance = ADC;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.NbrOfConversion = 1;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_160CYCLES_5;
hadc.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_160CYCLES_5;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
while(1);
}
/* Start Calibration */
// if (HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK)
// {
// while(1);
// }
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
if (HAL_SYSCFG_EnableVREFBUF() != HAL_OK)
{
while(1);
}
Thanks
2021-07-23 07:23 AM
> Since in my design VREF+ is connected to VCC, would that cause the problem ?
Yes this is a problem. VREFBUF will be fighting against VCC for the pin voltage. Best case, VREFBUF doesn't work, worst case the chip is damaged.