AnsweredAssumed Answered

Different results for ADC Bat. Measurement on STM32F105 and STM32F411

Question asked by Haithem sunny on Apr 11, 2018
Latest reply on Apr 12, 2018 by Haithem sunny

Hi everybody,

Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.
In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411.

Below our configuration for ADC "STM32F411":

void MX_ADC1_Init(void)
{
  ADC_ChannelConfTypeDef sConfig;
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.DiscontinuousConvMode = ENABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    /* ADC initialization error */
    dlog(DDEBUG, "Error on adc init\n");
    return;
  }
  sConfig.Channel = ADC_CHANNEL_14;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES/*ADC_SAMPLETIME_28CYCLES

  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    dlog(DDEBUG, "Error on adc channel config\n");
   }
  sConfig.Channel = ADC_CHANNEL_VREFINT;
  sConfig.Rank = 2;
  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    dlog(DDEBUG, "Error on adc channel config\n");
   }
  if (HAL_ADC_Start_DMA(&hadc1,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    dlog(DDEBUG, "Error on ADC DMA start\n");
  }
  MX_ADC1_GetValue();
 }

 

Results on the USART terminal:

[ADC] Before: 0, Converted 0: 0

[ADC] Before: 0, Converted 1: 0

[ADC] u32ConvertedVal: 0

Outcomes