cancel
Showing results for 
Search instead for 
Did you mean: 

How to change ADC channel with STM32L010

ledi001
Senior

Hello,

i am struggling with ADC conversion with STM32L010 because every new conversion overide the other channels. So i got on each channel the same result when i change the resistance on PA6. On PA4 and PA5 there is a 100k NTC connected.

I use PA4 (ADC_IN4), PA5 (ADC_IN5) and PA6 (ADC_IN6) for conversion.

For changing the channels i did this:

/* Temperature inside (PA4) */
sConfig.Channel = ADC_CHANNEL_4;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
ADC_Conversion();
...
...
...
/* Temperature outside (PA5) */
sConfig.Channel = ADC_CHANNEL_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
ADC_Conversion();
...
...
...

My initialization code with CubeMX is here:

static void MX_ADC_Init(void)
{
  ADC_ChannelConfTypeDef sConfig = {0};
 
  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
  */
  hadc.Instance = ADC1;
  hadc.Init.OversamplingMode = DISABLE;
  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.SamplingTime = ADC_SAMPLETIME_79CYCLES_5;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ContinuousConvMode = DISABLE;
  hadc.Init.DiscontinuousConvMode = ENABLE;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerFrequencyMode = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted. 
  */
  sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted. 
  */
  sConfig.Channel = ADC_CHANNEL_5;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted. 
  */
  sConfig.Channel = ADC_CHANNEL_6;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
}

Hope someone can help me...

1 REPLY 1

Surely the Rank should increase in your configuration? Otherwise you keep overwriting the same configuration slot.

The standard way STM32 parts do multiple channels, is the fill an array with DMA, and then you use the DMA completion as the equivalent to the ADC EOC for ALL channels.

Got no L010 hardware here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..