{"id":1829,"date":"2023-06-17T13:37:26","date_gmt":"2023-06-17T13:37:26","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1829"},"modified":"2023-06-17T13:37:26","modified_gmt":"2023-06-17T13:37:26","slug":"working-with-stm32-and-hm10-ble-part-2-full-duplex-communication","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1829","title":{"rendered":"Working with STM32 and HM10 BLE Part 2: Full Duplex Communication"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-1024x1024.jpg\" alt=\"\" class=\"wp-image-1830\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-1024x1024.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-300x300.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-150x150.jpg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-768x768.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-750x750.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-400x400.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1-250x250.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1.jpg 1100w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the previous guid (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1822\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1822\" target=\"_blank\">here<\/a>), we took a look at HM-10 module and how to connect it to STM32F4. In this guide, we shall use this module in full duplex to control LED and send strings from STM32F4 to a phone.<\/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>Library development.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Library development:<\/h2>\n\n\n\n<p>We start off by creating new source and header file with name of hm_10.c and hm_10.h respectively.<\/p>\n\n\n\n<p>Within the header file, include header guard: <\/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;}\">#ifndef HM_10_H_\n#define HM_10_H_\n\n\n#endif \/* HM_10_H_ *\/<\/pre><\/div>\n\n\n\n<p>Declare the following enums which handle the baudrate:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"418\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-1024x418.png\" alt=\"\" class=\"wp-image-1831\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-1024x418.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-300x123.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-768x314.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-1150x470.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-750x306.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-400x163.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM-250x102.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.13.47-PM.png 1454w\" 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;}\">typedef enum\n{\n\tBuad9600=0,\n\tBuad19200=1,\n\tBaud38400=2,\n\tBaud57666=3,\n\tBaud115200=4\n\n}HM10_BuadRate_Typedef;<\/pre><\/div>\n\n\n\n<p>Another enum to handle role as master or slave:<\/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=\"373\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-1024x373.png\" alt=\"\" class=\"wp-image-1832\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-1024x373.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-300x109.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-768x280.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-1536x560.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-1150x419.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-750x273.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-400x146.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM-250x91.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.15.12-PM.png 1706w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In my case (0 means slave and 1 means master):<\/p>\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;}\">typedef enum\n{\n\tSlave=0,\n\tMaster=1\n\n}HM10_Role_Typedef;\n\n<\/pre><\/div>\n\n\n\n<p>Also, set of functions that needed:<\/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 setBuadRate(HM10_BuadRate_Typedef baud);\n\nvoid setRole(HM10_Role_Typedef role);\n\nvoid setName(char *c);\n\nvoid FactoryReset();\n\nvoid moduleReset();\n<\/pre><\/div>\n\n\n\n<p>Hence, the header file 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;}\">#ifndef HM_10_H_\n#define HM_10_H_\n\n#include &quot;stdint.h&quot;\n\ntypedef enum\n{\n\tBuad9600=0,\n\tBuad19200=1,\n\tBaud38400=2,\n\tBaud57666=3,\n\tBaud115200=4\n\n}HM10_BuadRate_Typedef;\n\n\ntypedef enum\n{\n\tSlave=0,\n\tMaster=1\n\n}HM10_Role_Typedef;\n\n\n\nvoid setBuadRate(HM10_BuadRate_Typedef baud);\n\nvoid setRole(HM10_Role_Typedef role);\n\nvoid setName(char *c);\n\nvoid FactoryReset();\n\nvoid moduleReset();\n\n\n#endif \/* HM_10_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Now, in the source code, include the following header files:<\/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;hm_10.h&quot;\n#include &quot;hm_10_uart.h&quot;\n#include &quot;stdio.h&quot;\n#include &quot;led.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare a character array to handle the AT command:<\/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;}\">static char AT_Array[20];<\/pre><\/div>\n\n\n\n<p>Volatile variable to store the incoming data from UART:<\/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 char uart1_rec;<\/pre><\/div>\n\n\n\n<p>Set buadrate function will take the enum of buadrate as argument:<\/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 setBuadRate(HM10_BuadRate_Typedef baud)\n{\n\n\tsprintf(AT_Array,&quot;AT+BAUD%d\\r\\n&quot;,baud);\n\thm10_write_at_command(AT_Array);\n}<\/pre><\/div>\n\n\n\n<p>By sending for example (AT_BAUD0), it will set the buadrate to 9600.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>To set the role function, it will take role enum as argument:<\/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 setRole(HM10_Role_Typedef role)\n{\n\tsprintf(AT_Array,&quot;AT+ROLE%d\\r\\n&quot;,role);\n\thm10_write_at_command(AT_Array);\n}\n<\/pre><\/div>\n\n\n\n<p>Set name function will set the name of the module and takes string as argument:<\/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 setName(char *c)\n{\n\tsprintf(AT_Array,&quot;AT+NAME%s\\r\\n&quot;,c);\n\thm10_write_at_command(AT_Array);\n}<\/pre><\/div>\n\n\n\n<p>To factory reset the module (default state):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"232\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-1024x232.png\" alt=\"\" class=\"wp-image-1833\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-1024x232.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-300x68.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-768x174.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-1536x348.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-1150x260.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-750x170.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-400x91.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM-250x57.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.22.28-PM.png 1706w\" 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;}\">void FactoryReset()\n{\n\tsprintf(AT_Array,&quot;AT+RENEW\\r\\n&quot;);\n\thm10_write_at_command(AT_Array);\n}<\/pre><\/div>\n\n\n\n<p>To restart the module (exit AT mode):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"232\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-1024x232.png\" alt=\"\" class=\"wp-image-1835\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-1024x232.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-300x68.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-768x174.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-1536x348.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-1150x260.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-750x170.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-400x91.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1-250x57.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-17-at-4.23.24-PM-1.png 1706w\" 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;}\">\nvoid moduleReset()\n{\n\tsprintf(AT_Array,&quot;AT+RESET\\r\\n&quot;);\n\thm10_write_at_command(AT_Array);\n}\n<\/pre><\/div>\n\n\n\n<p>Since the UART is used in interrupt mode to receive the character, we shall declare a callback function as weak:<\/p>\n\n\n\n<p>Declaring a function as weak it, you can override it in another source file without any issue:<\/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 HC_12_Callback(unsigned char ch)\n{\n\tif (ch == '1')\n\t{\n\t\tled_toggle();\n\t}\n}\n\nvoid USART1_IRQHandler (void)\n{\n\n\tif(USART1-&gt;SR &amp; USART_SR_RXNE){\n\tuart1_rec=USART1-&gt;DR;\n\tHC_12_Callback(uart1_rec);\n\n\tUSART1-&gt;SR &amp;= ~USART_SR_RXNE;}\n\n\n}\n<\/pre><\/div>\n\n\n\n<p>In the 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;hm_10_uart.h&quot;\n#include &quot;led.h&quot;\n#include &quot;time_base.h&quot;\n#include &quot;exti.h&quot;\n#include &quot;hm_10.h&quot;\n\nuint32_t previousTicks;\n\n\nint main()\n{\n\n\tTicks_Init(16000000);\n\tPC13_EXTI_Init();\n\tled_init();\n\thm10_uart_init(9600,16000000);\n\tFactoryReset();\n\tdelay(100);\n\tmoduleReset();\n\tdelay(100);\n\n\twhile(1)\n\t{\n\t\tif(get_Ticks()-previousTicks&gt;=1000)\n\t\t{\n\n\t\t\thm10_write_string(&quot;Hello from STM32F411RE Nucleo-64\\r\\n&quot;);\n\t\t\tpreviousTicks=get_Ticks();\n\t\t}\n\t}\n\n\n}\n\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. Code:<\/h2>\n\n\n\n<p>You may download the code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/HM10_STM32-1.zip\">HM10_STM32-1<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/HM10_STM32-1.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. Results:<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-provider-youtube wp-block-embed-youtube\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"HM-10 BLE interface with STM32F4\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/FnBAwJOSAhk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guid (here), we took a look at HM-10 module and how to connect it to STM32F4. In this guide, we shall use this module in full duplex to control LED and send strings from STM32F4 to a phone. In this guide, we shall cover the following: Library development. Code. Results. 7. Library [&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-1829","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\/1829"}],"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=1829"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1829\/revisions"}],"predecessor-version":[{"id":1838,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1829\/revisions\/1838"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}