Getting started with STM32L053: ADC Multi Channel Continuous Conversion with DMA

In the previous guide (here), we took a look at the continuous mode for ADC module of STM32L0. In this guide, we shall see how to configure the ADC to work in DMA mode with two channels enabled. (Can be expanded to the desired number of channels).

In this guide, we shall cover the following:

  • What is DMA
  • Why should we use DMA when dealing with multiple channel in ADC
  • Configuring the ADC and DMA
  • Required parts and schematics
  • Code
  • Result

1. What is DMA

DMA which stands for Direct Memory Access is part of MCU that handle data transfer from peripheral to memory without invoking CPU at all which relief cpu to do something else, like processing the acquired adc vlaue for dsp processing etc

DMA (From digikey)

DMA can be operate in three different mode, Memory to Memory (moving one variable from one location to another), memory to peripheral (send string from memory to PC through UART) and peripheral to memory like in our case acquiring data from adc.

2. Why should we use DMA when dealing with multiple channel in ADC

Let say you want ti acquire data from adc from 3-channel in continuous mode. Since each conversion requires 15 cycles for 12-bit since the adc clock is the core frequency over (16MHz/2=8MHz), thats means generating interrupts at rate near half mega hertz which will effect the performance of the mcu. Hence, using DMA in such case makes sense.

3. Configure the ADC and DMA:

Create aa new source file with name of adc.c

We start off by enabling clock access to GPIOA and set PA0 and PA1 to analog mode:

	/*Enable clock access to GPIOA*/

	/*Set pa4 mode to analog mode*/

Enable clock access to ADC1:

	/*Enable clock access to ADC*/

Configure the operation to be continuous mode:

    /*Set Continuous conversion mode*/

Select the operation channel to be channel 0 and channel 1:

	/*Set sequencer channel*/

Set clock to be CLK/2:

	/*Set clock to be CLCK/2*/


Now, enable DMA for ADC:

	/*Enable ADC DMA*/

Since STM32L053 has only single DMA and it is connected to AHB Bus, we can enable clock access to DMA1 as following:


From table below which represents the DMA request channels, we can see that DMA1_Channel1 and channel2 can be used with the ADC. Hence, we shall use channel1.

Now, we shall configure the DMA:

The configuration as following:

  • Memory size to 16-bit.
  • Peripheral size to 16-bit.
  • Memory Increment.
  • Circular Mode

We shall set number of transfer as the size of the array:


Set the peripheral address to be ADC1->DR and memory address to the array:

	DMA1_Channel1->CPAR= (uint32_t)(&ADC1->DR);

Finally enable the DMA:


Configure the ADC_DMA in circular mode:


Launch ADC calibration:

	while(ADC1->CR & ADC_CR_ADCAL);

Enable the ADC:


Start the conversion:


For getting the adc data:

uint16_t get_adc_value (adc_Channel channel)
	return adc_dma_data[channel];


For the header file of adc.h:

#ifndef ADC_H_
#define ADC_H_

typedef enum {

#include <stdint.h>

void adc_dma_init(void);

uint16_t get_adc_value (adc_Channel channel);

#endif /* ADC_H_ */

In main.c file:

#include "uart.h"
#include "adc.h"
#include "stdio.h"

int main(void)


		printf("Channel 0=%d\t Channel 1=%d\r\n",get_adc_value(Channel0),get_adc_value(Channel1));
		for (int i=0;i<1000;i++);



4. Connection:

5. Code:

You may download the code from here:

6. Results:

Open serial monitor program and set the baudrate to 9600 and rotate the pot. you should see the values changes

Happy coding đŸ™‚

Add Comment

Your email address will not be published. Required fields are marked *