Skip to main content
RWagh.2
Associate II
December 5, 2022
Solved

ADC getvalue() not giving values

Hello,

I am using STM32L011G4U7 and wants to get the adc value where it showed once and not it is giving 0 for the adc raw values. Also please let me know that in order to read the vcc that is 3.3 volts do I need to select VREFINT channel as well along with ADC pin?

Here's my code:

 void ReadVCC(byte ATR[])

 {

 HAL_ADC_Start_IT(&hadc);

 HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);

 adcval = HAL_ADC_GetValue(&hadc);

 HAL_Delay(1);

 VDDA = VREF * (VREFINT_CAL / adcval);

 ATR[6] = (uint8_t) (VDDA>>8); // MSB

 ATR[7] = (uint8_t) (VDDA & 0x00FF); // LSB

  }

result: adcval 0

VDDA 1

This topic has been closed for replies.
TDK
TDKBest answer
December 7, 2022

Look at an example for the proper usage of HAL_ADC commands.

Here is one of many:

https://github.com/STMicroelectronics/STM32CubeL0/blob/a7b74aed35ecb7baeadeb16107aa8fddb6823589/Projects/STM32L073Z-EVAL/Examples/ADC/ADC_RegularConversion_Polling/Src/main.c

"If you feel a post has answered your question, please click ""Accept as Solution""."

5 replies

AJOY.1
Visitor II
December 5, 2022

For open adc channel, it will give garbage value between vcc and gnd.

Once the channel is connected with any voltage, it should give corresponding voltage value.

RWagh.2
RWagh.2Author
Associate II
December 5, 2022

My adc pin is connected to voltage divider and it is giving 1024 raw value

ONadr.1
Senior III
December 5, 2022

I cant see channel configuration in this code. (HAL_ADC_ConfigChannel(.....) )

TDK
TDKBest answer
December 7, 2022
"If you feel a post has answered your question, please click ""Accept as Solution""."
S.Ma
Principal
December 7, 2022

Vdda is usually vdd. Vref is a bandgap fixed voltage as internal channel. Reading it makes vdd deductable. When vdd is lowered, vref converted value goes up, and reversibly.