Skip to main content
tarzan2
Associate III
November 27, 2015
Question

STM32L4 ADC partially working

  • November 27, 2015
  • 3 replies
  • 801 views
Posted on November 27, 2015 at 17:10

Hello,

I'm using IAR & cubeMX, and the nucleo board

6 regular channels, no injection :

1/ internal TS

2/ A8 (connected to OPAMP 1) forced at 3.3V

3/ A9 forced at 3.3V

4/ A15 (connected to OPAMP 2) forced at 3.3/2 (voltage divider with 2R)

5/ internal vbat

6/ vref

I'm not concerned about speed. I performed a calibration with HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

Internal channels are working, but external channels are not. The ADC returns something between 400 and 700 (@12bits).

I can change the order of measurments, measure only output channel, measure multiple time the same input, in all case, all order, external channel returns floating values between 400 and 700.

I call the ADC conversion fuction every second with : HAL_ADC_Start_DMA(&hadc1, (uint32_t*)temp, 6);

@main() :

  MX_ADC1_Init();

  hadc1.Instance->CFGR = 0x80000000;

  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

@adc.c :

void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

    /**Common config 

    */

  hadc1.Instance = ADC1;

  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;

  hadc1.Init.Resolution = ADC_RESOLUTION_12B;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;

  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;

  hadc1.Init.LowPowerAutoWait = ENABLE;

  hadc1.Init.ContinuousConvMode = DISABLE;

  hadc1.Init.NbrOfConversion = 6;

  hadc1.Init.DiscontinuousConvMode = DISABLE;

  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc1.Init.DMAContinuousRequests = DISABLE;

  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;

  hadc1.Init.OversamplingMode = DISABLE;

  HAL_ADC_Init(&hadc1);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;

  sConfig.SingleDiff = ADC_SINGLE_ENDED;

  sConfig.OffsetNumber = ADC_OFFSET_NONE;

  sConfig.Offset = 0;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_8;

  sConfig.Rank = 2;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_9;

  sConfig.Rank = 3;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_15;

  sConfig.Rank = 4;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_VBAT;

  sConfig.Rank = 5;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure Regular Channel 

    */

  sConfig.Channel = ADC_CHANNEL_VREFINT;

  sConfig.Rank = 6;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

}
    This topic has been closed for replies.

    3 replies

    Chris1
    Associate II
    November 30, 2015
    Posted on November 30, 2015 at 16:03

    What does your GPIO configuration look like?

    The L4 devices require a specific mode setting (GPIO_MODE_ANALOG_ADC_CONTROL), e.g.,

        GPIO_InitStruct.Pin = GPIO_PIN_0;

        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;

        GPIO_InitStruct.Pull = GPIO_NOPULL;

        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    tarzan2
    tarzan2Author
    Associate III
    December 1, 2015
    Posted on December 01, 2015 at 17:35

    Chris T, thank you so much!

    - ADC.IN9 was wrongly configured by the STM32L4 FW package v1.0.0. I updated it yesterday for other reasons, and now ADC.IN9 is working.

    - Reading your message, I immediately looked at the 2 other inputs. There are configured in opamp.c as GPIO_MODE_ANALOG instead of GPIO_MODE_ANALOG_ADC_CONTROL, even if the opamp output is routed to ADC in cubeMX.

    I hope ST will quickly solve this bug because it may be time-consuming :)

    With the correction, my ADC now work fine.

    Amel NASRI
    ST Technical Moderator
    December 2, 2015
    Posted on December 02, 2015 at 15:45

    Hi bonelli,

    The reported issue regarding the mode selected for ADC pins should be already fixed in CubeMX 4.11.

    Are you using an older version?

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.