{"id":2951,"date":"2024-10-30T13:08:31","date_gmt":"2024-10-30T13:08:31","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2951"},"modified":"2024-10-30T13:08:33","modified_gmt":"2024-10-30T13:08:33","slug":"getting-started-with-stm32h5-arm-cortex-m33-adc-single-channel-continuous-conversion","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2951","title":{"rendered":"Getting Started with STM32H5 ARM Cortex M33: ADC Single Channel Continuous Conversion"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"725\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-1024x725.webp\" alt=\"\" class=\"wp-image-2952\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-1024x725.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-300x212.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-768x544.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-750x531.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-400x283.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3-250x177.webp 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/STM32-u5-1-1-3.webp 1141w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide on STM32H5, we shall configure the ADC of the STM32H5 to acquire analog voltage using polling mode in continuous mode.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Single vs continuous conversion.<\/li>\n\n\n\n<li>Modification to STM32CubeMX.<\/li>\n\n\n\n<li>Modification to the source code.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. Single vs Continuous Conversion:<\/h2>\n\n\n\n<p>In STM32 microcontrollers, Analog-to-Digital Converters (ADC) can operate in <strong>single conversion<\/strong> or <strong>continuous conversion<\/strong> modes, each serving different purposes based on the application requirements.<\/p>\n\n\n\n<p><strong>1. Single Conversion Mode<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Operation<\/strong>: In single conversion mode, the ADC performs a single conversion of the selected channel(s) and then stops. Once the conversion is complete, the ADC goes idle until it\u2019s triggered again (either manually by software or by an external trigger).<\/p>\n\n\n\n<p>\u2022 <strong>Use Case<\/strong>: This mode is ideal for applications that require occasional sampling, like reading sensor values at specific intervals. It\u2019s useful when the system needs precise control over when conversions happen and avoids unnecessary power consumption.<\/p>\n\n\n\n<p>\u2022 <strong>Power Efficiency<\/strong>: Since the ADC is only active during the conversion, single conversion mode is more power-efficient for low-frequency measurements.<\/p>\n\n\n\n<p><strong>2. Continuous Conversion Mode<\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Operation<\/strong>: In continuous conversion mode, the ADC repeatedly converts the selected channel(s) without stopping. As soon as one conversion is complete, another conversion starts automatically.<\/p>\n\n\n\n<p>\u2022 <strong>Use Case<\/strong>: This mode is beneficial for real-time monitoring applications where continuous sampling is needed, such as audio signal processing, data acquisition systems, or control systems that need frequent updates.<\/p>\n\n\n\n<p>\u2022 <strong>Data Handling<\/strong>: Continuous mode generates an ongoing stream of data, so it often requires efficient handling, like using DMA (Direct Memory Access) to transfer data to memory without CPU intervention, which improves performance in time-sensitive applications.<\/p>\n\n\n\n<p><strong>Key Differences<\/strong><\/p>\n\n\n\n<p><strong>Aspect<\/strong> <strong>Single Conversion Mode<\/strong> <strong>Continuous Conversion Mode<\/strong><\/p>\n\n\n\n<p><strong>Conversion Trigger<\/strong> Manually triggered or by an external event Starts automatically after each conversion<\/p>\n\n\n\n<p><strong>Power Consumption<\/strong> Lower, as ADC is idle between triggers Higher, as ADC is always active<\/p>\n\n\n\n<p><strong>Data Handling<\/strong> Easier, no need for constant reading May require DMA to manage continuous data<\/p>\n\n\n\n<p><strong>Use Cases<\/strong> Intermittent measurements Real-time or continuous data acquisition<\/p>\n\n\n\n<p><strong>Choosing Between the Two<\/strong><\/p>\n\n\n\n<p>\u2022 Use <strong>single conversion<\/strong> mode when you need control over when the ADC operates, conserving power, or if you only need periodic data.<\/p>\n\n\n\n<p>\u2022 Use <strong>continuous conversion<\/strong> mode for applications where constant monitoring is critical and fast data handling is set up (like with DMA).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"596\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-1024x596.png\" alt=\"\" class=\"wp-image-2953\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-1024x596.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-300x175.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-768x447.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-1150x669.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-750x437.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-400x233.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079-250x146.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/IMG_0079.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Modification to STM32CubeMX:<\/h2>\n\n\n\n<p>From the left side in project, open adc_single.ioc file as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-1024x572.jpg\" alt=\"\" class=\"wp-image-2954\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-1024x572.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-300x167.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-768x429.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-1536x857.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-2048x1143.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-1150x642.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-750x419.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-400x223.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-35-13-250x141.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Then from ADC section, parameter settings, enable the continuous mode as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-1024x572.jpg\" alt=\"\" class=\"wp-image-2955\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-1024x572.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-300x167.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-768x429.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-1536x857.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-2048x1143.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-1150x642.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-750x419.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-400x223.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-30_15-36-31-250x141.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the configuration. Save the project and that will generate the new configuration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Modification to the Source Code:<\/h2>\n\n\n\n<p>move the following function from the while 1 loop to user code begin 2:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_ADC_Start(&amp;hadc1);<\/pre><\/div>\n\n\n\n<p>In continuous mode, we need only to launch the ADC once and it will take over.<\/p>\n\n\n\n<p>That all for the guide.<\/p>\n\n\n\n<p>Save, build and run the project on your STM32H563Zi Nucleo-144 as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"28\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-1024x28.png\" alt=\"\" class=\"wp-image-2958\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-1024x28.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-300x8.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-768x21.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-1536x43.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-1150x32.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-750x21.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-400x11.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1-250x7.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/image-1.png 1734w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>Open your serial terminal application, set the baud rate 115200 and you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"733\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-1024x733.jpg\" alt=\"\" class=\"wp-image-2959\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-1024x733.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-300x215.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-768x550.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-1150x823.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-750x537.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-400x286.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2-250x179.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-24_07-17-00-2.jpg 1168w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude09 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide on STM32H5, we shall configure the ADC of the STM32H5 to acquire analog voltage using polling mode in continuous mode. In this guide, we shall cover the following: 1. Single vs Continuous Conversion: In STM32 microcontrollers, Analog-to-Digital Converters (ADC) can operate in single conversion or continuous conversion modes, each serving different purposes [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-2951","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2951"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2951"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2951\/revisions"}],"predecessor-version":[{"id":2960,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2951\/revisions\/2960"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}