{"id":4361,"date":"2018-08-08T20:00:48","date_gmt":"2018-08-08T18:00:48","guid":{"rendered":"https:\/\/msalamon.pl\/?p=4361"},"modified":"2025-12-27T20:37:15","modified_gmt":"2025-12-27T19:37:15","slug":"16x2-lcd-display-on-stm32-hal-part-2","status":"publish","type":"post","link":"https:\/\/msalamon.pl\/en\/16x2-lcd-display-on-stm32-hal-part-2\/","title":{"rendered":"16\u00d72 LCD Display on STM32 + HAL, Part 2"},"content":{"rendered":"\n<p>In the last <a href=\"http:\/\/msalamon.pl\/wyswietlacz-lcd-16x2-na-stm32-hal-cz-1\/\">&gt;&gt;part&lt;&lt;<\/a> I examined the refresh time of a 16\u00d72 LCD on STM32 using a 4-bit communication bus and a predetermined wait time for processing the supplied data. Today I will check how reading<\/p>\n\n\n\n<!--more-->\n\n\n\n<p> the so-called busy flag by the MCU will affect the refresh time. Let&#8217;s go!<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/sklep.msalamon.pl\/produkt\/lcd-2x16-znakow\/?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=lcd16x2&amp;utm_content=Text\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-1024x341.jpg\" alt=\"\" class=\"wp-image-957\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-1024x341.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-300x100.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-768x256.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-24x8.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-36x12.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner-160x53.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/09\/HD44780_baner.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">4-bit bus with busy flag checking<\/h1>\n\n\n\n<p>To read the <em>busy flag<\/em> from the display controller, I need to modify the wiring and the code. The modifications I made are:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\n<ol class=\"wp-block-list\">\n<li>Pin no. 5, i.e., <em>RW<\/em>, will this time be connected to the STM32, which will control the direction of data flow on the bus. Thanks to this, it will be possible to read data from the LCD.<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Changing the direction of the <em>GPIO<\/em> dedicated to communication with the display \u201con the fly\u201d. The library is supposed to do this by itself.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"369\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_.png\" alt=\"\" class=\"wp-image-138\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_-300x115.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_-768x295.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_-24x9.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_-36x14.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_KiCad_5V_-160x62.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>I will configure the GPIO for pins LCD_DB4\u2026LCD_DB7 as <em>Input<\/em> or <em>Output<\/em> in the way suggested by STM32CubeMX. I have also appropriately modified the transmit and receive functions.<\/p>\n\n\n\n<p>As a base I will use <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/nucleo-f401re\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=bmp180&amp;utm_content=Text\">Nucleo<\/a><a href=\"https:\/\/sklep.msalamon.pl\/produkt\/nucleo-f401re\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=lcd16x2&amp;utm_content=Text\"> F401RE.<\/a><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/sklep.msalamon.pl\/kategoria-produktu\/dev-boardy\/stm32-nucleo\/?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=lcd16x2&amp;utm_content=nucleo\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"400\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner.jpg\" alt=\"\" class=\"wp-image-1593\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner.jpg 1200w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-300x100.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-1024x341.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-768x256.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube.png\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube.png\" alt=\"\" class=\"wp-image-137\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube.png 600w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube-300x300.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube-150x150.png 150w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube-24x24.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube-36x36.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4bit_z_RW_Cube-80x80.png 80w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">static void LCD_DataOut()\n{\n\tGPIO_InitTypeDef GPIO_InitStruct;\n\n\tGPIO_InitStruct.Pin = LCD_DB4_Pin|LCD_DB5_Pin|LCD_DB6_Pin|LCD_DB7_Pin;\n\tGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n\tGPIO_InitStruct.Pull = GPIO_NOPULL;\n\tGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n\tHAL_GPIO_Init(GPIOB, &amp;amp;GPIO_InitStruct);\n}\n\nstatic void LCD_DataIn()\n{\n\tGPIO_InitTypeDef GPIO_InitStruct;\n\n\tGPIO_InitStruct.Pin = LCD_DB4_Pin|LCD_DB5_Pin|LCD_DB6_Pin|LCD_DB7_Pin;\n\tGPIO_InitStruct.Mode = GPIO_MODE_INPUT;\n\tGPIO_InitStruct.Pull = GPIO_NOPULL;\n\tHAL_GPIO_Init(GPIOB, &amp;amp;GPIO_InitStruct);\n}\n\n\/\/\n\/\/ Write byte to LCD\n\/\/\nuint8_t LCD_ReadByte(void)\n{\n\tuint8_t result = 0;\n\tLCD_DataIn();\n\n\tSET_LCD_RW;\n\n\tSET_LCD_E;\n\tresult = (LCD_GetDataPort() &amp;lt;&amp;lt; 4);\n\tRESET_LCD_E;\n\n\tSET_LCD_E;\n\tresult |= LCD_GetDataPort();\n\tRESET_LCD_E;\n\n\treturn result;\n}\n\n\/\/\n\/\/ Check Busy Flag\n\/\/\nuint8_t LCD_CheckBusyFlag()\n{\n\tRESET_LCD_RS;\n\treturn LCD_ReadByte();\n}\n\n\/\/\n\/\/ Write byte to LCD\n\/\/\nvoid LCD_WriteByte(uint8_t data)\n{\n\tLCD_DataOut();\n\n\tRESET_LCD_RW;\n\n\tSET_LCD_E;\n\tLCD_SetDataPort(data &amp;gt;&amp;gt; 4);\n\tRESET_LCD_E;\n\n\tSET_LCD_E;\n\tLCD_SetDataPort(data);\n\tRESET_LCD_E;\n\n\t\/\/ HAL_Delay(1);\n\t\/\/ Delay_us(120); \/\/ Wait for data processing\n\twhile((LCD_CheckBusyFlag() &amp;amp; (1&amp;lt;&amp;lt;7))); \/\/ Wait for data processing\n}<\/pre>\n\n\n\n<p>I run the code and\u2026 WOW! Although the microcontroller performs a ton of operations on the pins, the frame refresh time was only 2,74 ms! Is this speed worth one GPIO pin? I think in many cases definitely yes.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"298\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us.png\" alt=\"\" class=\"wp-image-136\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us-300x93.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us-768x238.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us-24x7.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us-36x11.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/4-bit_z_RW_TIM_Delay_us-160x50.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Or maybe I can shave off a bit more? The LCD controller offers up to an 8-bit communication bus width. I will check whether doubling the amount of data sent at once will halve the frame refresh time. First I will check without reading the busy flag.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8-bit bus without busy flag checking<\/h2>\n\n\n\n<p>Due to the hopelessly long refresh time I achieved using only the <em>delay<\/em> functions built into STM32HAL, I will skip considering this method for 8-bit. I will perform measurements only using a function operating on a <em>timer<\/em>.<\/p>\n\n\n\n<p>I start by connecting the remaining 4 lines, i.e., LCD_DB0\u2026LCD_DB3.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"360\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V.png\" alt=\"\" class=\"wp-image-139\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V-300x113.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V-768x288.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V-24x9.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V-36x14.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_KiCad_5V-160x60.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The code modification consists of assigning new functions to the appropriate pins in STM32CubeMX<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_.png\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"620\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_.png\" alt=\"\" class=\"wp-image-141\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_.png 600w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_-290x300.png 290w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_-24x24.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_-36x36.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_Cube_-77x80.png 77w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u2026and modifying the code for the wider bus. The functions related to setting the GPIO pins, sending one byte of data, and the display initialization function change, which now sets the LCD controller to 8-bit mode.<\/p>\n\n\n\n<p>The time obtained is nothing special. Basically, almost nothing got shorter compared to the 4-bit version. The whole frame transferred in 7,11 ms.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"323\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_.png\" alt=\"\" class=\"wp-image-144\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_-300x101.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_-768x258.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_-24x8.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_-36x12.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_bez_RW_TIM_Delay_us_-160x54.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8-bit bus with busy flag checking<\/h2>\n\n\n\n<p>For the 4-bit mode, replacing <em>delays<\/em> with reading LCD busyness worked brilliantly \u2013 the time decreased significantly. I will check whether for 8-bit the result will be equally spectacular.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"360\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V.png\" alt=\"\" class=\"wp-image-145\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V-300x113.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V-768x288.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V-24x9.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V-36x14.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_KiCad_5V-160x60.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_.png\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"620\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_.png\" alt=\"\" class=\"wp-image-142\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_.png 600w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_-290x300.png 290w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_-24x24.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_-36x36.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_Cube_-77x80.png 77w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>I rework the code and\u2026 to be honest, I expected something better \ud83d\ude41 In this way I got 2,74 ms, i.e., exactly the same result as with the 4-bit mode.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"332\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us.png\" alt=\"\" class=\"wp-image-146\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us.png 960w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us-300x104.png 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us-768x266.png 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us-24x8.png 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us-36x12.png 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2018\/07\/8bit_z_RW_TIM_Delay_us-160x55.png 160w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Further optimization?<\/h2>\n\n\n\n<p>You can still replace the HAL functions for controlling <em>GPIO<\/em> with direct register operations. Is it worth going further down this road? Probably not. It should be possible to shave off maybe 0,2 ms, because the time to set <em>GPIO<\/em> unfortunately has a negligible effect \u2013 the waiting time for the LCD controller is definitely greater, and I won\u2019t shorten that.<\/p>\n\n\n\n<p>Looking at the waveforms you can also infer quite an interesting thing. Namely, the first 1,5 ms at the beginning of the transfer is spent clearing the display. With busy-flag handling, this is more than half the time needed to display two full lines! Maybe that\u2019s where to try to bite? For example, instead of sending the clear command, write spaces, hmm? Or send a pre-prepared complete buffer from the microcontroller\u2019s RAM? There are many ways to buffer and in the future a thread on this topic will certainly appear on the blog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>I\u2019ve reached the end \ud83d\ude42 I examined all 4 possible ways of communicating with a popular LCD display with a controller compatible with HD44780 using the STM32F401RE microcontroller. The research results are presented in the table below.<\/p>\n\n\n\n<figure class=\"wp-block-table tablepress tablepress-id-1\"><table class=\"has-fixed-layout\"><thead><tr><th>Mode<\/th><th>Time<\/th><\/tr><\/thead><tbody><tr><td>4-bit HAL_Delay<\/td><td>67,29 ms<\/td><\/tr><tr><td>4-bit without BF<\/td><td>7,14 ms<\/td><\/tr><tr><td>4-bit with BF<\/td><td>2,74 ms<\/td><\/tr><tr><td>8-bit without BF<\/td><td>7,11 ms<\/td><\/tr><tr><td>8-bit with BF<\/td><td>2,74 ms<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Which mode to use? You can immediately reject the method using the built-in <em>HAL_Delay<\/em>. This time is definitely unacceptable! Don\u2019t waste your life, I don\u2019t recommend it.<\/p>\n\n\n\n<p>Comparing the two 4-bit modes shows how big an impact reading the busy flag has. You don\u2019t have to guess when the controller is ready to accept data, lengthening the whole procedure. Reducing the time by more than 2.5x costs only one <em>GPIO<\/em> pin. This time can be very valuable in a more complex project.<\/p>\n\n\n\n<p>And what about 8 bits? Smoke and mirrors. The results are almost identical to those with a data bus that\u2019s twice as narrow. What does this mean? You can completely skip this mode when using alphanumeric displays. Entering 8-bit mode is a waste of four valuable microcontroller pins.<\/p>\n\n\n\n<p>If you like the display, you can buy it in various variants <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/lcd-2x16-znakow\/\">in my store<\/a>.<\/p>\n\n\n\n<p>The test code along with the library can be found on my GitHUB: <a href=\"https:\/\/github.com\/lamik\/HD44780_STM32_HAL\" target=\"_blank\" rel=\"noopener\">link<\/a><\/p>\n\n\n\n<p>In the end, I encourage you to discuss in the comments the handling of the LCD display on STM32. Do you think I made a mistake somewhere? Do you have an interesting idea on what can be improved? Share it in the comments! Remember that the discussion should be polite and in accordance with the rules of the Polish language.<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;4361&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;0&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;16\u00d72 LCD Display on STM32 + HAL, Part 2&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the last &gt;&gt;part&lt;&lt; I examined the refresh time of a 16\u00d72 LCD on STM32 using a 4-bit communication bus and a predetermined wait time for processing the supplied data. Today I will check how reading<\/p>\n","protected":false},"author":1,"featured_media":2932,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[160],"tags":[175,176,174,177],"class_list":["post-4361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stm32","tag-electronics","tag-programming","tag-stm32","tag-stm32cubemx"],"_links":{"self":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/comments?post=4361"}],"version-history":[{"count":3,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4361\/revisions"}],"predecessor-version":[{"id":4472,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4361\/revisions\/4472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/media\/2932"}],"wp:attachment":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/media?parent=4361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/categories?post=4361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/tags?post=4361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}