2024-08-11 06:46 PM - edited 2024-08-11 08:43 PM
Hi,
I am using an STM32L452 and am trying to set the ADC reference voltage programmatically back and forth between the internal VREF (set to 2.5V) and the external 3V3 power rail. This is specifically for ADC1 channels 1 and channel 7.
I tried a few different ways (both using HAL and also registers/bits) but does not seem to set the VREF as reference voltage to the DAC. The DAC output value still remains the same as if I use the external voltage as reference.
How do I do that? i.e switch the DAC reference voltage back and forth between internal 2.5V and external 3V3 (or internal 3V3 if it is available).
Attached here is the .ioc file and further below is the relevant code.
Also if I try to add the following:
// Enable the clock for the VREFBUF peripheral
__HAL_RCC_VREF_CLK_ENABLE();
like suggested in some examples, it does not recognize that function and there are no .h files already included or part of the HAL header files/library that contain it.
How do I check if VREF clock is enabled?
And if it not, how do I enable it?
// Configure the VREFBUF to 2.5V
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);
// Enable the Voltage Reference Buffer (VREFBUF)
HAL_SYSCFG_EnableVREFBUF();
HAL_Delay(100);
/*
* If I uncomment this remains in the while loop
*
// Wait until the Voltage Reference Buffer is ready
while ((VREFBUF->CSR & VREFBUF_CSR_VRR) == 0) {
// Wait until the VRR (Voltage Reference Ready) flag is set
}
*/
// If I uncomment the next line it does not compile
// MX_ADC1_Init();
Thank you as always :)
Solved! Go to Solution.
2024-08-12 05:49 AM
> The VREF+ pin is free to float (see schematic below)
As I've said above, this is the small package, where it's internally connected to VDDA. And you can't use analog functions like DAC without connecting external power source to VDDA.
Consequently, you cannot use the internal VREFBUF in this package.
JW
2024-08-12 12:14 AM
> am trying to set the ADC reference voltage programmatically back and forth between the internal VREF (set to 2.5V) and the external 3V3 power rail.
You can't change that *programmatically*.
ADC/DAC reference is *always* the physical VREF+ pin. (in smaller packages bonded internally to VDDA). What "using internal VREF" in Cube in fact does is, that it switches on the internal reference and connects it to this pin. If you want to actually switch between external and internal VREF, you need to remove the external voltage from VREF+ pin, and you have to have a prescribed capacitance connected to it.
Note, that in smaller packages, VREF+ is internally bonded to VDDA, so you cannot disconnect it thus you can't use the internal VREF in those packages.
JW
2024-08-12 05:27 AM
Thank you
The VREF+ pin is free to float (see schematic below), but the DAC reading voltage doesn't seem to change when I change the VREF from VDD to 2.5V as shown in the instructions above.
Are there other instructions and/or sequence to do that?
Thank you
2024-08-12 05:49 AM
> The VREF+ pin is free to float (see schematic below)
As I've said above, this is the small package, where it's internally connected to VDDA. And you can't use analog functions like DAC without connecting external power source to VDDA.
Consequently, you cannot use the internal VREFBUF in this package.
JW
2024-08-12 06:09 AM
Thank you @waclawek.jan