cancel
Showing results for 
Search instead for 
Did you mean: 

ADC getvalue() not giving values

RWagh.2
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

5 REPLIES 5
AJOY.1
Associate

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
Associate II

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

ONadr.1
Senior III

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

TDK
Guru

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".
S.Ma
Principal

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.