AnsweredAssumed Answered

Multiple channels adc wrong sequence output (stm32f3 discovery)

Question asked by on Sep 29, 2014
Latest reply on Sep 29, 2014 by Clive One
Hi, i managed to get adc in continuous mode to work with 2 channels.The problem is when the program starts the conversion loop ,it can give me the first channel value for 2 or 4 iterations in a row then switch to the second channel value which have the same issue.To summarise ,I have this example
(Sometimes it is more and others it is less , i guess it is randomised)
Timingdealy=0  ConValue=value in ch1
Timingdealy=1  ConValue=value in ch1
Timingdealy=2  ConValue=value in ch1
Timingdealy=3  ConValue=value in ch1

Timingdealy=4  ConValue=value in ch2
Timingdealy=5  ConValue=value in ch2
My goal is to end this randomised output values.
Here is my code:
#include "stm32f30x.h"
#include "stm32f30x_adc.h"
#include "stm32f30x_gpio.h"
#include "stm32f30x_rcc.h"
__IO uint32_t TimingDelay = 10;
int main(void) {
    ADC_InitTypeDef ADC_InitStruct;
    GPIO_InitTypeDef GPIO_InitStruct;
    ADC_CommonInitTypeDef ADC_CommonInitStructure;
    int test = ADC_CR_ADCAL;
    TimingDelay = 10;
    int ConvValue = 0;
    int calibration_value;
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOA, &GPIO_InitStruct);
        GPIO_PinLockConfig(GPIOA, GPIO_Pin_0);
        GPIO_PinLockConfig(GPIOA, GPIO_Pin_1);
        ADC_InitStruct.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
        ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
        ADC_InitStruct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
        ADC_InitStruct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
        ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStruct.ADC_OverrunMode = DISABLE;
        ADC_InitStruct.ADC_AutoInjMode = DISABLE;
        ADC_InitStruct.ADC_NbrOfRegChannel = 2;
        ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
        ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
        ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular t;
        ADC_CommonInitStructure.ADC_TwoSamplingDelay = 9;
        ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
        ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);
        ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_1Cycles5);
        ADC_VoltageRegulatorCmd(ADC1, ENABLE);
        do {
        } while (TimingDelay > 0);
        ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
    while (ADC_GetCalibrationStatus(ADC1) != RESET)
    calibration_value = ADC_GetCalibrationValue(ADC1);
    ADC_RegularChannelSequencerLengthConfig(ADC1, 1);
    ADC_Cmd(ADC1, ENABLE);
    //while (ADC_GetStartConversionStatus(ADC1) == RESET)
    while (1) {
        while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != RESET) {
            ConvValue = ADC_GetConversionValue(ADC1);
    return (0);

Thank you for your interest