2023-02-23 02:30 PM
I am working with a NUCLEO-C031C6 board using STM32Cube ide V1.11.0 and I am noticing something weird with my ADC readings, I am using PA0 and PA1 for AIN0 and AIN1 when I launch the application I get the correct value if I have a signal input on AIN0 from the ADC but if I change the signal input to another value during runtime I notice that the new value is not read or updated it continues to show the previous value until I do a reset or re-start of the MCU. I tried looking at all my ADC settings but I don't see anything that looks incorrect. Any help or suggestions as usual will be greatly appreciated. I have attached my zipped project file.
2023-02-23 08:15 PM
Well, you can try to run this Brisk demo onto the nucleo instead of the STM32C0316-DK and check on the ADC values (code in Analog.c source file, reads PA4 and PA5 and Vref and VTemp manually in one shot mode repetitively). Maybe this will help.
2023-02-23 09:03 PM
You might want to refer to AN3116 which describes the possible modes using the ADC.
In your code you configure the ADC with:
hadc1.Init.ContinuousConvMode = DISABLE;
and you start the ADC conversion only once calling HAL_ADC_Start(&hadc1) in Init().
So the ADC will perform the conversion of the channel only once in your application.
If you want the ADC to do successive conversions on the channel, you need to either enable the Continuous Conversion mode:
hadc1.Init.ContinuousConvMode = ENABLE;
or restart new conversions calling HAL_ADC_Start() each time you need a new conversion to be performed. For example, you could use a timer and every time the tier expires you call HAL_ADC_Start(), or in the while(1) loop in main(), you could do:
HAL_ADC_Start(&hadc1);
AdcValue = HAL_ADC_GetValue(&hadc1);
2023-02-24 05:22 AM
Once again, Thank you all.
I inserted the HAL_ADC_Start(&hadc1); which starts the conversion and then I used the
AdcValue = HAL_ADC_GetValue(&hadc1); as you suggested and it works as it should. I should have done more research and read the app note AN3116