Skip to main content
RWagh.2
Associate II
Dec 5, 2022 8:57 AM UTC
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
Dec 7, 2022 5:23 AM UTC

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
Dec 5, 2022 10:08 AM UTC

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
Dec 5, 2022 12:38 PM UTC

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

ONadr.1
Senior III
Dec 5, 2022 2:24 PM UTC

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

TDK
TDKBest answer
Dec 7, 2022 5:23 AM UTC
"If you feel a post has answered your question, please click ""Accept as Solution""."
S.Ma
Principal
Dec 7, 2022 6:27 AM UTC

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.