2024-09-08 04:35 PM
Hi everybody,
I'm learning to use the ADC in a STM32F411CEU in Continuous Mode and Single Conversion with Polling. When the code is downloaded to the MCU everything runs ok (I mean, when the MCU runs by itself without any ST-Link connected).
The problem appears when I try to execute the code in a debugging session. The first time the function HAL_ADC_PollForConversion() is called, the result is HAL_OK, but in the next iterations the functions doesn't return HAL_OK anymore.
I know, I know, with Continuous Mode I should be using DMA. But I'm trying to learn the different operation modes (single conversion, scan mode, polling, DMA, etc.)
One thing I've found is that if I set the ADC parameter
End Of Conversion Selection = EOC flag at the end of all conversions
instead of
End Of Conversion Selection = EOC flag at the end of single channel conversion
, then the function HAL_ADC_PollForConversion() works ok in all the iterations when debugging.
Can anybody explain me what am I doing wrong?
Thanks in advance.
This is the code:
do { status_adc = HAL_ADC_Start(&hadc1); } while (status_adc != HAL_OK);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while (HAL_ADC_PollForConversion(&hadc1, 10) != HAL_OK) {}
input = HAL_ADC_GetValue(&hadc1);