cancel
Showing results for 
Search instead for 
Did you mean: 

F103 ADC DMA - help ! a question

mehmet.karakaya
Associate III
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
5 REPLIES 5
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
Up vote any posts that you find helpful, it shows what's working..
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

Posted on March 21, 2018 at 13:34

I got it working - thank you

Posted on March 21, 2018 at 14:56

I got it working but following ;

It ADConvert only 1 time for every trigger 

but I set the DMA buffer size to 50 for single channel

how can I make it ADConvert a sequence of samples for each trigger ?

thank you

my code 

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

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x4001244C; 

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) ADC_ValArray; 

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;  

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

DMA_InitStructure.DMA_Priority = DMA_Priority_High ;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; 

DMA_InitStructure.DMA_BufferSize = 100; 

----

ADC_InitStructure.ADC_ScanConvMode = DISABLE ;

ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 2; 

ADC_Init(ADC1, &ADC_InitStructure)

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

Posted on March 22, 2018 at 11:01

noone has any idea ?