cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 Cannot enable ADC (timeout on polling for ADC_ISR:ASRDY)

Steffen1
Associate II

I'm using CubeIDE 1.7.0 and a Nucleo board to initialize and start ADC1 (at default settings, more or less).

The issue is that HAL_ADC_Start() would return HAL_ERROR due to a timeout. This is probably Clock-related but I couldn't figure it out yet.

Here's some snippets (generated code, mostly) I thought might be relevant:

  HAL_StatusTypeDef ret = 0;
  uint32_t value = 0;
 
  while(1) {
	  ret = HAL_ADC_Start(&hadc4);
	  ret = HAL_ADC_PollForConversion(&hadc4, 1000);
	  value = HAL_ADC_GetValue(&hadc4);
	  HAL_ADC_Stop(&hadc4);
  }

static void MX_ADC1_Init(void)
 
{
 
 
 
 /* USER CODE BEGIN ADC1_Init 0 */
 
 
 
 /* USER CODE END ADC1_Init 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_14B;
 
 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.DMAContinuousRequests = DISABLE;
 
 hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
 
 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
 
 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
 
 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
 
 hadc1.Init.OversamplingMode = DISABLE;
 
 if (HAL_ADC_Init(&hadc1) != HAL_OK)
 
 {
 
  Error_Handler();
 
 }
 
 /* USER CODE BEGIN ADC1_Init 2 */
 
 
 
 /* USER CODE END ADC1_Init 2 */
 
 
 
}

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(hadc->Instance==ADC1)
  {
  /* USER CODE BEGIN ADC1_MspInit 0 */
 
  /* USER CODE END ADC1_MspInit 0 */
  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
    PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSI;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Peripheral clock enable */
    __HAL_RCC_ADC1_CLK_ENABLE();
 
    __HAL_RCC_GPIOC_CLK_ENABLE();
    /**ADC1 GPIO Configuration
    PC2     ------> ADC1_IN3
    */
    GPIO_InitStruct.Pin = VBUS_SENSE_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(VBUS_SENSE_GPIO_Port, &GPIO_InitStruct);
 
  /* USER CODE BEGIN ADC1_MspInit 1 */
 
  /* USER CODE END ADC1_MspInit 1 */
  }
void HAL_MspInit(void)
{
  /* USER CODE BEGIN MspInit 0 */
 
  /* USER CODE END MspInit 0 */
 
  __HAL_RCC_PWR_CLK_ENABLE();
 
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
 
  /* System interrupt init*/
 
  /* USER CODE BEGIN MspInit 1 */
 
  /* USER CODE END MspInit 1 */
}
10 REPLIES 10
Steffen1
Associate II

Hi Ramin,

that's great news! I'm glad you figured that out.

thanks,

Steffen