cancel
Showing results for 
Search instead for 
Did you mean: 

multiple channel adc reads the same value in all the channel in stm32

NJP.1
Associate III

HI all i have been working in stm32L072CBT6 controller i have the code to read the adc multiple channel and i can read the values for different channels individually by using separate code for each channel but if im reading all the four channels altogether the the value in one channel is reflecting in all the channels. And i have also checked whether the voltage in each channel is same and found that all the values are different though im getting the same values for example channel1 values reflecting in channel 0 any thought on this issue kindly share me. I have attached the code below.

static void MX_ADC1_Init(void)
{
 
	/* USER CODE BEGIN ADC1_Init 0 */
 
	  /* USER CODE END ADC1_Init 0 */
 
	  ADC_ChannelConfTypeDef sConfig = {0};
 
	  /* USER CODE BEGIN ADC1_Init 1 */
 
	  /* USER CODE END ADC1_Init 1 */
	  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
	  */
	  hadc1.Instance = ADC1;
	  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
	  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
	  hadc1.Init.ScanConvMode = ENABLE;
	  hadc1.Init.ContinuousConvMode = ENABLE;
	  hadc1.Init.DiscontinuousConvMode = DISABLE;
	  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
	  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
	  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
	  hadc1.Init.DMAContinuousRequests = DISABLE;
	  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;//ADC_EOC_SINGLE_CONV;
	  //naga
	  hadc.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5;
 
	  if (HAL_ADC_Init(&hadc1) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH0 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_0;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_160CYCLES_5;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH1 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_1;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
 
int main(void)
{
 
  HAL_Init();
  SystemClock_Config();
 
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_ADC1_Init();
 // MX_ADC_Init();
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  AD_RES0 = 0;
	  AD_RES1 = 0;
	 // HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
	 // HAL_GPIO_WritePin(BUZZER_GPIO_Port, BUZZER_Pin, GPIO_PIN_RESET);
 
		  ADC_Select_CH0();
 
		  HAL_ADC_Start(&hadc1);
 
		  HAL_ADC_PollForConversion(&hadc1, 1000);
 
		  AD_RES0 = HAL_ADC_GetValue(&hadc1);
 
		  HAL_ADC_Stop(&hadc1);
		  sprintf(Buf,"adc0 %u  \r\n", AD_RES0);
		  HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		 // ADC->CCR |= (1<<ADC->ADEN);
		  HAL_Delay(10);
 
 
 
 
			ADC_Select_CH1();
 
			HAL_ADC_Start(&hadc1);
 
			HAL_ADC_PollForConversion(&hadc1, 1000);
 
			AD_RES1 = HAL_ADC_GetValue(&hadc1);
 
			HAL_ADC_Stop(&hadc1);
 
			sprintf(Buf," adc1 %u \r\n", AD_RES1);
			HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
 
			HAL_Delay(10);
      }
}
 
 
 

1 ACCEPTED SOLUTION

Accepted Solutions
NJP.1
Associate III

The problem is with the channel select register the below code works fine in polling method itself.

void MX_ADC1_Init(void)
{
 
	/* USER CODE BEGIN ADC1_Init 0 */
 
	  /* USER CODE END ADC1_Init 0 */
 
	  ADC_ChannelConfTypeDef sConfig = {0};
 
	  /* USER CODE BEGIN ADC1_Init 1 */
 
	  /* USER CODE END ADC1_Init 1 */
	  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
	  */
	  hadc1.Instance = ADC1;
	  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
	  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
	  hadc1.Init.ScanConvMode = ENABLE;
	  hadc1.Init.ContinuousConvMode = ENABLE;
	  hadc1.Init.DiscontinuousConvMode = DISABLE;
	  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
	  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
	  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
	 // hadc1.Init.NbrOfConversion = 1;
	  hadc1.Init.DMAContinuousRequests = DISABLE;
	  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;//ADC_EOC_SINGLE_CONV;
	  //naga
	  hadc.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5;
 
	  if (HAL_ADC_Init(&hadc1) != HAL_OK)
	  {
	    Error_Handler();
	  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_0;
	//  sConfig.Rank = 1;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_1;
	//  sConfig.Rank = 2;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
	//  sConfig.Rank = 3;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_112CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	  /* USER CODE BEGIN ADC1_Init 2 */
 
	  /* USER CODE END ADC1_Init 2 */
}
 
 
void ADC_Select_CH0 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_0;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH1 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_1;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH5 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_5;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH6 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_6;
	  //
	  sConfig.Rank = 6;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void Adc_Read_Raw_Data(void)
{
	    ADC1->CHSELR  = 0x01;
		ADC_Select_CH0();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_0_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf,"adc0 %u  \r\n", Adc_0_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_0_Volt = ((float)Adc_0_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_0_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x02;
		ADC_Select_CH1();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_1_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc1 %u \r\n", Adc_1_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_1_Volt = ((float)Adc_1_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_1_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x20;
		ADC_Select_CH5();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_5_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc5 %u \r\n", Adc_5_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_5_Volt = ((float)Adc_5_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_5_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x40;
		ADC_Select_CH6();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_6_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc6 %u \r\n", Adc_6_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_6_Volt = ((float)Adc_6_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_6_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(100);
}

Thankyou all for the support.

View solution in original post

9 REPLIES 9
Muhammed Güler
Senior III

STM favors reading all channels at once instead of the adc reading method you are trying to use. Below is my multi-channel ADC application with STM32F0. I read 6 channels with a single line of code and use the value I need at that moment.0693W00000HohTYQAZ.png0693W00000HohTdQAJ.png 

uint32_t ADC_Reads[6];
// ADC Read Code 
HAL_ADC_Start_DMA(&hadc, ADC_Reads, 6);
//Instead of HAL_ADC_PollForConversion() I am using a variable whose value I change in the DMA transfer complete interrupt.

Thankyou for the reply , but in dma mode of conversion i heard that only the dma is executing all the time it seems not allowing our main function to perform that is the reasion i choose polling method and also my requirement is very less just to read a 4 adc channel and to process the things depending on the input values

No you can trigger a sequence of conversions that will stop until you retrigger it again. The example from Muhammad does exactly that.

You start the adc

you wait for conversion completed (see the comment on the fourth line above)

you read the value you want from ADC_Reads

And, what do you mean "I heard" ?

Anyway, DMA moves data without CPU involvement, so it shouldn't prevent your main function from running.

Again, try out Muhammad example, it's the best way.

NJP.1
Associate III

Thankyou mfran i will try that dma method of reading only and i will post the update in this forum

NJP.1
Associate III

The problem is with the channel select register the below code works fine in polling method itself.

void MX_ADC1_Init(void)
{
 
	/* USER CODE BEGIN ADC1_Init 0 */
 
	  /* USER CODE END ADC1_Init 0 */
 
	  ADC_ChannelConfTypeDef sConfig = {0};
 
	  /* USER CODE BEGIN ADC1_Init 1 */
 
	  /* USER CODE END ADC1_Init 1 */
	  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
	  */
	  hadc1.Instance = ADC1;
	  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
	  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
	  hadc1.Init.ScanConvMode = ENABLE;
	  hadc1.Init.ContinuousConvMode = ENABLE;
	  hadc1.Init.DiscontinuousConvMode = DISABLE;
	  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
	  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
	  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
	 // hadc1.Init.NbrOfConversion = 1;
	  hadc1.Init.DMAContinuousRequests = DISABLE;
	  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;//ADC_EOC_SINGLE_CONV;
	  //naga
	  hadc.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5;
 
	  if (HAL_ADC_Init(&hadc1) != HAL_OK)
	  {
	    Error_Handler();
	  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_0;
	//  sConfig.Rank = 1;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_1;
	//  sConfig.Rank = 2;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	//  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	//  */
	//  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
	//  sConfig.Rank = 3;
	//  sConfig.SamplingTime = ADC_SAMPLETIME_112CYCLES;
	//  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	//  {
	//    Error_Handler();
	//  }
	  /* USER CODE BEGIN ADC1_Init 2 */
 
	  /* USER CODE END ADC1_Init 2 */
}
 
 
void ADC_Select_CH0 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_0;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH1 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_1;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH5 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_5;
	  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void ADC_Select_CH6 (void)
{
	ADC_ChannelConfTypeDef sConfig = {0};
	  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
	  */
	  sConfig.Channel = ADC_CHANNEL_6;
	  //
	  sConfig.Rank = 6;
	  //sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}
 
void Adc_Read_Raw_Data(void)
{
	    ADC1->CHSELR  = 0x01;
		ADC_Select_CH0();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_0_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf,"adc0 %u  \r\n", Adc_0_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_0_Volt = ((float)Adc_0_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_0_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x02;
		ADC_Select_CH1();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_1_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc1 %u \r\n", Adc_1_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_1_Volt = ((float)Adc_1_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_1_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x20;
		ADC_Select_CH5();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_5_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc5 %u \r\n", Adc_5_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_5_Volt = ((float)Adc_5_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_5_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(10);
 
		ADC1->CHSELR  = 0x40;
		ADC_Select_CH6();
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1, 1000);
		Adc_6_Data = HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
		sprintf(Buf," adc6 %u \r\n", Adc_6_Data);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		Channel_6_Volt = ((float)Adc_6_Data/4095)*3.3;
		sprintf(Buf,"adc0 %u  \r\n", (unsigned int)Channel_6_Volt);
		HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
		//HAL_Delay(100);
}

Thankyou all for the support.

hello,

" i have the code to read the adc multiple channel and i can read the values for different channels individually by using separate code for each channel"

can you please share the code, since i am a little stuck.

It would be of great help

  1. void Adc_Read_Raw_Data(void)
  2. {
  3. ADC1->CHSELR = 0x01;
  4. ADC_Select_CH0();
  5. HAL_ADC_Start(&hadc1);
  6. HAL_ADC_PollForConversion(&hadc1, 1000);
  7. Adc_0_Data = HAL_ADC_GetValue(&hadc1);
  8. HAL_ADC_Stop(&hadc1);
  9. sprintf(Buf,"adc0 %u \r\n", Adc_0_Data);
  10. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  11. Channel_0_Volt = ((float)Adc_0_Data/4095)*3.3;
  12. sprintf(Buf,"adc0 %u \r\n", (unsigned int)Channel_0_Volt);
  13. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  14. //HAL_Delay(10);
  15.  
  16. ADC1->CHSELR = 0x02;
  17. ADC_Select_CH1();
  18. HAL_ADC_Start(&hadc1);
  19. HAL_ADC_PollForConversion(&hadc1, 1000);
  20. Adc_1_Data = HAL_ADC_GetValue(&hadc1);
  21. HAL_ADC_Stop(&hadc1);
  22. sprintf(Buf," adc1 %u \r\n", Adc_1_Data);
  23. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  24. Channel_1_Volt = ((float)Adc_1_Data/4095)*3.3;
  25. sprintf(Buf,"adc0 %u \r\n", (unsigned int)Channel_1_Volt);
  26. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  27. //HAL_Delay(10);
  28.  
  29. ADC1->CHSELR = 0x20;
  30. ADC_Select_CH5();
  31. HAL_ADC_Start(&hadc1);
  32. HAL_ADC_PollForConversion(&hadc1, 1000);
  33. Adc_5_Data = HAL_ADC_GetValue(&hadc1);
  34. HAL_ADC_Stop(&hadc1);
  35. sprintf(Buf," adc5 %u \r\n", Adc_5_Data);
  36. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  37. Channel_5_Volt = ((float)Adc_5_Data/4095)*3.3;
  38. sprintf(Buf,"adc0 %u \r\n", (unsigned int)Channel_5_Volt);
  39. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  40. //HAL_Delay(10);
  41.  
  42. ADC1->CHSELR = 0x40;
  43. ADC_Select_CH6();
  44. HAL_ADC_Start(&hadc1);
  45. HAL_ADC_PollForConversion(&hadc1, 1000);
  46. Adc_6_Data = HAL_ADC_GetValue(&hadc1);
  47. HAL_ADC_Stop(&hadc1);
  48. sprintf(Buf," adc6 %u \r\n", Adc_6_Data);
  49. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  50. Channel_6_Volt = ((float)Adc_6_Data/4095)*3.3;
  51. sprintf(Buf,"adc0 %u \r\n", (unsigned int)Channel_6_Volt);
  52. HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
  53. //HAL_Delay(100);
  54. }

Hi. How does one use this select channel, if you want to read adc values inside a timer interrupt? I have started the ADC in the main loop once, but starting and stopping inside the timer didn't work for me.