Skip to main content
Associate II
December 28, 2024
Question

How to use ADC on Nucleo-G491

  • December 28, 2024
  • 1 reply
  • 764 views

I am unable to obtain ADC values and would like some advice.

Here is the source code project.

https://github.com/katsumat/STM32CubeIDE/tree/main/workspace_1.16.1/ADCCalibration

 

PA0 is connected to GND, PA1 to Vdd, and PA3 to the output of a variable resistor.

The ends of the variable resistor are connected to Vdd and GND, ensuring an output range of 0 to 3.3V.

 

The input voltages for PA0, PA1, and PA3 are as follows:

KatsuMat_1-1735417352680.png

Here are the results after setting a breakpoint and checking:

KatsuMat_2-1735417413994.png

The variable did not hold any value.

KatsuMat_0-1735417870078.png

 

 

 

KatsuMat_0-1735417281046.png

 

1 reply

KnarfB
Super User
December 28, 2024

Look at the generated config code in your main.c lines 246 ff and copy that as closely as possible in your own configs. ADC_REGULAR_RANK_1 is not a 1, offset fields shall be initialized, etc.. 

hth

KnarfB

KatsuMatAuthor
Associate II
January 13, 2025
 

The value has been entered!

Thank you!!

KatsuMat_0-1736761169662.png

 

I have corrected the bolded part.

 

sConfig.Channel = ADC_CHANNEL_1;

sConfig.Rank = ADC_REGULAR_RANK_1;

sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;

sConfig.SingleDiff = ADC_SINGLE_ENDED;

sConfig.OffsetNumber = ADC_OFFSET_NONE;

sConfig.Offset = 0;

HAL_ADC_ConfigChannel(&hadc1, &sConfig);

HAL_ADC_Start(&hadc1);

HAL_ADC_PollForConversion(&hadc1, 1000);

OffsetAcc = HAL_ADC_GetValue(&hadc1);

HAL_ADC_Stop(&hadc1);

hadc1.Instance->SQR1 = 0;