AnsweredAssumed Answered

Multichannel ADC

Question asked by nerold.adam on May 6, 2015
Latest reply on May 13, 2016 by Clive One
Hi, I'm developing application on STM32F0 where I use two gas sensors (CO and CO2), so I need two channels on ADC. In my main.c I only call two functions and on beginig of each function I change channel like so:

void CO()
   {double ADC1ConvertedValue;
//AD conv. and sending data to usart
void CO2()
{double ADC1ConvertedValue;
//AD conv. and sending data to usart}

When I comment on of those two functions it runs just fine (CO gives me value around 750 and CO2 gives me value around 1000 until I blow into it or something). 
But when I uncomment both function and wanna measure both at once it gives me weird numbers, for example CO is 800 and in very next measurment it is 2500 and then back to 800. It seems like mcu cannot handle switching the channels or what. 
Can anyone explain where is the problem?
I'm beginer at programming STM32 and I read something about DMA that it is best way to do it, but I didnt manage to make it functional.
Will this switching of channel work or do I need to use another method?

btw ADC1 conf. is below:

void ADC1_Configuration(void)
  ADC_InitTypeDef ADC_InitStructure;
  /* ADC1 DeInit */
  /* ADC1 Periph clock enable */
     RCC->APB2ENR |= (1<<9);
  /* Initialize ADC structure */
  /* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits  */
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
  ADC_Init(ADC1, &ADC_InitStructure);
  /* ADC Calibration */
  /* Enable ADC1 */
  /* Wait the ADCEN falg */
  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
  /* ADC1 regular Software Start Conv */