Skip to main content
ABN
Associate III
August 21, 2024
Question

ADC Polling HAL_ERROR

  • August 21, 2024
  • 2 replies
  • 1106 views

Hi community,

I have an application to sample the ADC and go to sleep(STOP2) mode. From the RM0434 got to know that cannot use the ADC/DMA interrupt as a wakeup source to get the ADC converted values

So I went with the Polling approach as shown in the snapshot. ADC_PollForConversion function is always giving HAL_Error. Can I get some help with this?

ABN_0-1724238853870.png

This code snippet is the ADC Init function. Also planning to use multiple channels going further

hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
 hadc1.Init.Resolution = ADC_RESOLUTION_12B;
 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 hadc1.Init.LowPowerAutoWait = DISABLE;
 hadc1.Init.ContinuousConvMode = DISABLE;
 hadc1.Init.NbrOfConversion = 1;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.DMAContinuousRequests = DISABLE;
 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
 hadc1.Init.OversamplingMode = ENABLE;
 hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_16;
 hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
 hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
 hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
 if (HAL_ADC_Init(&hadc1) != HAL_OK)
 {
 Error_Handler();
 }

 /** Configure Regular Channel
 */
 sConfig.Channel = ADC_CHANNEL_14;
 sConfig.Rank = ADC_REGULAR_RANK_1;
 sConfig.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;
 sConfig.SingleDiff = ADC_SINGLE_ENDED;
 sConfig.OffsetNumber = ADC_OFFSET_NONE;
 sConfig.Offset = 0;
 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
 {
 Error_Handler();
 }


 

2 replies

TDK
Super User
August 21, 2024

What does hadc->State indicate is the source of the error? Should also be able to step though HAL_ADC_PollForConversion to find this.

"If you feel a post has answered your question, please click ""Accept as Solution""."
ABN
ABNAuthor
Associate III
August 22, 2024

ABN_0-1724322902092.png

This is the place where HAL_Error is returned

TDK
Super User
August 22, 2024

Okay, so it sees that DMAEN is set, which it shouldn't be for polling mode. Find out where/why that's being set.

> hadc1.Init.DMAContinuousRequests = DISABLE;

This should make it disabled. Perhaps there is more relevant code that is not being shown?

"If you feel a post has answered your question, please click ""Accept as Solution""."