{"id":3300,"date":"2025-03-20T13:14:46","date_gmt":"2025-03-20T13:14:46","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3300"},"modified":"2025-03-20T13:15:45","modified_gmt":"2025-03-20T13:15:45","slug":"getting-started-with-stm32h5-arm-cortex-m33-i2c-in-dma-mode","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3300","title":{"rendered":"Getting Started with STM32H5 ARM Cortex M33:\u00a0I2C in DMA Mode"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1.webp\" alt=\"\" class=\"wp-image-3301\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-300x300.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-150x150.webp 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-768x768.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-750x750.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-400x400.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-06-15.14.04-A-highly-detailed-and-realistic-illustration-of-an-STM32H5-Nucleo-144-development-board-accurately-depicted-with-correct-pin-labels-and-layout.-The-bo-1-250x250.webp 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall see how to configure the I2C to work in DMA and transmit and receive data from a slave device (DS3231 RTC).<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Configure I2C to work in DMA.<\/li>\n\n\n\n<li>Develop the main code.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. Configure I2C to Work in DMA:<\/h2>\n\n\n\n<p>We shall continue from the previous guide from <a href=\"https:\/\/blog.embeddedexpert.io\/?p=3268\" data-type=\"link\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=3268\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Open i2c_fullduplex.ioc file as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"760\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-760x1024.jpg\" alt=\"\" class=\"wp-image-3302\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-760x1024.jpg 760w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-223x300.jpg 223w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-768x1034.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-750x1010.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-400x539.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35-250x337.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-41-35.jpg 946w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from connectivity, select I2C1, then NVIC setting as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"844\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-844x1024.jpg\" alt=\"\" class=\"wp-image-3304\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-844x1024.jpg 844w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-247x300.jpg 247w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-768x932.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-1266x1536.jpg 1266w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-1150x1396.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-750x910.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-400x485.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1-250x303.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-46-26-1.jpg 1480w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Enable I2C1 Event interrupt as shown.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from System Core, select GPDMA1, enable CH0 and CH1 in standard request mode as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"510\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-1024x510.jpg\" alt=\"\" class=\"wp-image-3305\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-1024x510.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-300x149.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-768x382.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-1536x764.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-1150x572.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-750x373.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-400x199.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13-250x124.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-48-13.jpg 1660w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, configure CH0 as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Request: I2C1_TX<\/li>\n\n\n\n<li>Direction: Memory to peripheral.<\/li>\n\n\n\n<li>From Source Data setting, enable Address Increment<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"543\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-543x1024.jpg\" alt=\"\" class=\"wp-image-3306\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-543x1024.jpg 543w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-159x300.jpg 159w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-768x1447.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-815x1536.jpg 815w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-1087x2048.jpg 1087w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-750x1413.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-400x754.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08-250x471.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-51-08.jpg 1092w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For CH1, configure it as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Request: I2C1_RX<\/li>\n\n\n\n<li>Direction: Peripheral to Memory<\/li>\n\n\n\n<li>From destination Data Setting, enable address increment.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"538\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-538x1024.jpg\" alt=\"\" class=\"wp-image-3307\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-538x1024.jpg 538w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-158x300.jpg 158w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-768x1463.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-806x1536.jpg 806w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-750x1429.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-400x762.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46-250x476.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_14-53-46.jpg 1050w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the configuration. Save the project. This will generate the code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Develop the Main Code:<\/h2>\n\n\n\n<p>Continue from the previous guide, in user code begin PV in main.c, add the following volatile variable to handle tx and rx communication completion 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;}\">volatile uint8_t txcompleted=0;\nvolatile uint8_t rxcompleted=0;<\/pre><\/div>\n\n\n\n<p>The reason behinds this since they shall be called in the interrupts, using volatile will let the compiler not to optimize the variable.<\/p>\n\n\n\n<p>Next, in user code begin 3 in while 1 loop:<\/p>\n\n\n\n<p>First, read from memory location using 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;}\"> HAL_I2C_Mem_Read_DMA(&amp;hi2c1, DS3231_Addr, 0x00, 0x01, rtc_data, 3);<\/pre><\/div>\n\n\n\n<p>The function takes the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Instant to the i2c which is hi2c1 in this case.<\/li>\n\n\n\n<li>I2C address which is DS3231_address (defined from the previous guide).<\/li>\n\n\n\n<li>Memory location which is 0x00 for the seconds.<\/li>\n\n\n\n<li>Buffer to hold the read data which is rtc_data (declared already from the previous guide).<\/li>\n\n\n\n<li>Size of the data to be read which is 3.<\/li>\n<\/ul>\n\n\n\n<p>Notice there is no timeout needed since this will be handled by the hardware.<\/p>\n\n\n\n<p>Wait until the read operation completed 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;}\"> while(rxcompleted==0);\n\t  rxcompleted=0;\n<\/pre><\/div>\n\n\n\n<p>Convert the BCD to decimal 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;}\">\t  for (int i=0;i&lt;3;i++)\n\t  {\n\t\t  rtc_data[i]=bcd_to_decimal(rtc_data[i]);\n\t  }<\/pre><\/div>\n\n\n\n<p>Print the RTC data:<\/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;}\">printf(&quot;RTC DATA H=%d M=%d S=%d\\r\\n&quot;,rtc_data[2],rtc_data[1],rtc_data[0]);<\/pre><\/div>\n\n\n\n<p>In case the seconds is 5, random the values of hours and minutes and set seconds to zero 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;}\">if(rtc_data[0]==5)\n\t  {\n\t\t  rtc_data[0]=0x00;\n\t\t  rtc_data[1]=(rand() % 5);\n\t\t  rtc_data[2]=(rand() % 5);<\/pre><\/div>\n\n\n\n<p>Then transmit the data using DMA and wait for tx to complete.<\/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  HAL_I2C_Mem_Write_DMA(&amp;hi2c1, DS3231_Addr, 0x00, 0x01, rtc_data, 3);\n\t\t  while(txcompleted==0);\n\t\t  txcompleted=0;<\/pre><\/div>\n\n\n\n<p>Finally, delay by 200ms 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;}\">HAL_Delay(200);<\/pre><\/div>\n\n\n\n<p>Hence, the while 1 loop 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;}\">\t  HAL_I2C_Mem_Read_DMA(&amp;hi2c1, DS3231_Addr, 0x00, 0x01, rtc_data, 3);\n\t  while(rxcompleted==0);\n\t  rxcompleted=0;\n\n\t  for (int i=0;i&lt;3;i++)\n\t  {\n\t\t  rtc_data[i]=bcd_to_decimal(rtc_data[i]);\n\t  }\n\t  printf(&quot;RTC DATA H=%d M=%d S=%d\\r\\n&quot;,rtc_data[2],rtc_data[1],rtc_data[0]);\n\t  if(rtc_data[0]==5)\n\t  {\n\t\t  rtc_data[0]=0x00;\n\t\t  rtc_data[1]=(rand() % 5);\n\t\t  rtc_data[2]=(rand() % 5);\n\t\t  HAL_I2C_Mem_Write_DMA(&amp;hi2c1, DS3231_Addr, 0x00, 0x01, rtc_data, 3);\n\t\t  while(txcompleted==0);\n\t\t  txcompleted=0;\n\t  }\n\n\t  HAL_Delay(200);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from drivers, STM32H5 drivers folder, src folder, open stm32h5xx_hal_i2c.c source file as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"567\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-1024x567.jpg\" alt=\"\" class=\"wp-image-3308\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-1024x567.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-300x166.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-768x426.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-1536x851.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-2048x1135.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-1150x637.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-750x416.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-400x222.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-20_15-10-31-250x139.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The following functions shall be called when HAL_I2C_Mem_Read_DMA and HAL_I2C_Write_DMA is called:<\/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 HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)<\/pre><\/div>\n\n\n\n<p>And<\/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 HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)<\/pre><\/div>\n\n\n\n<p>In case you are using normal read and write for the I2C, the following functions will be called:<\/p>\n\n\n\n<p>In case read using DMA:<\/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 HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)<\/pre><\/div>\n\n\n\n<p>In case write using DMA:<\/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 HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)<\/pre><\/div>\n\n\n\n<p>Hence, in main.c in user code begin 4, we shall handle the interrupt of Tx and Rx completed 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 HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)\n{\n\tif(hi2c-&gt;Instance ==I2C1)\n\t\trxcompleted=1;\n\n}\n\nvoid HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)\n{\n\tif(hi2c-&gt;Instance ==I2C1)\n\t\ttxcompleted=1;\n\n}<\/pre><\/div>\n\n\n\n<p>In the functions, we shall check which i2c has generated the interrupt which is i2c1 in this case.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the guide.<\/p>\n\n\n\n<p>Save the project, build it and run it on your STM32H563Zi board.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"28\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-1024x28.jpg\" alt=\"\" class=\"wp-image-3318\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-1024x28.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-300x8.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-768x21.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-1536x43.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-1150x32.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-750x21.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-400x11.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3-250x7.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-07-12_15-03-3-2-3.jpg 1734w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Results:<\/h2>\n\n\n\n<p>Open your favourite terminal applicaton, set the buadrate to be 115200 and you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"733\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-1024x733.jpg\" alt=\"\" class=\"wp-image-3320\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-1024x733.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-300x215.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-768x550.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-1150x823.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-750x537.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-400x286.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4-250x179.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2024-04-28_17-06-56-4.jpg 1168w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Note when second part becomes 5, new data for hours and minutes are written.<\/p>\n\n\n\n<p>Happy coding\u00a0\ud83d\ude09 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall see how to configure the I2C to work in DMA and transmit and receive data from a slave device (DS3231 RTC). In this guide, we shall cover the following: 1. Configure I2C to Work in DMA: We shall continue from the previous guide from here. Open i2c_fullduplex.ioc file as following: [&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-3300","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\/3300"}],"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=3300"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3300\/revisions"}],"predecessor-version":[{"id":3322,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3300\/revisions\/3322"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}