AnsweredAssumed Answered

F103 ADC DMA - help ! a question

Question asked by karakaya.mehmet on Mar 19, 2018
Latest reply on Mar 22, 2018 by karakaya.mehmet

hello dear forum,

 

I want use ADC + DMA with F103

I want start ADC conversion with external input and want 

ADC convert 50 samples and stop until next start

 

however with every start ADC measures one single sample and put it in the target array

with incrementing the target array adres

 

please advice 

thank you

my code 

--------------------------------------------------------

void init_adc1(void)
{
//    ADC_InitTypeDef  ADC_InitStructure;

 

GPIO_InitStructure.GPIO_Pin = /*GPIO_Pin_4|*/GPIO_Pin_5 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
//  RCC_ADCCLKConfig(RCC_PCLK2_Div2); 
  ADC_DeInit(ADC1);

 

  ADC_InitStructure.ADC_ScanConvMode = ENABLE; // tarama modu açık
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; 
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; 
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 2; // 
  ADC_Init(ADC1, &ADC_InitStructure);

 

    adc_channel_config();
    ADC_DMACmd(ADC1,ENABLE);
  ADC_Cmd(ADC1, ENABLE); 

 

  ADC_ResetCalibration(ADC1);
  while(ADC_GetResetCalibrationStatus(ADC1));

 

  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));
      
}

void ADC1_DMAConfig(void){
DMA_InitTypeDef DMA_InitStructure;

  DMA_Cmd(DMA1_Channel1,DISABLE);
  DMA_DeInit ( DMA1_Channel1);

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x4001244C; // ADC->DR Adresi
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) ADC_ValArray; // hedef adresimiz
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // ADC kaynak. Veri yönü ADC -> Hafıza 
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // ADC adresi sabit kalacak
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Her değer alındığına memory adresi 1 artırılacak
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  // Kaynaktan alınacak veri 16 bit
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; // Hedef büyüklüğü 16 bit
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //veri alındıktan sonra başa dönülecek.
  DMA_InitStructure.DMA_Priority = DMA_Priority_High ; // Kanal Önceliği yüksek. ( bu bize kalmış)
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // hafızadan hafızaya transfer kapalı. 
  DMA_InitStructure.DMA_BufferSize = 100; // 
  
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
  DMA_Cmd(DMA1_Channel1,ENABLE);

}

        if (GPIOB->IDR&GPIO_Pin_9) RAM[0]=0;else RAM[0]=1;
        if(RAM[0]&&!RAM[20])ADC_ExternalTrigConvCmd(ADC1, ENABLE);
        RAM[20]=RAM[0];

Outcomes