2022-11-22 04:45 AM
I am using the ADC on an STM32 microcontroller.
The ADC is operated in ContinuousConvMode.
Can I start it with HAL_ADC_Start and query it at any time with HAL_ADC_GetValue?
Or may HAL_ADC_GetValue only be used if it is ensured that the ADC is not currently performing a measurement?
So start ADC and as soon as the measurement is finished read out using HAL_ADC_GetValue and start with HAL_ADC_Start.
My concern is that I want to make sure that there is no problem if HAL_ADC_GetValue is called, but the ad converter is currently storing its measured value.
2022-11-22 07:25 AM
Hello mfrank9 (Community Member)
Before calling HAL_ADC_GetValue() you must check for ADC conversion completion with HAL_PollForConversion() either in discontinuous or continuous conversion mode.
This API wait for EOC or EOS flags.
/*##- Start the conversion process ##*/
if (HAL_ADC_Start(&AdcHandle) != HAL_OK)
{
/* Start Conversation Error */
Error_Handler();
}
while (1)
{
/*## Wait for the end of conversion ##*/
/* For simplicity reasons, this example is just waiting till the end of the
conversion, but application may perform other tasks while conversion
operation is ongoing. */
if (HAL_ADC_PollForConversion(&AdcHandle, 10) != HAL_OK)
{
/* End Of Conversion flag not set on time */
Error_Handler();
}
else
{
/* ADC conversion completed */
/*## Get the converted value of regular channel ##*/
uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
}
}
In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'
BR
romain
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-11-22 07:16 PM
If the adc has both normal and injected (high prio) channels, better use dma in cyclic modd over multiple channels and filling the adc sample ram array. Then you can read even in debug mode these values at anytime.
There maybe some adc refman style examples on the corresponding Nucleo to try to start from.