cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 ADC and DMA Help

abid_naeemm
Associate II
Posted on August 05, 2014 at 19:36

Hello,

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.

#dma #adc #stm32f0
4 REPLIES 4
Posted on August 05, 2014 at 20:06

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F0%20ADC-DMA%20touble&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=312]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F0%20ADC-DMA%20touble&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=312

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
abid_naeemm
Associate II
Posted on August 05, 2014 at 20:22

Thank you Clive1!

I saw that you are using timers in that thread to get the values. Is it possible to read the channels without using any timers for stm32f0?

abid_naeemm
Associate II
Posted on August 05, 2014 at 20:24

Something very similar to the following thread but with 6 channels instead:

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FMulti%20Channel%20ADC%20reading&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=2362

The problem for me to refer to the above thread is that it is stm32f4 and I not sure how far off is stm32f4 from stm32f072...

Posted on August 05, 2014 at 21:03

So don't use the timers

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;// Not triggered

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; // Not triggered

Remove the TIM code

See also

STM32F0308-Discovery_FW_V1.0.1\Projects\Peripheral_Examples\ADC_DMA\main.c

STM32F072B-Discovery_FW_V1.0.1\Projects\Peripheral_Examples\ADC_DMA\main.c

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..