AnsweredAssumed Answered

STM32F303 ADC Issue.

Question asked by bell.mark on Sep 19, 2016
Latest reply on Sep 20, 2016 by bell.mark

I’m having difficulty getting the ADC to work on the F303 board in the the value returned is always 0.    The input line is PA0,  ADC1,  Chanel 1.

The STM32cubeMX generated initialization code is as follows:


  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  HAL_ADC_Init(&hadc1);
  This function returns HAL_OK

  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = 1;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
  This function returns HAL_OK


The following code is in HAL_ADC_MspInit() in stm32f3xx_hal_msp.c:

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  if(hadc->Instance==ADC1)
  {
  /* USER CODE BEGIN ADC1_MspInit 0 */

  /* USER CODE END ADC1_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_ADC12_CLK_ENABLE();
 
    /**ADC1 GPIO Configuration    
    PA0     ------> ADC1_IN1
    */
    GPIO_InitStruct.Pin = DEFROSTER_SENSE_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(DEFROSTER_SENSE_GPIO_Port, &GPIO_InitStruct);

  /* USER CODE BEGIN ADC1_MspInit 1 */

  /* USER CODE END ADC1_MspInit 1 */
  }

}


My normal (periodic) processing:
 
  HAL_ADC_Start(&hadc1);
  This function returns HAL_OK

   HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
   This function returns HAL_OK

    nADCValue = HAL_ADC_GetValue(&hadc1);  
    This function always returns 0.

Help appreciated.

Outcomes