Skip to main content
mehmet.karakaya
Associate III
March 19, 2018
Question

F103 ADC DMA - help ! a question

  • March 19, 2018
  • 5 replies
  • 774 views
Posted on March 19, 2018 at 16:55

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];

#dma #f103 #adc
This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
March 19, 2018
Posted on March 19, 2018 at 17:49

There is probably a way of using TIM1 or TIM8 in a One Pulse - Repetition Count mode.

Have the ADC trigger via TIM.

Trigger the TIM to capture 50 events.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mehmet.karakaya
Associate III
March 21, 2018
Posted on March 21, 2018 at 12:16

hello thanks for answering

I searched Google for a F103 + TIM triggered  + ADC + DMA example but couldnot find it

also I couldnot get the SP Library example working

can anybody share a working SPL code please 

thank you

mehmet.karakaya
Associate III
March 21, 2018
Posted on March 21, 2018 at 13:34

I got it working - thank you