AnsweredAssumed Answered

VDDA and PA2 ADC measurements

Question asked by Jérémy Da Silva on Aug 30, 2017
Latest reply on Sep 4, 2017 by Vangelis Fortounas

Hello,

 

I work on a STM32L151CCU6 and I need your help.

I try to measure VDDA voltage in order to calculate a voltage divider on PA2 (single mode). My two ADC configuration functions are :

 

void MX_ADC_Init(void)
{
  GPIO_InitTypeDef gpioInit1;
  GPIO_InitTypeDef gpioInit2;
   
    gpioInit1.Pin = PID_PIN; //PA2
    gpioInit1.Mode = GPIO_MODE_ANALOG;
    gpioInit1.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(PID_PORT, &gpioInit1); PA2
    
    gpioInit2.Pin = PID_POWER_SUPPLY_PIN; //PB2
    gpioInit2.Mode = GPIO_MODE_OUTPUT_PP;
    gpioInit2.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(PID_POWER_SUPPLY_PORT, &gpioInit2); //PB2
    
  __HAL_RCC_ADC1_CLK_ENABLE();
  ADC_ChannelConfTypeDef sConfig;

 

    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
    */
  adc_identification.Instance = ADC1;
  adc_identification.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
  adc_identification.Init.Resolution = ADC_RESOLUTION_12B;
  adc_identification.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  adc_identification.Init.ScanConvMode = ADC_SCAN_DISABLE;
  adc_identification.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  adc_identification.Init.LowPowerAutoWait = ADC_AUTOWAIT_DISABLE;
  adc_identification.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE;
  adc_identification.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
  adc_identification.Init.ContinuousConvMode = DISABLE;
  adc_identification.Init.NbrOfConversion = 1;
  adc_identification.Init.DiscontinuousConvMode = DISABLE;
  adc_identification.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  adc_identification.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  adc_identification.Init.DMAContinuousRequests = DISABLE;
  if (HAL_ADC_Init(&adc_identification) != HAL_OK)
  {
    while(1);
  }

 

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
    */
  sConfig.Channel = ADC_CHANNEL_2;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES;
  if (HAL_ADC_ConfigChannel(&adc_identification, &sConfig) != HAL_OK)
  {
    while(1);
  }
  ADC_Enable(&adc_identification);
}

 

and :

 

void MX_ADC_VDD_Init(void)
{
  ADC_ChannelConfTypeDef sConfig;
 
  /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)*/

 

  VDD_measurement.Instance = ADC1;
  VDD_measurement.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  VDD_measurement.Init.Resolution = ADC_RESOLUTION_12B;
  VDD_measurement.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  VDD_measurement.Init.ScanConvMode = ADC_SCAN_DISABLE;
  VDD_measurement.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  VDD_measurement.Init.LowPowerAutoWait = ADC_AUTOWAIT_DISABLE;
  VDD_measurement.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE;
  VDD_measurement.Init.ChannelsBank = ADC_CHANNELS_BANK_A;
  VDD_measurement.Init.ContinuousConvMode = DISABLE;
  VDD_measurement.Init.NbrOfConversion = 1;
  VDD_measurement.Init.DiscontinuousConvMode = DISABLE;
  VDD_measurement.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  VDD_measurement.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  VDD_measurement.Init.DMAContinuousRequests = DISABLE;
  if (HAL_ADC_Init(&VDD_measurement) != HAL_OK)
  {
    while(1);
  }

 

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
    */
  sConfig.Channel = ADC_CHANNEL_17;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_4CYCLES;
  if (HAL_ADC_ConfigChannel(&VDD_measurement, &sConfig) != HAL_OK)
  {
    while(1);
  }
  ADC_Enable(&VDD_measurement);
}

 

When I try to measure this two ADC channel, I find 0.

 

I use this function : HAL_ADC_GetValue(&VDD_measurement);

 

Does anyone know where is my problem?

 

Thanks,

Jérémy

Outcomes