cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071 reading multiple ADC channels

LPetr.1
Senior

Hello. We chose STM32L071 CPU without realising that it does not have Scan conversion mode for multiple ADC channels.

Can someone confirm if it is possible to read multiple ADC channels using this CPU?

Please suggest what is the most convenient way to do this.

13 REPLIES 13
MM..1
Chief II

I dont test but try

 for(int i = 0; i< Max_Channels; i++) select_adc_channel(i);
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
HAL_ADC_Start(&hadc);
 
      for(int i = 0; i< Max_Channels; i++)
      {
          HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
          adcValue[i] = HAL_ADC_GetValue(&hadc);
          printf("adc value[%i]=%u \n",i,adcValue[i]);
 
      }
      printf("\n");
      HAL_Delay(1000);
  }

if continuos enabled then too start adc move before while ...

LPetr.1
Senior

Thanks for the response. I dont understand the code. Why would you want to call select_adc_channel(i); outside a for loop where the adc conversion happens? If I understand it correctly, before you step into while loop, you will simply call select_adc_channel multiple times and do nothing else. Shouldnt it be:

  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
HAL_ADC_Start(&hadc);
 
      for(int i = 0; i< Max_Channels; i++)
      {
          select_adc_channel(i);
          HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
          adcValue[i] = HAL_ADC_GetValue(&hadc);
          printf("adc value[%i]=%u \n",i,adcValue[i]);
 
      }
      printf("\n");
      HAL_Delay(1000);
  }

Ahhh I explain, you ask scan mode. This works mark all channels to scan group, normaly generated code do this, but you write own func,
then I show you how use this func. For() before while mark required channels...once
After this in while do job.
Selecting channels after start ADC is error... Check HAL returned values!

Thanks