2024-12-28 12:30 PM - edited 2024-12-28 12:33 PM
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:
Here are the results after setting a breakpoint and checking:
The variable did not hold any value.
2024-12-28 12:55 PM - edited 2025-01-13 01:49 AM
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
2025-01-13 01:41 AM - edited 2025-01-13 01:42 AM
The value has been entered!
Thank you!!
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;