AnsweredAssumed Answered

STM32F303 StdLibrary ADC4 DMA

Question asked by tntbc on Oct 27, 2016
Latest reply on Oct 30, 2016 by tntbc
Hello,
i have a small problem with the ADC4 and the DMA. The code following below works with the ADC1 fine. But the ADC4 makes problems. The ADC4 works, this  i could see in the debug window. But the DMA request did not work. What is my mistake?
void ADC_VoltageInit(){
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
 
  RCC_AHBPeriphClockCmd(RCC_AHBENR_ADC34EN,ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOBEN,ENABLE);
 
  GPIO_InitADC.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitADC.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitADC.GPIO_Pin = GPIO_Pin_12;
  GPIO_Init(GPIOB,&GPIO_InitADC);
 
  RCC_ADCCLKConfig(RCC_ADC34PLLCLK_Div1);
  ADC_Init(ADC4,&ADC_Struct);
  ADC_VoltageRegulatorCmd(ADC4,ENABLE);
  Delay(10);//Warte auf den Regulator;
  ADC_SelectCalibrationMode(ADC4,ADC_CalibrationMode_Single);
  ADC_StartCalibration(ADC4);
  while(ADC_GetCalibrationStatus(ADC4) != RESET);
 
 
 
  nvicADC.NVIC_IRQChannelCmd = ENABLE;     
  nvicADC.NVIC_IRQChannelPreemptionPriority = 1;
  nvicADC.NVIC_IRQChannelSubPriority = 1;   
  nvicADC.NVIC_IRQChannel = DMA2_Channel4_IRQn;
  NVIC_Init(&nvicADC);
 
  SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_ADC2ADC4,ENABLE);
 
  ADC_Def.ADC_Clock = ADC_Clock_AsynClkMode;
  ADC_Def.ADC_Mode = ADC_Mode_Independent;
  ADC_Def.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
  ADC_Def.ADC_DMAMode = ADC_DMAMode_Circular;
  ADC_Def.ADC_TwoSamplingDelay = 0;
  ADC_CommonInit(ADC4,&ADC_Def);
 
  ADC_Struct.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
  ADC_Struct.ADC_Resolution = ADC_Resolution_10b;
  ADC_Struct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
  ADC_Struct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
  ADC_Struct.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_Struct.ADC_OverrunMode = ADC_OverrunMode_Disable;
  ADC_Struct.ADC_AutoInjMode = ADC_AutoInjec_Disable;
  ADC_Struct.ADC_NbrOfRegChannel = 1;
 
  ADC_Init(ADC4,&ADC_Struct);
  ADC_RegularChannelConfig(ADC4,ADC_Channel_3,1,ADC_SampleTime_7Cycles5);
  dmaADCInit.DMA_BufferSize = ADC_LNG;
  dmaADCInit.DMA_DIR = DMA_DIR_PeripheralSRC;
  dmaADCInit.DMA_M2M = DMA_M2M_Disable;
  dmaADCInit.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  dmaADCInit.DMA_MemoryInc = DMA_MemoryInc_Enable;
  dmaADCInit.DMA_Mode = DMA_Mode_Normal;
  dmaADCInit.DMA_PeripheralDataSize = DMA_MemoryDataSize_HalfWord;
  dmaADCInit.DMA_PeripheralInc = DMA_MemoryInc_Disable;
  dmaADCInit.DMA_Priority = DMA_Priority_Medium;
  dmaADCInit.DMA_MemoryBaseAddr = (uint32_t)ADC3ConvertedValue;
  dmaADCInit.DMA_PeripheralBaseAddr = (uint32_t)&ADC4->DR;
 
  DMA_Init(DMA2_Channel4,&dmaADCInit);
  DMA_ITConfig(DMA2_Channel4,DMA2_IT_TC4,ENABLE);
 
  ADC_DMAConfig(ADC4,ADC_DMAMode_OneShot);
  ADC_DMACmd(ADC4,ENABLE);
  ADC_Cmd(ADC4,ENABLE);
 
  while(!ADC_GetFlagStatus(ADC4, ADC_FLAG_RDY));
  DMA_Cmd(DMA2_Channel4,ENABLE);
  ADC_StartConversion(ADC4);
}

Outcomes