AnsweredAssumed Answered

ADC with HAL, EOC flag never set

Question asked by Paulstrom.Bjorn on Oct 11, 2016
Latest reply on Oct 11, 2016 by FTITI.Walid
Hello I am trying to use the ADC like this:

ADC_ChannelConfTypeDef sConfig;

       adc.Instance = ADC1;
       adc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
       adc.Init.Resolution = ADC_RESOLUTION_12B;
       adc.Init.ScanConvMode = DISABLE;
       adc.Init.ContinuousConvMode = DISABLE;
       adc.Init.DiscontinuousConvMode = DISABLE;
       adc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
       adc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
       adc.Init.NbrOfConversion = 1;
       adc.Init.DMAContinuousRequests = DISABLE;
       adc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
       if (HAL_ADC_Init(&adc) != HAL_OK)
       {
         //Error_Handler();
       }


       sConfig.Channel = ADC_CHANNEL_0;
       sConfig.Rank = 1;
       sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
       if (HAL_ADC_ConfigChannel(&adc, &sConfig) != HAL_OK)
       {
         //Error_Handler();
       }

GPIO_InitTypeDef GPIO_InitStruct;
       if(adcHandle->Instance==ADC1)
       {
         __HAL_RCC_ADC1_CLK_ENABLE();

         GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4;
         GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
         GPIO_InitStruct.Pull = GPIO_NOPULL;
         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

         HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
       }


HAL_ADC_Start(&g_AdcHandle);
    for (;;)
    {
        if (HAL_ADC_PollForConversion(&g_AdcHandle, 1000000) == HAL_OK)
        {
            g_ADCValue = HAL_ADC_GetValue(&g_AdcHandle);
            g_MeasurementNumber++;
        }
    }


 But it gets stuck in this code, looking for EOC flag:

while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC)))
  {
    /* Check if timeout is disabled (set to infinite wait) */
    if(Timeout != HAL_MAX_DELAY)
    {
      if((Timeout == 0U) || ((HAL_GetTick() - tickstart ) > Timeout))
      {
        /* Update ADC state machine to timeout */
        SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
        
        /* Process unlocked */
        __HAL_UNLOCK(hadc);
        
        return HAL_TIMEOUT;
      }
    }
  }

Any ideas why this happens?

Outcomes