STM32G051x ADC strange referance voltage
Posted: Sat Mar 29, 2025 8:14 pm
Hello, I was able to successfully setup a project for my board with STM32G051F8P6 but was unable to configure ADC properly. My voltage source is 3.3V (from LDO) but I get strange readings when I read ADC1. I have a Voltage Divider connected to ADC1 channel 1 with resistor 1 15k to the ground and 68k to Vs
And here is my ADC config:
I start ADC and then start sampling by executing
But when I convert read value I have 2.96V instead of 3.8V. I know This MCU has an Internal Voltage reference buffer but enabling or disabling it does not affect anything
Do you have any idea what can be wrong here?
And here is my ADC config:
Code: Select all
/*
* ADC conversion group 2.
* Mode: Linear buffer, 1 channel, SW triggered.
* Channels: IN01.
*/
#define ADC_GRP2_NUM_CHANNELS 1
#define ADC_GRP2_BUF_DEPTH 1
adcsample_t samples2[ADC_GRP2_BUF_DEPTH * ADC_GRP2_NUM_CHANNELS];
const ADCConversionGroup adc_grp2_cfg = {
.circular = false,
.num_channels = ADC_GRP2_NUM_CHANNELS,
.end_cb = NULL,
.error_cb = adcerrorcallback,
.cfgr1 = ADC_CFGR1_CONT | ADC_CFGR1_RES_12BIT,
.tr1 = ADC_TR_DISABLED,
.tr2 = ADC_TR_DISABLED,
.tr3 = ADC_TR_DISABLED,
.awd2cr = 0U,
.awd3cr = 0U,
.smpr = ADC_SMPR_SMP_3P5,
.chselr = ADC_CHSELR_CHSEL1
};
I start ADC and then start sampling by executing
Code: Select all
/*
* Starting PORTAB_ADC1 driver and the temperature sensor.
*/
adcStart(&ADCD1, NULL);
adcConvert(&ADCD1, &adc_grp2_cfg, samples2, ADC_GRP2_BUF_DEPTH);
But when I convert read value
Code: Select all
float voltage = samples2 * 18.26f / 4095f; Code: Select all
VREFBUF->CSR = VREFBUF_CSR_ENVR | VREFBUF_CSR_VRS | VREFBUF_CSR_HIZ;Do you have any idea what can be wrong here?