{"id":2588,"date":"2024-06-14T05:13:14","date_gmt":"2024-06-14T05:13:14","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2588"},"modified":"2024-06-14T05:13:17","modified_gmt":"2024-06-14T05:13:17","slug":"working-with-stm32-and-i2s-part-3-sending-data-using-dma","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2588","title":{"rendered":"Working with STM32 and I2S Part 3: Sending Data using DMA"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"150\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Inter-IC-Sound-1.jpg\" alt=\"\" class=\"wp-image-2589\" \/><\/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=2567\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2567\" target=\"_blank\">here<\/a>), we took a look how to configure the I2S and transmit data using poling mode. In this guide, we shall use DMA to transfer data over I2S bus.<\/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>I2S Configuration.<\/li><li>DMA Configuration.<\/li><li>Sending Data over DMA.<\/li><li>Interrupt handler.<\/li><li>Main code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">12. I2S Configuration:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Within I2S_init function in I2S.c source file, before enabling the I2S, enable TX using DMA as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"243\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-1024x243.jpg\" alt=\"\" class=\"wp-image-2590\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-1024x243.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-300x71.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-768x183.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-1536x365.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-2048x487.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-1150x273.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-750x178.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-400x95.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-03-33-250x59.jpg 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;}\">\t\/*Enable SPI_TX_DMA*\/\n\tSPI3-&gt;CR2|=SPI_CR2_TXDMAEN;<\/pre><\/div>\n\n\n\n<p>Enable SPI3 interrupt in NVIC (will need it later):<\/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;}\">\t\/*Enable SPI3 interrupt in NVIC*\/\n\tNVIC_EnableIRQ(SPI3_IRQn);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">13. DMA Configuration:<\/h2>\n\n\n\n<p>After enabling the interrupt for SPI3, we shall configure the DMA, first we need to know which DMA and Stream is related to SPI3_TX, from the DMA1 request mapping, we can find the following:<\/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=\"421\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-1024x421.jpg\" alt=\"\" class=\"wp-image-2591\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-1024x421.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-300x123.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-768x316.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-1536x631.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-1150x473.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-750x308.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-400x164.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20-250x103.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-13_17-04-20.jpg 1912w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>We have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>DMA1 is needed.<\/li><li>Either Stream5 or Stream7 can be used.<\/li><li>Channel 0.<\/li><\/ul>\n\n\n\n<p>Hence, we start by enable clock access to DMA1 as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>From the block diagram, we can find that DMA1 is connected to AHB1 bus.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"620\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-1024x620.jpg\" alt=\"\" class=\"wp-image-2592\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-1024x620.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-300x182.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-768x465.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-1536x931.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-1150x697.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-750x454.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-400x242.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20-250x151.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-47-20.jpg 1644w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, we can enable the clock access to DMA1 as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"427\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-1024x427.jpg\" alt=\"\" class=\"wp-image-2593\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-1024x427.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-300x125.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-768x320.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-1536x640.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-2048x853.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-1150x479.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-750x312.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-400x167.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-48-16-250x104.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\/*Enable Clock Access to DMA1*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_DMA1EN;<\/pre><\/div>\n\n\n\n<p>Configure the DMA with the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Channel is channel 0.<\/li><li>Memory increment mode.<\/li><li>Direction is Memory to peripheral.<\/li><li>Enable transfer complete interrupt.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"361\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1024x361.jpg\" alt=\"\" class=\"wp-image-2594\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1024x361.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-300x106.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-768x271.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1536x542.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-2048x722.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1150x405.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-750x264.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-400x141.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-250x88.jpg 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;}\">\tDMA1_Stream7-&gt;CR|=(0x00&lt;&lt;DMA_SxCR_CHSEL_Pos)|DMA_SxCR_MINC|DMA_SxCR_DIR_0|DMA_SxCR_TCIE;<\/pre><\/div>\n\n\n\n<p>Enable DMA1_Stream7 in the NVIC:<\/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;}\">\t\/*Enable DMA1_Steam5 Interrupt in nVIC*\/\n\tNVIC_EnableIRQ(DMA1_Stream7_IRQn);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">14. Sending Data using DMA:<\/h2>\n\n\n\n<p>We start by declaring the following 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 I2S_SendData_DMA(uint16_t *data, uint16_t len)<\/pre><\/div>\n\n\n\n<p>The function takes two parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Point to the buffer that contains the data to be send.<\/li><li>Length of the data to be transmitted.<\/li><\/ul>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>Set the peripheral address of the DMA to be SPI3-&gt;DR as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"333\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-1024x333.jpg\" alt=\"\" class=\"wp-image-2595\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-1024x333.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-300x98.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-768x250.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-1536x500.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-2048x667.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-1150x374.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-750x244.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-400x130.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-56-43-250x81.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\/*Set Peripheral address to SPI3-&gt;DR*\/\n\tDMA1_Stream7-&gt;PAR=(uint32_t)&amp;SPI3-&gt;DR;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Set Memory address to be the buffer passed by the user:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"339\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-1024x339.jpg\" alt=\"\" class=\"wp-image-2596\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-1024x339.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-300x99.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-768x254.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-1536x508.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-2048x677.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-1150x380.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-750x248.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-400x132.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-57-49-250x83.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\/*Set the memory address*\/\n\tDMA1_Stream7-&gt;M0AR=(uint32_t)data;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Set number of transfer to be the length passed by the user:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"331\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-1024x331.png\" alt=\"\" class=\"wp-image-2597\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-1024x331.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-300x97.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-768x248.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-1536x496.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-2048x662.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-1150x372.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-750x242.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-400x129.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-14-at-7.58.53\u202fAM-250x81.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;}\">\t\/*Set the length*\/\n\tDMA1_Stream7-&gt;NDTR=len;<\/pre><\/div>\n\n\n\n<p>Launch the DMA:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"361\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-1024x361.jpg\" alt=\"\" class=\"wp-image-2598\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-1024x361.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-300x106.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-768x271.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-1536x542.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-2048x722.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-1150x405.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-750x264.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-400x141.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_07-52-41-1-250x88.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\/*Launch the DMA*\/\n\tDMA1_Stream7-&gt;CR|=DMA_SxCR_EN;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">15. Interrupt Handler :<\/h2>\n\n\n\n<p>For the interrupt handler of the DMA:<\/p>\n\n\n\n<p>Declare this 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 DMA1_Stream7_IRQHandler(void)<\/pre><\/div>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>Check if the source of the interrupt is transfer complete:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"469\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-1024x469.jpg\" alt=\"\" class=\"wp-image-2602\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-1024x469.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-300x137.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-768x352.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-1536x703.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-1150x526.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-750x343.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-400x183.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1-250x114.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-03-52-1.jpg 1962w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\/*Check the Intrrupt source of DMA1_Stream7*\/\n\tif((DMA1-&gt;HISR &amp; DMA_HISR_TCIF7) ==DMA_HISR_TCIF7 )<\/pre><\/div>\n\n\n\n<p>Within the if condition, enable SPI_TX buffer is empty interrupt:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"199\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-1024x199.jpg\" alt=\"\" class=\"wp-image-2603\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-1024x199.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-300x58.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-768x149.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-1536x298.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-2048x398.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-1150x223.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-750x146.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-400x78.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-05-45-250x49.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\t\/*Enable SPI Tx buffer empty interrupt*\/\n\t\tSPI3-&gt;CR2|=SPI_CR2_TXEIE;<\/pre><\/div>\n\n\n\n<p>Clear the pending flag of the DMA:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"303\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-1024x303.jpg\" alt=\"\" class=\"wp-image-2601\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-1024x303.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-300x89.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-768x227.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-1536x454.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-1150x340.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-750x222.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-400x118.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28-250x74.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-04-28.jpg 1726w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">\t\t\/*Clear Pending flag*\/\n\t\tDMA1-&gt;HIFCR=DMA_HIFCR_CTCIF7;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Declare the following 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;}\">__WEAK void SPI3_DMA_TX_Completed(void)\n{\n\n}<\/pre><\/div>\n\n\n\n<p>This function shall be overwritten by the user in his application.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>For the SPI interrupt handler:<\/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 SPI3_IRQHandler(void)<\/pre><\/div>\n\n\n\n<p>Check if TX buffer is empty and it is not busy:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"259\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-1024x259.jpg\" alt=\"\" class=\"wp-image-2604\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-1024x259.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-300x76.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-768x194.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-1536x389.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-2048x518.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-1150x291.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-750x190.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-400x101.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/2024-06-14_08-08-24-250x63.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/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;}\">if ((SPI3-&gt;SR &amp; SPI_SR_TXE) &amp;&amp; ((SPI3-&gt;SR &amp; SPI_SR_BSY)==0))<\/pre><\/div>\n\n\n\n<p>Call the weak 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;}\">\t\t\/*Call SPi3_DMA_TX_Completed function*\/\n\t\tSPI3_DMA_TX_Completed();<\/pre><\/div>\n\n\n\n<p>Disable TX buffer interrupt empty:<\/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;}\">\t\t\/*Disable SPI Tx Buffer empty interrupt*\/\n\t\tSPI3-&gt;CR2&amp;=~SPI_CR2_TXEIE;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Finally, add the following function in the header file:<\/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 I2S_SendData_DMA(uint16_t *data, uint16_t len);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">16. Main Code:<\/h2>\n\n\n\n<p>In main.c file:<\/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;delay.h&quot;\n#include &quot;stdlib.h&quot;\n#include &quot;i2s.h&quot;\n\n#define dataSize 10\nuint16_t data[dataSize] = {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999, 0xAAAA};\n\nvolatile uint8_t I2S_Finished=0;\n\n\nint main(void)\n{\n\tdelay_init(168000000);\n\tI2S3_Pins_Init();\n\tI2S3_Init();\n\n\n\twhile(1)\n\t{\n\t\tI2S_SendData_DMA(data, dataSize);\n\t\twhile(I2S_Finished==0);\n\t\tI2S_Finished=0;\n\t\tdelay(10);\n\t}\n\n\n}\n\nvoid SPI3_DMA_TX_Completed(void)\n{\n\tI2S_Finished=1;\n\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">17. Results:<\/h2>\n\n\n\n<p>By connecting logic analyzer to the clock, data and word select, you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"182\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-1024x182.png\" alt=\"\" class=\"wp-image-2582\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-1024x182.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-300x53.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-768x136.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-1536x272.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-2048x363.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-1150x204.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-750x133.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-400x71.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-06-at-8.17.43\u202fAM-250x44.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Since have successfully transmitted data over I2S bus.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, we shall configure CS43L22 to generate some audio.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look how to configure the I2S and transmit data using poling mode. In this guide, we shall use DMA to transfer data over I2S bus. In this guide, we shall cover the following: I2S Configuration. DMA Configuration. Sending Data over DMA. Interrupt handler. Main code. Results. 12. [&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-2588","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\/2588"}],"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=2588"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2588\/revisions"}],"predecessor-version":[{"id":2606,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2588\/revisions\/2606"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}