AnsweredAssumed Answered

STM32F072 ADC and DMA Help

Question asked by mozaffar.abid on Aug 5, 2014
Latest reply on Aug 5, 2014 by Clive One

I'm new to the concept of using DMA with ADC on STM32F072 MCU and I want to read 6 ADC channels (PA0 thru PA5) using DMA.

Initially I tried reading the 6 channels just by configuring the ADC as follows:

void Adc_Init(void)
  RCC->AHBENR  |= (1UL<<17);      //Enable GPIOA.
  RCC->APB2ENR |= (1UL<< 9);     //Enable ADC.
  GPIOA->MODER |= (3UL<<0*2);     //PA0 is analog.
  GPIOA->MODER |= (3UL<<2*1|3UL<<2*2|3UL<<2*3|3UL<<2*4|3UL<<2*5);     //Setting PA 1 thru 5 pins in analog mode.

  ADC1->CR      =     0x00000005;     //Start the ADC conversion.
  ADC1->CFGR1     =     0x0000E4C0;     //Auto-Off ON, Wait ON, Cont. conv. ON, EXTEN set to 01 (detect rising edge), EXTSEL set to 011.
  ADC1->SMPR     =     0x00000003;     //SMP set to 011 (28.5 ADC clock cycles. This applies to all channels)
  ADC1->TR     =     0x0FFF0000;     // HT (analog watchdog high trigger) is set to 0xFFF.

uint16_t Get_Adc(uint8_t ch)   
  ADC1->CHSELR |= (1UL<<ch);
  while (!(ADC1->ISR & 1<<2));     
  return ADC1->DR;     

I tried setting a variable to read each channel but it turned out that the channels got interwoven and so changing the value on one channel would disrupt the other channels.

Based on my quick research, I found that what I would be needing is a DMA for my ADC channels in order to correctly read each ADC channel value. So, is it possible for me to get a template which shows how the configuration of the ADC and DMA is done and how to read the 6 channels of ADC using DMA?

Thank you very much for your help.