HAL_ADC_PollForConversion gets stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-28 6:14 PM
I'm writing software that involves reading a single ADC value from my STM32H7R3V8H6, however it is getting stuck in HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);.
If i switch the delay to a smaller value it runs through but it still returns a timeout.
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 100);
adc1Data = HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
//readT(&engine, 0);
//readP(&engine, 0);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
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.SamplingMode = ADC_SAMPLING_MODE_NORMAL;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
sConfig.OffsetSign = ADC_OFFSET_SIGN_NEGATIVE;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
- Labels:
-
ADC
-
STM32H7 series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 2:16 PM
I misspoke, it doesn't return a timeout, it simply stays there forever. I looked into the code and it gets stuck in the loop that I put previously. That loop looks like it will return HAL_ERROR after some time, but its a very large amount of time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 2:18 PM
The ADC clock is enable from calling MX_ADC1_Init>HAL_ADC_Init>HAL_ADC_MspInit
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 2:26 PM
Looks like the H7 is a bit different as far as the ADC Clock, it's set in RCC domain 3 kernel clock configuration register (RCC_D3CCIPR):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 4:01 PM
@dfshea wrote:I misspoke, it doesn't return a timeout, it simply stays there forever. I looked into the code and it gets stuck in the loop that I put previously. That loop looks like it will return HAL_ERROR after some time, but its a very large amount of time.
Did you use 100ms for the timeout?
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 6:42 PM
For the ADC calibration I didn't see any option for a timeout, just inputting the ADC handle and ADC_SINGLE_ENDED.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 11:19 PM
Hello @dfshea
Could you please share your project so that we can assist you more effectively?
Saket_Om
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 11:36 PM
@dfshea wrote:For the ADC calibration I didn't see any option for a timeout, just inputting the ADC handle and ADC_SINGLE_ENDED.
No, i'm at talking about when you call HAL_ADC_PollForConversion
If you pass 100ms and it doesn't timeout, then you have two issues.
1. the ADC_FLAG_EOC flag isn't being set so you're stuck in the while loop.
2. HAL Tick isn't incrementing so it doesn't timeout.
Sounds like maybe something wasn't set up correctly or modified from default. Upload your IOC file
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-05 4:33 AM

- « Previous
-
- 1
- 2
- Next »