AnsweredAssumed Answered

DMA only fetching 2 values from ADC

Question asked by John Hite on Apr 20, 2017
Latest reply on Apr 23, 2017 by waclawek.jan



This is an update from my previous thread:STM32F4 ADC/DMA always returns same value. 


The ADC2 DR has the right value in it but the DMA is not working as I thought it would. It is only transferring 2 values although the array size and # of readings is 8. Condensed code is below.





#define ADC_NUM_READINGS 8  //  Changing these will require a significant change


void AdcInit(void);
uint16_t readVoltage(void);
static uint16_t adc2_result[ADC_NUM_READINGS];


static const DMA_InitTypeDef dma2 =
    ADC2_BASE + 0x4C,                       //  ADC2->DR
    (uint32_t)&adc2_result,               //Mememory 0 base address


void adcInit(void)
    ADC_CommonInitTypeDef cInit;
    ADC_InitTypeDef init;
    OS_ERR err;


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);


    DMA_Init(DMA2_Stream2, (DMA_InitTypeDef*)&dma2);
    DMA_Cmd(DMA2_Stream2, ENABLE);


    cInit.ADC_Mode = ADC_Mode_Independent;
    cInit.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
    cInit.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
    cInit.ADC_Prescaler = ADC_Prescaler_Div2;


    init.ADC_Resolution = ADC_Resolution_12b;
    init.ADC_ScanConvMode = DISABLE;
    init.ADC_ContinuousConvMode = ENABLE;
    init.ADC_DataAlign = ADC_DataAlign_Right;
    init.ADC_NbrOfConversion = 1;
    ADC_Init(ADC2, &init);


    ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 1, ADC_SampleTime_15Cycles);
    //ADC_DMARequestAfterLastTransferCmd(ADC2, ENABLE);
    ADC_Cmd(ADC2, ENABLE);


uint16_t readVoltage(void)

   return adc2_result[0];   // I set a break point here and examine the array. Locations 2-7 are always zero.