AnsweredAssumed Answered

STM32L4 ADC partially working

Question asked by bonelli on Nov 27, 2015
Latest reply on Dec 2, 2015 by Amel N
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);


}

Outcomes