Skip to main content
CBarb.1
Associate II
February 23, 2023
Question

NUCLEO-C031C6 upates adc value only once upon start up but does not update afterwards

  • February 23, 2023
  • 3 replies
  • 3734 views

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.

This topic has been closed for replies.

3 replies

S.Ma
Principal
February 24, 2023

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.

christop
ST Employee
February 24, 2023

You might want to refer to AN3116 which describes the possible modes using the ADC.

https://www.st.com/content/ccc/resource/technical/document/application_note/c4/63/a9/f4/ae/f2/48/5d/CD00258017.pdf/files/CD00258017.pdf/jcr:content/translations/en.CD00258017.pdf

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);

CBarb.1
CBarb.1Author
Associate II
February 24, 2023

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