DMA is an important feature of any microcontroller. In this article, we are going to learn how we can use DMA for ADC reading with STM32. Here I’ll continue from the previous article. So let’s start.
⚠️ Disclaimer ⚠️
Working with electricity involves serious risk. Ensure you have the necessary skills and take proper safety precautions before attempting any electrical projects. Proceed at your own risk — the author assumes no responsibility for any damage, injury, or issues resulting from the use or misuse of the information provided.
All content on this website is original and protected by copyright. Please do not copy or reproduce content without permission. While most of the resources shared here are open-source and freely accessible for your learning and benefit, your respect for our intellectual effort is appreciated.
If you find our tutorials helpful, consider supporting us by purchasing related materials or sharing our work — it helps keep the content flowing.
Need help or have questions? Leave a comment below — the author is always happy to assist!
Table of Contents
About the previous article:
In our previous article, we discussed how we can use ADC from STM32 microcontroller, especially STM32103C8Tx MCU. If you have not read it, please read that article from here: ADC Reading with STM32103C8Tx (BluePill)
So, why DMA?
DMA or Direct Memory Access allows you to access the memory directly from the section it is set. So the MCU itself is free to calculate and get the result and can work elsewhere. This enables a faster response and low pressure on the processor.

So, DMA helps getting access to the resources without disturbing the process running in the main processor.
Using DMA in STM32:
To activate DMA, first, open the .ioc file and go to ADC (or DMA) from the left selection section.
Now, select how many ADCs you need to use. Then mark them one by one. And then click on DMA Settings:
Here, in the DMA mode, select ‘Circular’ so that DMA can read the data continuously in a circular mode. Then click on ‘Parameters Settings’.
Here, set how many conversions you are using. In my case, I used 7, so selected 7. Then in the ‘Rank’ selection, select one by one.
Example: Rank 1: Channel 0, Sampling: 7.5 Cycles.
Note, here more the cycle, the more stable the value is and the more time it will consume to give results.
After selecting the ranks. then save the project to generate code.
Main.c File with DMA in STM32:
In the main.c file, you need some lines to add. In the variable section, declare an array where you can store the readings.

Then simply start DMA with following lines:
Its enough to read the analog signals now without any further codes.
Debugging:
Now, simply connect your device and debugger(ST-Link) and click on debug.
Now, you’ll find the results. So, you can use them in the other part of the code.
I hope this article will help you with learning STM32. See you soon with more useful articles. thanks.
You can also read my other articles which may help you:
- ADC Reading with STM32103C8Tx (BluePill)
- Adafruit_FONA Library with ESP32
- INA219 interfacing with STM32
- STM32 as USB Device
Liked this article? Subscribe to our newsletter:
or,
Visit LabProjectsBD.com for more inspiring projects and tutorials.
Thank you!
0 Comments