AnsweredAssumed Answered

STM32f3 ADC & DMA Problem

Question asked by rehf.alex on Oct 4, 2015
Latest reply on Nov 17, 2017 by G S
Hey,
i am trying hard to get the DMA & ADC controller to work on my discovery board. I want to sample PA1&2, which are connected to current shunts.
the following code is not working, and i am not sure why. the DMA_IT_TC is called once. 
i start the conversion in the TIM1_CC4 with

DMA_SetCurrDataCounter(DMA1_Channel1, 2);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_StartConversion(ADC1);

this is my init_code:

uint16_t ADCBuffer[] = {1,1};


void ADC_DMA_Config(void){




       RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);


       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);


       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);




       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
       GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
       GPIO_Init(GPIOA, &GPIO_InitStructure);


       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
       GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
       GPIO_Init(GPIOA, &GPIO_InitStructure);


       ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
       ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
       ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
       ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
       ADC_CommonInitStructure.ADC_TwoSamplingDelay = 10;


       ADC_CommonInit(ADC1, &ADC_CommonInitStructure);


       ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;
       ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
       ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
       ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
       ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
       ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
       ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
       ADC_InitStructure.ADC_NbrOfRegChannel = 2;
       ADC_Init(ADC1, &ADC_InitStructure);


       /* ADC1 regular channel7 configuration */
       ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_7Cycles5);
       ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 2, ADC_SampleTime_7Cycles5);




       DMA_StructInit(&DMA_InitStructure);
       DMA_InitStructure.DMA_PeripheralBaseAddr  = (uint32_t)&(ADC1->DR);
       DMA_InitStructure.DMA_MemoryBaseAddr  = (uint32_t)&ADCBuffer;
       DMA_InitStructure.DMA_DIR  = DMA_DIR_PeripheralSRC;
       DMA_InitStructure.DMA_BufferSize  = 2;
       DMA_InitStructure.DMA_PeripheralInc  = DMA_PeripheralInc_Disable;
       DMA_InitStructure.DMA_MemoryInc  = DMA_MemoryInc_Enable;
       DMA_InitStructure.DMA_PeripheralDataSize  = DMA_PeripheralDataSize_HalfWord;
       DMA_InitStructure.DMA_MemoryDataSize  = DMA_MemoryDataSize_HalfWord;
       DMA_InitStructure.DMA_Mode  = DMA_Mode_Normal;
       DMA_InitStructure.DMA_Priority  = DMA_Priority_Medium;
       DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
       DMA_Init(DMA1_Channel1, &DMA_InitStructure);
       DMA_ClearITPendingBit(DMA1_IT_TC1);
       DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);




       NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
       NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
       NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
       NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
       NVIC_Init(&NVIC_InitStructure);




       /* Enable ADC1 */
       ADC_DMAConfig( ADC1, ADC_DMAMode_OneShot);
       ADC_DMACmd(ADC1, ENABLE);
       ADC_Cmd(ADC1, ENABLE);
     }

Outcomes