{"id":947,"date":"2022-05-14T15:05:02","date_gmt":"2022-05-14T15:05:02","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=947"},"modified":"2022-05-14T15:05:05","modified_gmt":"2022-05-14T15:05:05","slug":"getting-started-with-stm32l053-adc-single-channel-continuous-conversion","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=947","title":{"rendered":"Getting started with STM32L053: ADC Single Channel Continuous  Conversion"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"323\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1024x323.png\" alt=\"\" class=\"wp-image-202\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1024x323.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-300x95.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-768x243.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1150x363.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-750x237.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-400x126.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-250x79.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=936\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=936\" target=\"_blank\">here<\/a>), we took a look at how t configure the ADC of STM32L053 in single channel single conversion mode. In this guide, we shall see how to configure the ADC to work 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\"><li>Difference between Single Conversion and Continuous Conversion.<\/li><li>What extra steps needed to enable continuous mode.<\/li><li>Results<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Difference between Single Conversion and Continuous Conversion&nbsp;<\/h2>\n\n\n\n<p>In the single conversion mode, the ADC does one conversion and stop as soon as the conversion ended. The process can\u2019t started unless the start is triggered by software. This can be useful for certain application like monitor battery capacity like every 10 minutes.&nbsp;<\/p>\n\n\n\n<p>In continuous conversion mode, the ADC starts a new conversion as soon as it finishes one. This mode has the advantage of keeping the ADC value up to date for control purposes such as temperature, flow rate etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. What the extra steps needed to enable Continuous Conversion<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>As we saw from the previous guide, we enabled the adc manually every time we needed to get a new adc value. To enable continuous mode, we need to enable CONT_bit (Bit 13) in ADC configuration register1 (ADC_CFGR1).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"325\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-1024x325.png\" alt=\"\" class=\"wp-image-940\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-1024x325.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-300x95.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-768x244.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-1536x488.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-2048x651.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-1150x365.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-750x238.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-400x127.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.04.08-AM-250x79.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/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;}\"> \/*Set Continuous conversion mode*\/\n\tADC1-&gt;CFGR1 |=ADC_CFGR1_CONT;<\/pre><\/div>\n\n\n\n<p>And in the main function,<\/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;}\">#include &quot;uart.h&quot;\n#include &quot;adc.h&quot;\n#include &quot;stdio.h&quot;\nuint32_t adc_data;\nint main(void)\n{\n\tpa1_adc_init();\n\tadc_activate();\n\tuart_init();\n\tstart_conversion();\n\twhile(1)\n\t{\n\n\t\tadc_data=adc_read();\n\t\tprintf(&quot;adc data=%ld\\r\\n&quot;,adc_data);\n\t\tfor (int i=0;i&lt;1000;i++);\n\n\n\t}\n\n}\n<\/pre><\/div>\n\n\n\n<p>As you may noticed, the start conversion is called once and the conversion will occur automatically:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Results:<\/h2>\n\n\n\n<p>Open a serial terminal and set the baud rate at 9600 and you will get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"718\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-1024x718.png\" alt=\"\" class=\"wp-image-945\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-1024x718.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-300x210.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-768x538.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-1150x806.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-750x526.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-400x280.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM-250x175.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/05\/Screen-Shot-2022-05-11-at-8.11.58-AM.png 1170w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look at how t configure the ADC of STM32L053 in single channel single conversion mode. In this guide, we shall see how to configure the ADC to work in continuous mode. In this guide, we shall cover the following: Difference between Single Conversion and Continuous Conversion. What [&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-947","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\/947"}],"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=947"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions\/948"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}