AnsweredAssumed Answered

reading multiple adc channels, no dma

Question asked by achterop.sietse on Jan 26, 2015
  Hello List,

I,m struggling with reading, without DMA, from multiple channels.
Every, say, 10 msec I call:
var1 = Get_ADC_Value(11);
var2 = Get_ADC_Value(12);

Both variables ALWAYS get the same value, that is the value from the first called channel, here 11.

The function (partly) is:
int16_t Get_ADC_Value(uint8_t Channel)
{
  uint16_t ADC_Val; //Stores the calculated ADC value
  switch(Channel)
    {
    case 11:
      ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_84Cycles);
      ADC_SoftwareStartConv(ADC1);
      while(ADC_GetSoftwareStartConvStatus(ADC1) != RESET){ADC_Val = 0;}
      ADC_Val = ADC_GetConversionValue(ADC1);
      break;
    case 12:
      ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_84Cycles);
      ADC_SoftwareStartConv(ADC1);
      while(ADC_GetSoftwareStartConvStatus(ADC1) != RESET){ADC_Val = 0;}
      ADC_Val = ADC_GetConversionValue(ADC1);
      break;
                .... other channels



The configuration:
void ADC_Configuration(void)
{
  ADC_InitTypeDef       ADC_InitStructure;
  ADC_CommonInitTypeDef ADC_CommonInitStructure;
  GPIO_InitTypeDef      GPIO_InitStructure;
 
  /* Configure ADC Channel 11, 12, 15, and 14 as analog input */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_5 | GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  /* ADC Common configuration *************************************************/
  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInit(&ADC_CommonInitStructure);
  
  /* ADC1 regular channel 10 to 15 configuration ************************************/
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfConversion = 1;
  ADC_Init(ADC1, &ADC_InitStructure);
  ADC_Init(ADC2, &ADC_InitStructure);
  
  /* Enable ADC1 to ADC3*/
  ADC_Cmd(ADC1, ENABLE);
  ADC_Cmd(ADC2, ENABLE);
}

Clocks are also enabled.
All in all completely standard, but ....

Hopefully someone can help me.
     Thanks in advance,
           Sietse

Outcomes