{"id":581,"date":"2021-11-18T03:31:18","date_gmt":"2021-11-18T03:31:18","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=581"},"modified":"2021-11-18T15:48:38","modified_gmt":"2021-11-18T15:48:38","slug":"working-with-stm32f7-and-adc-part-1-single-channel-continuous-conversion","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=581","title":{"rendered":"Working with STM32F7 and ADC part 2: Single channel Continuous  Conversion"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"323\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-1024x323.png\" alt=\"\" class=\"wp-image-225\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-1024x323.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-300x95.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-768x243.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-1150x363.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-750x237.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-400x126.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1-250x79.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/1200px-ADC_Symbol.svg_-1.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=562\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=562\" target=\"_blank\">here<\/a>), we took a look how to configure the ADC in STM32F7 for single channel single conversion. In this guide, we shall configure the ADC in continuous mode conversion.<\/p>\n\n\n\n<p>In this guide, we will 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>Connection diagram<\/li><li>Code<\/li><li>Results<\/li><\/ul>\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>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 1) in Control Register 2 (CR2).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"345\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-1024x345.png\" alt=\"\" class=\"wp-image-229\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-1024x345.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-300x101.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-768x259.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-1536x518.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-1150x388.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-750x253.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-400x135.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM-250x84.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-29-at-10.29.54-AM.png 1762w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\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;}\">ADC1-&gt;CR2|=ADC_CR2_CONT;<\/pre><\/div>\n\n\n\n<p> Also, The SWSTART shall be set in the initialization function of the ADC.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Connection diagram:<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"948\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-1024x948.png\" alt=\"\" class=\"wp-image-563\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-1024x948.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-300x278.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-768x711.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-1536x1421.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-1150x1064.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-750x694.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-400x370.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM-250x231.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/11\/Screen-Shot-2021-11-11-at-7.21.34-AM.png 1662w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>The connection is as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Right leg of the pot to 3V3&nbsp;<\/li><li>Middle leg to A0 of Arduino connection (PA3)<\/li><li>Left leg to GND<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\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;stm32f7xx.h&quot;                  \/\/ Device header\n#define CH3 0x03\n\nuint16_t adc_data;\n\nint main(void)\n\t{\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_ADC1EN;\n\t\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODER3_0|GPIO_MODER_MODER3_1;\n\tADC1-&gt;SQR1=0;\n\tADC1-&gt;SQR3|=(CH3&lt;&lt;0);\n\tADC1-&gt;CR2|=ADC_CR2_CONT;\n\tADC1-&gt;CR2|=ADC_CR2_ADON;\n\tADC1-&gt;CR2|=ADC_CR2_SWSTART;\n\twhile(1)\n\t\t{\n\t\twhile(((ADC1-&gt;SR) &amp; ADC_SR_EOC) == 0);\n\t\tadc_data=ADC1-&gt;DR;\n\t\tfor (volatile int i=0;i&lt;10000;i++);\n\t\t}\n\t}\n\t<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p>After compiling the code, uploading the code to mcu, opening a debug session in keil uVision&nbsp;<\/p>\n\n\n\n<p>Rotate the potentiometer and observe the adc_data in watch window<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-1024x242.png\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-1024x242.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-300x71.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-768x181.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-1536x363.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-2048x484.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-1150x272.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-750x177.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-400x94.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.36-AM-250x59.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Potentiometer rotate Counter clockwise&nbsp;<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-1024x242.png\" alt=\"\" class=\"wp-image-217\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-1024x242.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-300x71.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-768x181.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-1536x363.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-2048x484.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-1150x272.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-750x177.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-400x94.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.57.42-AM-250x59.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding &#x1f60a;&#x1f60a;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look how to configure the ADC in STM32F7 for single channel single conversion. In this guide, we shall configure the ADC in continuous mode conversion. In this guide, we will cover the following: Difference between Single Conversion and Continuous Conversion. What extra steps needed to enable continuous [&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-581","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\/581"}],"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=581"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":583,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions\/583"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}