{"id":200,"date":"2021-07-26T08:02:18","date_gmt":"2021-07-26T08:02:18","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=200"},"modified":"2021-07-27T15:04:18","modified_gmt":"2021-07-27T15:04:18","slug":"working-with-adc-and-stm32-part1-single-channel-single-conversion","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=200","title":{"rendered":"Working with ADC and STM32 part1: Single Channel Single Conversion"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><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\" \/><figcaption>ADC Symbol<\/figcaption><\/figure>\n\n\n\n<p>In this guide, we shall learn how to use the ADC of the STM32 for single channel Single Conversion mode using only registers.<\/p>\n\n\n\n<p>The ADC is commonly used to measure the voltage from a sensor for example temperature sensor such as LM35 which can provide voltage proportional to the temperature.<\/p>\n\n\n\n<p>This guide will cover the following<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is the ADC<\/li><li>Required Parts<\/li><li>Schematic<\/li><li>Code<\/li><li>Results<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1.1 What is the ADC<\/h2>\n\n\n\n<p>In&nbsp;electronics, an&nbsp;<strong>analog-to-digital converter<\/strong>&nbsp;(<strong>ADC<\/strong>,&nbsp;<strong>A\/D<\/strong>, or&nbsp;<strong>A-to-D<\/strong>) is a system that converts an&nbsp;analog signal, such as a sound picked up by a&nbsp;microphone&nbsp;or light entering a&nbsp;digital camera, into a&nbsp;digital signal that can be read by STM32. <\/p>\n\n\n\n<p>ADCs can vary greatly between microcontroller. The ADC on the STM32F411 is a 12-bit ADC meaning it has the ability to detect 4096(2^12) discrete analog levels (which is also called <strong><em>Resolution<\/em><\/strong>). Some microcontrollers have 8-bit ADCs (2^8 = 256 discrete levels) and some have 16-bit ADCs (2^16 = 65,536 discrete levels).<\/p>\n\n\n\n<p>The way an ADC works is fairly complex. There are a few different ways to achieve this feat (see Wikipedia&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Analog-to-digital_converter#ADC_types\">for a list<\/a>), but one of the most common technique uses the analog voltage to charge up an internal capacitor and then measure the time it takes to discharge across an internal resistor. The microcontroller monitors the number of clock cycles that pass before the capacitor is discharged. This number of cycles is the number that is returned once the ADC is complete. Other methods used called Successive-approximation ADC which you can read about it in details from this wikipedia page (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Successive-approximation_ADC\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Successive-approximation_ADC\" target=\"_blank\" rel=\"noreferrer noopener\">Link<\/a>)<\/p>\n\n\n\n<p>For more information about how the adc of STM32F4 works, refer to the user manual (RM0383).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"relating-adc-value-to-voltage\">1.2 Relating ADC Value to Voltage<\/h2>\n\n\n\n<p>The ADC reports a\u00a0<em>ratio metric value<\/em>. This means that the ADC assumes 3.3V is 4095 and anything less than 3.3V will be a ratio between 3.3V and 4095.<\/p>\n\n\n\n<p>For example if the sensor has output voltage of 1.66V hence the ADC output will be (4095\/3.3)*1.66=2059.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.3 ADC registers needed in this guid<\/h2>\n\n\n\n<p>The registers of ADC in STM32F411 are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ADC_SR (Status Register).<\/li><li>ADC_CR1 (Control Register 1).<\/li><li>ADC_CR2 (Control Register 2).<\/li><li>ADC_SQ3 (Sequence 3).<\/li><li>ADC_DR (Data Register).<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2 Required Parts <\/h2>\n\n\n\n<p>You will need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>STM32F411 Nucleo-64<\/li><li>BreadBoard <\/li><li>1KOhm Potentiometer <\/li><li>Hookup wires (male-male)<\/li><\/ul>\n\n\n\n<p>We shall use Keil uVision (MDK-ARM) IDE (<a href=\"https:\/\/www.keil.com\/demo\/eval\/arm.htm\" data-type=\"URL\" data-id=\"https:\/\/www.keil.com\/demo\/eval\/arm.htm\" target=\"_blank\" rel=\"noreferrer noopener\">Link<\/a>)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3 Schematic<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"859\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-1024x859.png\" alt=\"\" class=\"wp-image-204\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-1024x859.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-300x252.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-768x645.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-1536x1289.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-1150x965.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-750x629.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-400x336.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM-250x210.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.26.07-AM.png 1804w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Connection Diagram<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-1024x768.jpg\" alt=\"\" class=\"wp-image-205\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-1024x768.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-300x225.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-768x576.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-1536x1152.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-2048x1536.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-1150x863.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-750x563.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-400x300.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/IMG_5941-250x188.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>actual connection<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4.1 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;}\">\/\/read the analog voltage on PA1\n\n#include &quot;stm32f4xx.h&quot;                  \/\/ Device header\n#include &quot;stdint.h&quot;\nvoid ADC_init(void);\nvoid delayMs(int delay);\nuint16_t adcValue;\n\nint main(void){\nADC_init();\n\n\t\nwhile(1){\nADC1-&gt;CR2|=ADC_CR2_SWSTART; \/\/start adc conversion\n\/\/wait for the end of conversion \nwhile(!((ADC1-&gt;SR)&amp;ADC_SR_EOC)){;}\nadcValue=ADC1-&gt;DR;\ndelayMs(10);\n}\n\n}\nvoid ADC_init(void){\nRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN; \/\/enable gpio a clock\nRCC-&gt;APB2ENR|=RCC_APB2ENR_ADC1EN; \/\/enable adc clock\nGPIOA-&gt;MODER|=GPIO_MODER_MODER1;  \/\/set the PA1 to analog mode\nADC1-&gt;CR2=0; \/\/disable the adc \t\nADC1-&gt;SQR3|=1; \nADC1-&gt;CR2|=1; \/\/enable the adc \t\n}\n\nvoid delayMs(int delay)\n{\nint i;\nfor(; delay&gt;0 ;delay--)\n{\nfor(i =0; i&lt;3195;i++);\n}\n\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">4.2 Code explanation <\/h2>\n\n\n\n<p>We are starting by including both the MCU header file and stdint.h<\/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;stm32f4xx.h&quot;                  \/\/ Device header\n#include &quot;stdint.h&quot;<\/pre><\/div>\n\n\n\n<p>We declare the prototype of the used 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;}\">void ADC_init(void);\nvoid delayMs(int delay);<\/pre><\/div>\n\n\n\n<p>then declaring the variable which will hold the ADC results as unsigned int with length of 16-bit (uint16_t) since the ADC is only 12-bit<\/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;}\">uint16_t adcValue;<\/pre><\/div>\n\n\n\n<p>int the main function we are initializing the ADC <\/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;}\">int main(void){\nADC_init();<\/pre><\/div>\n\n\n\n<p>then in the while loop we are start the conversion by setting bit named <strong><em>SWSTART<\/em><\/strong>  as seen in the register<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"204\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-1024x204.png\" alt=\"\" class=\"wp-image-209\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-1024x204.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-300x60.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-768x153.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-1536x306.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-2048x408.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-1150x229.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-750x150.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-400x80.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.41.31-AM-1-250x50.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>SWSTART location in ADC_CR2<\/figcaption><\/figure>\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_SWSTART; \/\/start adc conversion<\/pre><\/div>\n\n\n\n<p>then waiting for the end of conversion which is in ADC_SR register, store the result in adcValue and delay about 10 milliseconds between each read<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"2376\" height=\"692\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited.png\" alt=\"\" class=\"wp-image-211\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited.png 2376w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-300x87.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-1024x298.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-768x224.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-1536x447.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-2048x596.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-1150x335.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-750x218.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-400x116.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.43.02-AM-edited-250x73.png 250w\" sizes=\"(max-width: 2376px) 100vw, 2376px\" \/><\/figure>\n\n\n\n<p>EOC position in ADC_SR<\/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;}\">while(!((ADC1-&gt;SR)&amp;ADC_SR_EOC)){;}\nadcValue=ADC1-&gt;DR;\ndelayMs(10);\n}\n\n}<\/pre><\/div>\n\n\n\n<p>To initialize the ADC, the following is needed<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>enable clock access to GPIOA and ADC1 <\/li><li>Set GPIO_A1 as Analog Input.<\/li><li>Disable the ADC before configure the ADC<\/li><li>Set the PA1 as first in the sequence in SQ3 register <\/li><li>Enable the ADC  (bit0) (Refer to ADC_CR2 register from above)<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"219\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-1024x219.png\" alt=\"\" class=\"wp-image-214\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-1024x219.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-300x64.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-768x165.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-1536x329.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-2048x439.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-1150x246.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-750x161.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-400x86.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/07\/Screen-Shot-2021-07-26-at-10.51.28-AM-1-250x54.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Sequence of Conversion<\/figcaption><\/figure>\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 <\/p>\n\n\n\n<p>Rotate the potentiometer and observe the adcValue in watch window<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><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 <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><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\" \/><figcaption>Potentiometer rotate clockwise <\/figcaption><\/figure>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall learn how to use the ADC of the STM32 for single channel Single Conversion mode using only registers. The ADC is commonly used to measure the voltage from a sensor for example temperature sensor such as LM35 which can provide voltage proportional to the temperature. This guide will cover the [&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-200","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\/200"}],"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=200"}],"version-history":[{"count":9,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}