it is L476RG, I read the reference manual, I tried to read a 3.2v dc signal, I use HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED); int vdda=HAL_ADCEx_Calibration_GetValue(&hadc1,ADC_SINGLE_ENDED); HAL_ADC_Start(&hadc1); HAL_ADC_PollForConversion(&hadc1, 100); int digital_result = HAL_ADC_GetValue(&hadc1); HAL_ADC_Stop(&hadc1);

the vdda = 69 from the HAL_ADCEx_Calibration_GetValue function, digital_result=948; then I use formula float real_volt=vdda/4095.0*digital_result; I got a 15.9v result, where am I wrong? it is 12 bit ADC and single-ended.

Another interesting thing is, this is 12 bit ADC, but HAL_ADC_GetValue return a uint32_t, so sometimes this return value is very large, such as 65505 for a 2.4v input, there is no offset so the data should be no-sign, shall I directly extract the 12 bits on the right (right-aligned)?

enter image description here enter image description here

  • 1
    \$\begingroup\$ Have you read the Reference Manual It tells you how to set the ADC reference voltage, and how to adjust the resolution (trading off conversion time). \$\endgroup\$ – The Photon Nov 5 '19 at 4:28
  • \$\begingroup\$ To be fair, that's the most complicated ADC I've seen on a $6 microcontroller. \$\endgroup\$ – The Photon Nov 5 '19 at 4:32
  • \$\begingroup\$ thanks for your reply, I did not find this manual before, I am reading it, suppose I could set the reference voltage to 3.3v, then how to convert the digital values? \$\endgroup\$ – adam Nov 5 '19 at 4:46
  • 1
    \$\begingroup\$ It depends how you set the resolution and over-sampling. Whether you choose left or right justification, etc. \$\endgroup\$ – The Photon Nov 5 '19 at 4:48
  • \$\begingroup\$ Without the ADC settings this question is not answerable - we use the L451 which has the same ADC implementation (in my understanding) and the results are perfectly fine. \$\endgroup\$ – Arsenal Nov 5 '19 at 7:38


  1. There is a stupid bug mess up the channel configuration. When I switch the channel, I use ADC_ChannelConfTypeDef sConfig and did not initialize all parameters of sConfig except for the channel number.

  2. We found we have to use 3.3v (by guess) as the ref volt, v=digital_result/4096*3.3v

  3. Also, for the calibration we need to enable Verfint Channel in MX

    HAL_ADC_PollForConversion(&hadc1, 100); 
    int digital_result = HAL_ADC_GetValue(&hadc1); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.