{"id":858,"date":"2022-03-29T16:13:20","date_gmt":"2022-03-29T16:13:20","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=858"},"modified":"2022-03-29T16:13:23","modified_gmt":"2022-03-29T16:13:23","slug":"working-with-adc-and-stm32-part-5-timer-triggered-with-dma","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=858","title":{"rendered":"Working with ADC and STM32 part 5: Timer triggered with DMA"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/08\/1200px-ADC_Symbol.svg_.png\" alt=\"\" \/><\/figure>\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=319\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=319\" target=\"_blank\">here<\/a>), we took a look at the ADC in continuous mode with DMA. In that guide, we used the ADC to trigger freely. In this guide, we shall use timer to trigger the adc to convert the channel(s).<\/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>ADC Configuration for timer trigger and DMA.<\/li><li>Configure the DMA.<\/li><li>Configure the timer.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Configuring the ADC for timer trigger and DMA:<\/h2>\n\n\n\n<p>In order to configure the ADC, we need to configure some bits in CR2:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"305\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-1024x305.png\" alt=\"\" class=\"wp-image-859\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-1024x305.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-300x89.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-768x229.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-1536x457.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-2048x610.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-1150x342.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-750x223.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-400x119.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.50.32-PM-250x74.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We need to set the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>EXTEN to rising edge.<\/li><li>EXTSEL to be Timer 2 TRGO event<\/li><li>DDS and DMA.<\/li><\/ul>\n\n\n\n<p>Hence the ADC configuration as following:<\/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;}\">\/*ADC related set up*\/\n\tRCC-&gt;AHB1ENR\t\t|=RCC_AHB1ENR_GPIOAEN;\n\tRCC-&gt;APB2ENR\t\t|=RCC_APB2ENR_ADC1EN;\n\tGPIOA-&gt;MODER\t\t|=GPIO_MODER_MODE0_0|GPIO_MODER_MODE0_1;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_DMA|ADC_CR2_DDS;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_EXTEN_0;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_EXTSEL_1|ADC_CR2_EXTSEL_2;<\/pre><\/div>\n\n\n\n<p>Note: Don&#8217;t start the ADC yet.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.Configure the DMA:<\/h2>\n\n\n\n<p>Before we configure the DMA, we need to check which  channel and stream is needed:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-1024x557.png\" alt=\"\" class=\"wp-image-860\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-1024x557.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-300x163.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-768x418.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-1536x836.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-2048x1115.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-1150x626.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-750x408.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-400x218.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.56.02-PM-250x136.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We have stream0 and stream4. In this guide, we shall use stream0.<\/p>\n\n\n\n<p>In order to configure the DMA we need to set the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"213\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-1024x213.png\" alt=\"\" class=\"wp-image-861\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-1024x213.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-300x62.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-768x159.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-1536x319.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-2048x425.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-1150x239.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-750x156.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-400x83.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-6.57.50-PM-250x52.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Channel to 0.<\/li><li>Memory and peripheral sizes to 16-bit (half-word).<\/li><li>Set memory increment.<\/li><li>Set the mode to be circular.<\/li><li>Direction to be peripheral to memory.<\/li><li>Transfer complete interrupt.<\/li><\/ul>\n\n\n\n<p>Hence the configuration code as following:<\/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;}\">\tRCC-&gt;AHB1ENR\t\t|=RCC_AHB1ENR_DMA2EN;\n\tDMA2_Stream0-&gt;CR\t&amp;=~DMA_SxCR_EN;\n\twhile(DMA2_Stream0-&gt;CR ==DMA_SxCR_EN){;}\n\tDMA2_Stream0-&gt;CR\t|=DMA_SxCR_MSIZE_0|DMA_SxCR_PSIZE_0|DMA_SxCR_MINC|DMA_SxCR_TCIE|DMA_SxCR_CIRC;\n\tDMA2_Stream0-&gt;PAR\t =(uint32_t)(&amp;(ADC1-&gt;DR));\n\tDMA2_Stream0-&gt;M0AR \t =(uint32_t )(adc_data);\n\tDMA2_Stream0-&gt;NDTR\t =10;\n\tNVIC_EnableIRQ(DMA2_Stream0_IRQn);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Timer configuration:<\/h2>\n\n\n\n<p>Since we are using timer2, we need to configure to The update event is selected as trigger output (TRGO) as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"213\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-1024x213.png\" alt=\"\" class=\"wp-image-862\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-1024x213.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-300x62.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-768x159.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-1536x319.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-2048x425.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-1150x239.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-750x156.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-400x83.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.05.05-PM-250x52.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;}\">\/* Timer related setup*\/\n\tRCC-&gt;APB1ENR\t\t|=RCC_APB1ENR_TIM2EN;\n\tTIM2-&gt;PSC\t\t\t =16000-1;\n\tTIM2-&gt;ARR\t\t\t =10-1;\n\tTIM2-&gt;CR2\t\t\t|=TIM_CR2_MMS_1;<\/pre><\/div>\n\n\n\n<p>Finally, we launch the peripheral in this following order:<\/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;}\">\/*Launch the ADC*\/\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_ADON;\n\t\/*Launch the DMA*\/\n\tDMA2_Stream0-&gt;CR \t|=DMA_SxCR_EN;\n\t\/*Launch the timer*\/\n\tTIM2-&gt;CR1\t\t\t|=TIM_CR1_CEN;<\/pre><\/div>\n\n\n\n<p>In the main loop, we wait until the transfer in completed:<\/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(1)\n\t{\n\t\tif(finished==1)\n\t\t\t{\n\t\t\tfinished=0;\n\t\t\tprintf(&quot;adc values=\\r\\n&quot;);\n\t\t\tfor (int i=0;i&lt;10;i++)\n\t\t\t\t{\n\t\t\t\tprintf(&quot;adc_data[%d]=%d\\r\\n&quot;,i,adc_data[i]);\n\t\t\t\t}\n\t\t\tprintf(&quot;----------------------------\\r\\n&quot;);\n\n\t\t\t}\n\n\n\t}\n<\/pre><\/div>\n\n\n\n<p>Finally interrupt handler for the DMA as following:<\/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 DMA2_Stream0_IRQHandler(void)\n\t\t{\n\n\t\tif(((DMA2-&gt;LISR)&amp;DMA_LISR_TCIF0))\n\t\t\t\t{\n\t\t\t\tfinished=1;\n\t\t\t\tDMA2-&gt;LIFCR=DMA_LIFCR_CTCIF0;\n\t\t\t\t}\n\t\tNVIC_ClearPendingIRQ(DMA2_Stream0_IRQn);\n\t\t}<\/pre><\/div>\n\n\n\n<p>Here, we are retargeting printf to be used with SWO (from <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=800\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=800\" target=\"_blank\">here<\/a>).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>The entire code as following:<\/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;stdio.h&quot;\nuint16_t adc_data[10];\nvolatile uint8_t finished=0;\nint main(void)\n{\n\t\/*ADC related set up*\/\n\tRCC-&gt;AHB1ENR\t\t|=RCC_AHB1ENR_GPIOAEN;\n\tRCC-&gt;APB2ENR\t\t|=RCC_APB2ENR_ADC1EN;\n\tGPIOA-&gt;MODER\t\t|=GPIO_MODER_MODE0_0|GPIO_MODER_MODE0_1;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_DMA|ADC_CR2_DDS;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_EXTEN_0;\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_EXTSEL_1|ADC_CR2_EXTSEL_2;\n\n\t\/*DMA related setup*\/\n\tRCC-&gt;AHB1ENR\t\t|=RCC_AHB1ENR_DMA2EN;\n\tDMA2_Stream0-&gt;CR\t&amp;=~DMA_SxCR_EN;\n\twhile(DMA2_Stream0-&gt;CR ==DMA_SxCR_EN){;}\n\tDMA2_Stream0-&gt;CR\t|=DMA_SxCR_MSIZE_0|DMA_SxCR_PSIZE_0|DMA_SxCR_MINC|DMA_SxCR_TCIE|DMA_SxCR_CIRC;\n\tDMA2_Stream0-&gt;PAR\t =(uint32_t)(&amp;(ADC1-&gt;DR));\n\tDMA2_Stream0-&gt;M0AR \t =(uint32_t )(adc_data);\n\tDMA2_Stream0-&gt;NDTR\t =10;\n\tNVIC_EnableIRQ(DMA2_Stream0_IRQn);\n\n\t\/* Timer related setup*\/\n\tRCC-&gt;APB1ENR\t\t|=RCC_APB1ENR_TIM2EN;\n\tTIM2-&gt;PSC\t\t\t =16000-1;\n\tTIM2-&gt;ARR\t\t\t =10-1;\n\tTIM2-&gt;CR2\t\t\t|=TIM_CR2_MMS_1;\n\t\/*Launch the ADC*\/\n\tADC1-&gt;CR2\t\t\t|=ADC_CR2_ADON;\n\t\/*Launch the DMA*\/\n\tDMA2_Stream0-&gt;CR \t|=DMA_SxCR_EN;\n\t\/*Launch the timer*\/\n\tTIM2-&gt;CR1\t\t\t|=TIM_CR1_CEN;\n\nwhile(1)\n\t{\n\t\tif(finished==1)\n\t\t\t{\n\t\t\tfinished=0;\n\t\t\tprintf(&quot;adc values=\\r\\n&quot;);\n\t\t\tfor (int i=0;i&lt;10;i++)\n\t\t\t\t{\n\t\t\t\tprintf(&quot;adc_data[%d]=%d\\r\\n&quot;,i,adc_data[i]);\n\t\t\t\t}\n\t\t\tprintf(&quot;----------------------------\\r\\n&quot;);\n\n\t\t\t}\n\t}\n\n}\n\n\nvoid DMA2_Stream0_IRQHandler(void)\n\t\t{\n\n\t\tif(((DMA2-&gt;LISR)&amp;DMA_LISR_TCIF0))\n\t\t\t\t{\n\t\t\t\tfinished=1;\n\t\t\t\tDMA2-&gt;LIFCR=DMA_LIFCR_CTCIF0;\n\t\t\t\t}\n\t\tNVIC_ClearPendingIRQ(DMA2_Stream0_IRQn);\n\t\t}\n\nint __io_putchar(int ch)\n\t{\n\t ITM_SendChar(ch);\n\treturn ch;\n\t}\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Result:<\/h2>\n\n\n\n<p>When you run the code and open new Serial Wire Viewer window, you should get the following results:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-1024x557.png\" alt=\"\" class=\"wp-image-863\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-1024x557.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-300x163.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-768x418.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-1536x836.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-1150x626.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-750x408.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-400x218.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM-250x136.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-7.12.05-PM.png 1566w\" 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 the ADC in continuous mode with DMA. In that guide, we used the ADC to trigger freely. In this guide, we shall use timer to trigger the adc to convert the channel(s). In this guide, we shall cover the following: ADC Configuration for timer trigger [&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-858","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\/858"}],"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=858"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/858\/revisions"}],"predecessor-version":[{"id":864,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/858\/revisions\/864"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}