2

I'm not able to understand the use of VREFINT in stm32f103 board. Can anyone explain me how to get adc value in stm32f103 using VREFINT?

  if(HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK)
  {
      adcVrefInt = HAL_ADC_GetValue(&hadc1);
      vdd = 4095.0 * 1.20 / (float)adcVrefInt;
      vdd += 0.61; // .61 is the difference i'm getting in VDD
      sprintf(buffer, "VREFINT: %ld\tVDD: %.2f\t", adcVrefInt, vdd);
      HAL_UART_Transmit(&huart1, (uint8_t *)buffer, strlen(buffer), 100);

      if(HAL_ADC_PollForConversion(&hadc2, 100) == HAL_OK)
      {
          adcValue = HAL_ADC_GetValue(&hadc2);
          adcVoltage = (vdd/4095.0) * adcValue;
          sprintf(buffer, "ADC_PA0: %ld\tVoltage-PA0: %.2f\n", adcValue, adcVoltage);
          HAL_UART_Transmit(&huart1, (uint8_t *)buffer, strlen(buffer), 100);
      }
  }
Satyam Miri
  • 33
  • 1
  • 6
  • Could you clarify what your problem is exactly? Can't get a reading? Don't know how to interpret the value? Something else? What have you tried so far? – followed Monica to Codidact Sep 02 '19 at 07:25
  • i want to measure the adc value from another channel let's say PA0. My stm32f103 bluepill is powered by a 3.7v li ion battery and for stm32f1 bluepill the vref pin is internally connected with vdd(supply voltage for stm32).i'm not getting correct adc value because time to time voltage of battery will be decrease. So to get the correct adc reading, i want to use vrefint which is available in stm32f1 but i dont have any idea how to use it – Satyam Miri Sep 02 '19 at 07:33
  • Essentially, you can use Vref to determine VDDA, since Vref is always 1.20V, but Vdda may change, i.e. be 2.8V, or 3.4V. That allows automatic configuration of **gain** and **bias** on system boot and significantly improve measurement conversion accuracy. – Nik Sep 18 '21 at 17:19

1 Answers1

2

You can read the VREFINT channel (17) much like any other channel on ADC1, after setting the TSVREFE bit in ADC1->CR2. It's an internal analog signal, there is no pin associated with it. VREFINT has a fixed voltage of 1.20 ± 0.04 V.

If an ADC input pin is connected to VDDA, you get a reading of 4095. If it's connected to VSSA, you get 0. If there is any other voltage V1 between these limits, you get 4095 * V1 / VDDA. This applies to the VREFINT channel as well.

When you measure VREFINT, ADC1->DR = 4095 * VREFINT / VDDA. Because you know that VREFINT = 1.20V, you can calculate VDDA=4095 * 1.20 / ADC1->DR Volts.