title: Not getting correct values of potentiometer in the channel1 and channel2 in stm32f103
body: <p>I have been trying to read values from two potentiometers connected to channel1 and channel2 in ADC1 and read the values through UART in a serial Terminal,but unable to do it. It either comes random value or a same value for both the POTS. ADC works perfectly for a single channel.
  The board I am using is STM32F103(Bluepill).
  I have my own UART library that I am using to read.</p>
  <p><strong>ADC initialisation</strong>
  in the regular channel configurations, I made two different functions of both thechannels</p>
  <pre><code>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 */
  
    /** Common config
    */
    hadc1.Instance = ADC1;
    hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
    hadc1.Init.ContinuousConvMode = ENABLE;
    hadc1.Init.DiscontinuousConvMode = DISABLE;
    hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
    hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
    hadc1.Init.NbrOfConversion = 2;
    if (HAL_ADC_Init(&amp;hadc1) != HAL_OK)
    {
      Error_Handler();
    }
  
    /** Configure Regular Channel
    */
   
  </code></pre>
  <p>For configuring the regular channels I made two different functions as these will be called in other functions with a multiplication factor.</p>
  <pre><code>void ADC_SET_CH1()
  {
       //MX_ADC1_Init();
      ADC_ChannelConfTypeDef sConfig = {0};
       sConfig.Channel = ADC_CHANNEL_1;
    sConfig.Rank = ADC_REGULAR_RANK_1;
    sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5;
    if (HAL_ADC_ConfigChannel(&amp;hadc1, &amp;sConfig) != HAL_OK)
    {
      Error_Handler();
    }
        HAL_NVIC_EnableIRQ(ADC1_IRQn);
  }
  
   void ADC_SET_CH2()
   {
       //MX_ADC1_Init();
       ADC_ChannelConfTypeDef sConfig = {0};
       sConfig.Channel = ADC_CHANNEL_2;
         sConfig.Rank = ADC_REGULAR_RANK_2;
         sConfig.SamplingTime = ADC_SAMPLETIME_41CYCLES_5;
         if (HAL_ADC_ConfigChannel(&amp;hadc1, &amp;sConfig) != HAL_OK)
         {
           Error_Handler();
         }
         HAL_NVIC_EnableIRQ(ADC1_IRQn);
   }
  </code></pre>
  <p>The different functions that I made in order to call them in the while loop to read the values in serial terminal:</p>
  <pre><code>float read_value1()
   {
       ADC_SET_CH1();
      //rawData=0.1525*readAdc(0x01);
      // HAL_ADC_Start_IT(&amp;hadc1);
       rawdata1=0.1525*HAL_ADC_GetValue(&amp;hadc1);
      return rawdata1;
   }
   float read_value2()
    {
       ADC_SET_CH2();
      //rawData1=0.1525*readAdc(0x02);
      //HAL_ADC_Start_IT(&amp;hadc1);
       rawData=0.1525*HAL_ADC_GetValue(&amp;hadc1);
  
      return rawData;
    }
  </code></pre>
  <p><strong>MAIN:</strong></p>
  <pre><code>#include &quot;main.h&quot;
  
  /* Private includes ----------------------------------------------------------*/
  /* USER CODE BEGIN Includes */
  #include &quot;uart.h&quot;
  #include &quot;stm32f1xx_it.h&quot;
  
  char *readbuffer;
  float rawData=0.0f;
  float potValue=0.0f;
  char *readbuffer1;
  float rawdata1=0.0f;
  float potvalue1=0.0f;
  int main(void)
  {
    
    HAL_Init();
    SystemClock_Config();
    MX_GPIO_Init();
    MX_ADC1_Init();
    MX_USART1_UART_Init();
    MX_TIM3_Init();
    /* USER CODE BEGIN 2 */
    HAL_ADC_Start_IT(&amp;hadc1);
  </code></pre>
  <p><strong>while 1:</strong></p>
  <pre><code>while (1)
    {
       potValue=read_value1();
    readbuffer=(convertIntToString(potValue));
    writeString1(&quot;pot0:&quot;);
    writeString1(readbuffer);
    //writeString1(&quot;\n&quot;);
    HAL_Delay(500);
    writeString1(&quot;     &quot;);
    potvalue1= read_value2();
    readbuffer1=convertIntToString(potvalue1);
    writeString1(&quot;pot1:&quot;);
    writeString1(readbuffer1);
    writeString1(&quot;\n&quot;);
  }
  }
  </code></pre>
  <p><strong>The IRQ function:</strong></p>
  <pre><code>  void ADC1_2_IRQHandler(void)
  {
    /* USER CODE BEGIN ADC1_2_IRQn 0 */
      adcValue=ADC1-&gt;DR;
      //HAL_ADC_Start_IT(&amp;hadc1);
    /* USER CODE END ADC1_2_IRQn 0 */
    HAL_ADC_IRQHandler(&amp;hadc1);
    /* USER CODE BEGIN ADC1_2_IRQn 1 */
  
    /* USER CODE END ADC1_2_IRQn 1 */
  }
  </code></pre>