AnsweredAssumed Answered

STM32, ADC and continuous conversion mode

Question asked by Denis Gottardello on Jan 19, 2018
Latest reply on Jan 21, 2018 by baird.hal.001

Hi. I need to have the value of 2 channels and the internal temperature.
My adc is setup as this:

 

  hadc.Instance = ADC1;

  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  hadc.Init.ContinuousConvMode = DISABLE;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 

and this is my callback:

 

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) {
    if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC)) {
        ADCValues[ADCIndex]= HAL_ADC_GetValue(hadc);
        ADCIndex++;
    }
    if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS)) {
        ADCIndex= 0;
        Vdd= 3300 * (*VREFINT_CAL_ADDR) / ADCValues[3];
        Temperature= (((int32_t)ADCValues[2] * Vdd / 3300)- (int32_t)*TEMP30_CAL_ADDR);
        Temperature= Temperature * (int32_t)(110- 30);
        Temperature= Temperature / (int32_t)(*TEMP110_CAL_ADDR- *TEMP30_CAL_ADDR);
        Temperature= Temperature+ 30;
        Reader125_0= ADCValues[1];
        Reader125_1= ADCValues[0];
    }
}

 

everything is working perfectly but only with "hadc.Init.ContinuousConvMode = DISABLE;"

If I enable "hadc.Init.ContinuousConvMode" I have wrong values.

What can I do to resolve the problem?

Outcomes