{"id":1822,"date":"2023-06-14T13:30:30","date_gmt":"2023-06-14T13:30:30","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1822"},"modified":"2023-06-14T13:30:33","modified_gmt":"2023-06-14T13:30:33","slug":"working-with-stm32-and-hm10-ble-part-1-environment-and-connection-setup","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1822","title":{"rendered":"Working with STM32 and HM10 BLE Part 1: Environment and connection setup"},"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-1024x1024.jpg\" alt=\"\" class=\"wp-image-1823\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-1024x1024.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-300x300.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-150x150.jpg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-768x768.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-750x750.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-400x400.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL-250x250.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/61vKZjfcnqL.jpg 1100w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In this two part series guide, we shall interface HM10 BLE module with STM32 and control an LED and send string from STM32.<\/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>What is HM-10.<\/li><li>Connection.<\/li><li>UART setup.<\/li><li>LED Setup.<\/li><li>Time base setup.<\/li><li>code.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is HM-10:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>The\u00a0<strong>HM-10<\/strong>\u00a0is a readily available\u00a0<strong>Bluetooth 4.0 module<\/strong>\u00a0used for establishing wireless data communication. The module is designed by using the Texas Instruments CC2540 or CC2541\u00a0<strong>Bluetooth low energy<\/strong>\u00a0(BLE) System on Chip (SoC) but design and firmware originated from the Jinan Huamao Technology Company.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"732\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-1024x732.png\" alt=\"\" class=\"wp-image-1824\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-1024x732.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-300x214.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-768x549.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-1150x822.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-750x536.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-400x286.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM-250x179.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-4.15.42-PM.png 1422w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>HM-10 Pinout Configuration<\/strong><\/h3>\n\n\n\n<p>HM-10 is a 34-pin module. In them most are not compulsory use pins. We only need four pins of all 34 to establish a communication. We will describe the function of each pin below.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Pin Number<\/strong><\/td><td><strong>Pin Name<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>1<\/td><td>UART_TX<\/td><td>UART interface-Transmit<\/td><\/tr><tr><td>2<\/td><td>UART_RX<\/td><td>UART interface-Receive<\/td><\/tr><tr><td>3<\/td><td>UART_CTS<\/td><td>UART interface<\/td><\/tr><tr><td>4<\/td><td>UART_RTS<\/td><td>UART interface<\/td><\/tr><tr><td>5<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>6<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>7<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>8<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>9<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>10<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>11<\/td><td>RESETB<\/td><td>Reset if low for 100ms<\/td><\/tr><tr><td>12<\/td><td>VCC<\/td><td>3.3V<\/td><\/tr><tr><td>13<\/td><td>GND<\/td><td>Ground<\/td><\/tr><tr><td>14<\/td><td>GND<\/td><td>Ground<\/td><\/tr><tr><td>15<\/td><td>USB_D-<\/td><td>USB interface<\/td><\/tr><tr><td>16<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>17<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>18<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>19<\/td><td>NC<\/td><td>No Connection<\/td><\/tr><tr><td>20<\/td><td>USB_D+<\/td><td>USB interface<\/td><\/tr><tr><td>21<\/td><td>GND<\/td><td>Ground<\/td><\/tr><tr><td>22<\/td><td>GND<\/td><td>Ground<\/td><\/tr><tr><td>23<\/td><td>PIO0<\/td><td>System Key<\/td><\/tr><tr><td>24<\/td><td>PIO1<\/td><td>System LED<\/td><\/tr><tr><td>25<\/td><td>PIO2<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>26<\/td><td>PIO3<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>27<\/td><td>PIO4<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>28<\/td><td>PIO5<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>29<\/td><td>PIO6<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>30<\/td><td>PIO7<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>31<\/td><td>PIO8<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>32<\/td><td>PIO9<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>33<\/td><td>PIO10<\/td><td>Programmable input\/output line<\/td><\/tr><tr><td>34<\/td><td>PIO11<\/td><td>Programmable input\/output line<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>HM-10 Module Features<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>BT Version: Bluetooth Specification V4.0<\/li><li>BLE chip &#8211;\u00a0 Bluetooth Low Energy consumption<\/li><li>Send and receive no bytes limit.<\/li><li>Working frequency: 2.4GHz ISM band<\/li><li>UART Serial Interface<\/li><li>Full-Speed USB Interface<\/li><li>12 General Purpose Input\/output Pins<\/li><li>In-System-Programmable Flash- 128 KB or 256KB<\/li><li>8-KB SRAM<\/li><li>32-kHz Sleep Timer With Capture<\/li><li>Long range: Open space have 100 Meters<\/li><li>Potable size<\/li><li>HM-10 MODULE Specifications<\/li><li>Operating\u00a0 voltage of \u00a0MODULE: 2.0V \u2013 3.6V<\/li><li>Can operate on LOW voltages<\/li><li>Consumes 235uA on battery backup<\/li><li>Input RF level: 10dBm<\/li><li>Maximum voltage: + 3.9V<\/li><li>Operating temperature: -40\u00baC to +85\u00baC<\/li><li>ESD: 750V<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>For more information, please refer to the datasheet from <a href=\"https:\/\/people.ece.cornell.edu\/land\/courses\/ece4760\/PIC32\/uart\/HM10\/DSD%20TECH%20HM-10%20datasheet.pdf\" data-type=\"URL\" data-id=\"https:\/\/people.ece.cornell.edu\/land\/courses\/ece4760\/PIC32\/uart\/HM10\/DSD%20TECH%20HM-10%20datasheet.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connection:<\/h2>\n\n\n\n<p>In this guide, we need sing STM32F4 and single HC-12 module in order to make communication between iPhone and STM32:<\/p>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"931\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-1024x931.png\" alt=\"\" class=\"wp-image-1825\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-1024x931.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-300x273.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-768x698.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-1536x1397.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-1150x1046.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-750x682.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-400x364.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM-250x227.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-14-at-3.56.37-PM.png 2006w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>STM32F44<\/td><td>HM-10 Module<\/td><\/tr><tr><td>5V<\/td><td>Vcc<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><tr><td>PA9 (UART1_TX)<\/td><td>RX<\/td><\/tr><tr><td>PA10(UART1_RX)<\/td><td>TX<\/td><\/tr><tr><td>PA0<\/td><td>Key<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. UART setup:<\/h2>\n\n\n\n<p>We start off by creating new source and header file with name of hm10_uart.c and hm10_uart.h respectively.<\/p>\n\n\n\n<p>Te utilitized UART is UART1 which will receive data using interrupt:<\/p>\n\n\n\n<p>To see how to setup UART from scratch and everything related to it, please refer to&nbsp;<a href=\"https:\/\/blog.embeddedexpert.io\/?p=347\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a>&nbsp;topic.<\/p>\n\n\n\n<p>Within 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;}\">#ifndef HM_10_UART_H_\n#define HM_10_UART_H_\n\n#include &quot;stdint.h&quot;\n\nvoid hm10_uart_init(uint32_t baud,uint32_t freq);\n\nvoid hm10_write_char(unsigned char ch);\n\nvoid hm10_write_at_command(unsigned char * ch);\n\nvoid hm10_write_string(unsigned char * ch);\n\n\n#endif \/* HM_10_UART_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Within source 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 &lt;hm_10_uart.h&gt;\n#include &quot;stm32f4xx.h&quot;\n\n\n#define AF07 0x07\n\n\nstatic void uart_set_baudrate(USART_TypeDef *USARTx, uint32_t PeriphClk,  uint32_t BaudRate);\n\n\nvoid hm10_uart_init(uint32_t baud,uint32_t freq)\n{\n\t\/*Enable clock access to GPIOA and USART1*\/\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_USART1EN;\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\t\/*Configure the GPIO for UART Mode*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_0;\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE10_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE10_0;\n\tGPIOA-&gt;AFR[1]|=(AF07&lt;&lt;GPIO_AFRH_AFSEL9_Pos)|(AF07&lt;&lt;GPIO_AFRH_AFSEL10_Pos); \/\/ALT7 for UART1 (PA9 and PA10)\n\t\/*Configure UART*\/\n\tuart_set_baudrate(USART1,freq,baud);\n\tUSART1-&gt;CR1|=USART_CR1_TE|USART_CR1_RE;\n\tUSART1-&gt;CR1|=USART_CR1_RXNEIE;\n\tNVIC_EnableIRQ(USART1_IRQn);\n\tUSART1-&gt;CR1|=USART_CR1_UE;\n}\n\nstatic uint16_t compute_uart_bd(uint32_t PeriphClk, uint32_t BaudRate)\n{\n\treturn ((PeriphClk + (BaudRate\/2U))\/BaudRate);\n}\n\nstatic void uart_set_baudrate(USART_TypeDef *USARTx, uint32_t PeriphClk,  uint32_t BaudRate)\n{\n\tUSARTx-&gt;BRR =  compute_uart_bd(PeriphClk,BaudRate);\n}\n\n\nvoid hm10_write_char(unsigned char ch)\n{\n\t\/*Make sure the transmit data register is empty*\/\n\twhile(!(USART1-&gt;SR &amp; USART_SR_TXE)){}\n\n\t\/*Write to transmit data register*\/\n\tUSART1-&gt;DR  =  (ch &amp; 0xFF);\n}\n\n\nvoid hm10_write_at_command(unsigned char * ch)\n{\n\twhile(*ch)\n\t{\n\t\thc12_write_char(*ch);\n\t\tch++;\n\t}\n}\n\nvoid hm10_write_string(unsigned char * ch)\n{\n\twhile(*ch)\n\t{\n\t\thc12_write_char(*ch);\n\t\tch++;\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. LED Setup:<\/h2>\n\n\n\n<p>Since the built-in LED is connected to PA5, we need to configure PA5 as output:<\/p>\n\n\n\n<p>For more details, please refer to&nbsp;<a href=\"https:\/\/blog.embeddedexpert.io\/?p=246\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a>&nbsp;topic.<\/p>\n\n\n\n<p>create new source and header file with name of led.c and led.h respectively.<\/p>\n\n\n\n<p>Within header file:<\/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;}\">#ifndef LED_H_\n#define LED_H_\n\nvoid led_init(void);\nvoid led_on(void);\nvoid led_off(void);\nvoid led_toggle(void);\n\n\n#endif \/* LED_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Within source code:<\/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;led.h&quot;\n#include &quot;stm32f4xx.h&quot;\n\n\nvoid led_init(void)\n{\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE5_0;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE5_1;\n\n}\n\nvoid led_on(void)\n{\n\tGPIOA-&gt;BSRR=GPIO_BSRR_BS5;\n}\n\nvoid led_off(void)\n{\n\tGPIOA-&gt;BSRR=GPIO_BSRR_BR5;\n}\n\nvoid led_toggle(void)\n{\n\tGPIOA-&gt;ODR^=GPIO_ODR_OD5;\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Time Base setup:<\/h2>\n\n\n\n<p>To see how to implement time base from scratch, please refer to&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1644\" target=\"_blank\">this<\/a>&nbsp;topic.<\/p>\n\n\n\n<p>Within the header file:<\/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;}\">#ifndef TIME_BASE_H_\n#define TIME_BASE_H_\n\n#include &quot;stdint.h&quot;\n\nvoid Ticks_Init(uint32_t freq);\nuint32_t get_Ticks();\nvoid delay(uint32_t delay_ms);\n\n\n\n\n#endif \/* TIME_BASE_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Within source 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;time_base.h&quot;\n\n#include &quot;stm32f4xx.h&quot;\n\n\nvolatile uint32_t current_ticks;\n\nvoid Ticks_Init(uint32_t freq)\n{\n\t\/*Load the SysTick value to be the core frequency over 1000\n\t *\n\t * Since th core frequency is in MHz, dividing it by 1000 will get 1ms period\n\t * *\/\n\tSysTick-&gt;LOAD=(freq\/1000)-1;\n\n\t\/*Set the source to be internal core clock*\/\n\tSysTick-&gt;CTRL=(1&lt;&lt;SysTick_CTRL_CLKSOURCE_Pos);\n\n\t\/*Enable The interrupt *\/\n\n\tSysTick-&gt;CTRL|=(1&lt;&lt;SysTick_CTRL_TICKINT_Pos);\n\n\t\/*Enable Systick Interrupt in NIVC*\/\n\n\tNVIC_EnableIRQ(SysTick_IRQn);\n\n\t\/*Enable Systick*\/\n\tSysTick-&gt;CTRL|=(1&lt;&lt;SysTick_CTRL_ENABLE_Pos);\n\n\n}\n\nvoid SysTick_Handler()\n{\n\t\/*Increment the counter*\/\n\tcurrent_ticks++;\n}\n\nuint32_t get_Ticks()\n{\n\t\/*Return the counter value*\/\n\treturn current_ticks;\n}\n\n\/*Spin lock the CPU to force delay*\/\nvoid delay(uint32_t delay_ms)\n{\n\n\tuint32_t ticks_start=get_Ticks();\n\n\twhile(get_Ticks()-ticks_start&lt;delay_ms);\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Code:<\/h2>\n\n\n\n<p>You may download the setup environment based on STM32CubeIDE 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.zip\">HM10_STM32<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/HM10_STM32.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In part two, we shall control the LED and send string from STM32 to iPhone\/Android.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this two part series guide, we shall interface HM10 BLE module with STM32 and control an LED and send string from STM32. In this guide, we shall cover the following: What is HM-10. Connection. UART setup. LED Setup. Time base setup. code. 1. What is HM-10: The\u00a0HM-10\u00a0is a readily available\u00a0Bluetooth 4.0 module\u00a0used for establishing [&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-1822","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\/1822"}],"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=1822"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1822\/revisions"}],"predecessor-version":[{"id":1827,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1822\/revisions\/1827"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}