cancel
Showing results for 
Search instead for 
Did you mean: 

Enable and use VREFBUF for ADC measures

SCana.1
Associate

Hi,

I am following the instructions in STM32 reference manual to configure VREFBUF to use in my ADC measures. In chapter 17, it explains that it is needed to set ENVR to enable VREFBUF, then reset HIZ and set VRS (in my case for VREFBUF = 2.5V), then it is needed to wait until voltage reference output has reached its expected value. In my case, the code is stopped checking it, returning TIMEOUT_ERROR.

We tried to do it with ST functions and thru ST registers, both options failed in the same point:

Option 1:

VREFBUF->CSR |= VREFBUF_CSR_ENVR;

VREFBUF->CSR &= ~VREFBUF_CSR_HIZ;

VREFBUF->CSR |= VREFBUF_CSR_VRS;

while( !( VREFBUF->CSR & VREFBUF_CSR_VRR ) );

Option 2:

HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);

HAL_SYSCFG_EnableVREFBUF();

 HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);

In option 2, code is stopped inside HAL_SYSCFG_EnableVREFBUF() function, returning this TIMEOUT error:

 while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)

 {

  if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)

  {

   return HAL_TIMEOUT;

  }

 }

Please, could you help me to configure it and make it work for my ADC measures?

Is there aything else I am nor including?

Thanks in advance

4 REPLIES 4

Which STM32?

Read out and check/post VREFBUF registers content after you've set them.

JW

SCana.1
Associate

Hi JW,

Thanks for your reply.

I solved the problem 🙂

My question now is that I am measuring an input voltage of 6V, but ADC returned value is 0. I am measuring also other pins between 0 and 3.3V and work as expected.

I readed Reference Manual but don't know exactly how to enable inputs higher than 3.3V.

Should I modify any register or call any function to measure more than 3,3V?

I am using STM32WB55.

Thank you,

You cannot measure voltages above VREF+ (=VDDA), and voltages above VDD will damage the pin. See Absolute maximum values in datasheet.

JW

Hi @SCana.1 . Idk if you are still remembering but  can you explain how did you solve your problem? I am dealing with the same problem. I couldn't find any solution yet.