AnsweredAssumed Answered

STM32F4 ADC Scan conversion is not working.

Question asked by Patrick Morwald on Mar 20, 2018
Latest reply on Mar 22, 2018 by Patrick Morwald

Hi,

 

i have an ADC where i want to read multiple channels sequentially and than use this data. I read them every second or so, so i want to start the reading manually each time. But when its started it should read all the assigned channels. 

 

Unfortunately, with the configuration below, it only seems to read the first channel and not going through the sequence of channels. This is my initialization code:

 

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.ScanConvMode = ENABLE;
hadc2.Init.ContinuousConvMode = DISABLE;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc2.Init.NbrOfConversion = 2;
hadc2.Init.DMAContinuousRequests = DISABLE;
hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_12;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_13;
sConfig.Rank = 2;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

 

And this is my loop where i call a reading and the callback function:

 

while (1)
{

HAL_ADC_Start_IT(&hadc2);
HAL_Delay(4000);

}

 

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc){

if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC))
{
// ADC_raw[0] = HAL_ADC_GetValue(hadc);
if (indexer < 2){
ADC_raw[indexer] = HAL_ADC_GetValue(hadc);
indexer++;
}
else {
vdd_a = ((float)ADC_raw[0] * 3.3) / 4095;
}
}

}

 

Please help.

Outcomes