{"id":774,"date":"2022-02-18T18:24:54","date_gmt":"2022-02-18T18:24:54","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=774"},"modified":"2022-02-19T03:37:59","modified_gmt":"2022-02-19T03:37:59","slug":"working-with-stm32-and-displays-max7219-8-digit-7-segment-display","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=774","title":{"rendered":"Working with STM32 and displays: MAX7219 8-digit 7-segment display"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/static.wixstatic.com\/media\/8feff0_2e8f45ca9cbe4ea9be949e56769fc0b1~mv2.png\/v1\/fill\/w_1007,h_543,al_c\/8feff0_2e8f45ca9cbe4ea9be949e56769fc0b1~mv2.png\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall take a look at MAX7219 8-Digit LED Display Drivers and how to use them with 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>MAX7219<\/li><li>Connection with STM32<\/li><li>Code<\/li><li>Demo<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.1 MAX7219:<\/h2>\n\n\n\n<p>Unlike the 74HC595 shift register, we don\u2019t need to control each digit of 7-segment display individually by adding delay. We just send data 7-segments and seven-segment control data. It has a built-in BCD to 7-segment decoder. Most importantly, it has on-chip 8\u00d78 RAM which we can use to store display codes of digits that we want to display.<\/p>\n\n\n\n<p>One of the major advantages of this display driver is that we can update individual bits without updating the entire display that isn\u2019t possible with 74HC595 shift register. Hence, we can save microcontroller execution time and energy.<\/p>\n\n\n\n<p>Moreover, it has a built-in brightness control circuit and by using a scan limit register we can configure the number of digits display we want to use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.2 Pinout Diagram:<\/h2>\n\n\n\n<p>As you can depict from this pinout diagram that it is a 24 pin IC. Eight pins provide data to segments that A-G pins. DIG0 to DIG7 pins are used to connect with common pins of 8 common-cathode type seven-segment displays. The pin configuration is the same for both MAX7219 and MAX7212.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"921\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-1024x921.png\" alt=\"\" class=\"wp-image-775\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-1024x921.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-300x270.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-768x691.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-1536x1382.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-1150x1034.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-750x675.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-400x360.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM-250x225.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.24.46-PM.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This table shows the function of each pin. Out of 14 pins, 16 pins are used to connect 8-digit LED displays.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/microcontrollerslab.com\/wp-content\/uploads\/2020\/04\/MAX7219-pin-details.jpg?ezimgfmt=rs:767x404\/rscb1\/ngcb1\/notWebP\" alt=\"MAX7219 pin details\" class=\"wp-image-16871\" \/><\/figure>\n\n\n\n<p>According to the above table, MAX7219\/MAX7212 receives and transmits data through SPI communication. Pin1 (DIN) is a serial data input pin. We connect DIN of MAX7219 with a DOUT pin of PIC16F877A microcontroller SPI pin. Serial data transfer to an internal 16-bit register on every positive edge clock on pin13(Clk). We provide clock signals from Pic microcontroller SPI communication clock pin (SCK).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.3 MAX7219\/MAX7212 Registers:<\/h2>\n\n\n\n<p>This block diagram shows the configuration registers of MAX7219 LED driver IC. It has drivers for segements and digits.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/microcontrollerslab.com\/wp-content\/uploads\/2020\/04\/MAX7219-MAX7212-configuration-Registers.jpg?ezimgfmt=rs:754x484\/rscb1\/ngcb1\/notWebP\" alt=\"MAX7219 MAX7221configuration Registers\" class=\"wp-image-16875\" \/><\/figure>\n\n\n\n<p>Following are the main registers that used to configure and control display.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.4 Registers Map:<\/h2>\n\n\n\n<p>The following table shows the registers within the IC.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-889x1024.png\" alt=\"\" class=\"wp-image-776\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-889x1024.png 889w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-261x300.png 261w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-768x884.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-1334x1536.png 1334w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-1150x1324.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-750x863.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-400x461.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM-250x288.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.27.06-PM.png 1600w\" sizes=\"(max-width: 889px) 100vw, 889px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">1.5 Serial Data Format:<\/h2>\n\n\n\n<p>The data shall be sent in serial format with most significant bit (MSB) first to be transmit:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"117\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-1024x117.png\" alt=\"\" class=\"wp-image-777\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-1024x117.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-300x34.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-768x88.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-1536x176.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-2048x234.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-1150x131.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-750x86.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-400x46.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-18-at-5.28.54-PM-250x29.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connection with STM32:<\/h2>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td>MAX7219<\/td><td>STM32F411 Nucleo<\/td><\/tr><tr><td>Vcc<\/td><td>5V<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><tr><td>Din<\/td><td>MOSI (PA7)<\/td><\/tr><tr><td>SCK<\/td><td>SCK (PA7)<\/td><\/tr><tr><td>CS<\/td><td>PA9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. Code<\/h2>\n\n\n\n<p>We start off by configuring the SPI 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 spi_gpio_init(void)\n{\n\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;AHB1ENR |= GPIOAEN;\n\n\t\/*Set PA5,PA6,PA7 mode to alternate function*\/\n\n\t\/*PA5*\/\n\tGPIOA-&gt;MODER &amp;=~(1U&lt;&lt;10);\n\tGPIOA-&gt;MODER |=(1U&lt;&lt;11);\n\n\t\/*PA6*\/\n\tGPIOA-&gt;MODER &amp;=~(1U&lt;&lt;12);\n\tGPIOA-&gt;MODER |=(1U&lt;&lt;13);\n\n\t\/*PA7*\/\n\tGPIOA-&gt;MODER &amp;=~(1U&lt;&lt;14);\n\tGPIOA-&gt;MODER |=(1U&lt;&lt;15);\n\n\n\t\/*Set PA9 as output pin*\/\n\tGPIOA-&gt;MODER |=(1U&lt;&lt;18);\n\tGPIOA-&gt;MODER &amp;=~(1U&lt;&lt;19);\n\n\t\/*Set PA5,PA6,PA7 alternate function type to SPI1*\/\n\t\/*PA5*\/\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;20);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;21);\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;22);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;23);\n\n\t\/*PA6*\/\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;24);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;25);\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;26);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;27);\n\n\t\/*PA7*\/\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;28);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;29);\n\tGPIOA-&gt;AFR[0] |=(1U&lt;&lt;30);\n\tGPIOA-&gt;AFR[0] &amp;= ~(1U&lt;&lt;31);\n\n\n}\n\nvoid spi1_config(void)\n{\n\t\/*Enable clock access to SPI1 module*\/\n\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN; \/\/enable clock for spi1\n\n\tSPI1-&gt;CR2=0;\n\tSPI1-&gt;CR1=SPI_CR1_SSM|SPI_CR1_MSTR|SPI_CR1_SSI|SPI_CR1_SPE;\n}<\/pre><\/div>\n\n\n\n<p>SPI write function for multiple bytes 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 spi1_transmit(uint8_t *data,uint32_t size)\n{\n\n\tuint32_t i=0;\n\tuint8_t temp;\n\n\twhile(i&lt;size)\n\t{\n\t\t\/*Wait until TXE is set*\/\n\t\twhile(!(SPI1-&gt;SR &amp; (SR_TXE))){}\n\n\t\t\/*Write the data to the data register*\/\n\t\tSPI1-&gt;DR = data[i];\n\t\ti++;\n\t}\n\t\/*Wait until TXE is set*\/\n\twhile(!(SPI1-&gt;SR &amp; (SR_TXE))){}\n\n\t\/*Wait for BUSY flag to reset*\/\n\twhile((SPI1-&gt;SR &amp; (SR_BSY))){}\n\n\t\/*Clear OVR flag*\/\n\ttemp = SPI1-&gt;DR;\n\ttemp = SPI1-&gt;SR;\n\n}<\/pre><\/div>\n\n\n\n<p>Chip enable disable function :<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void cs_enable(void)\n{\n\tGPIOA-&gt;ODR &amp;=~(1U&lt;&lt;9);\n\n}\n\n\/*Pull high to disable*\/\nvoid cs_disable(void)\n{\n\tGPIOA-&gt;ODR |=(1U&lt;&lt;9);\n}\n<\/pre><\/div>\n\n\n\n<p>Now for MAX7219, we can need to initialize the IC first 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 max7219_init(void)\n\t\t{\n\t\tspi_gpio_init();\n\t\tspi1_config();\n\t\tuint8_t data[2];\n\t\t  \/\/ Run test\n\t\t\t\/\/ All LED segments should light up\t\n\t\tdata[0]=0x0F;\n\t\tdata[1]=0x01;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\tcs_disable();\n\t\tfor (volatile int i=0;i&lt;100000;i++){}\n\t\tdata[0]=0x0F;\n\t\tdata[1]=0x00;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\tcs_disable();\n\t\t\/\/ Enable mode B\n\t\tdata[0]=0x09;\n\t\tdata[1]=0xFF;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\tcs_disable();\n\t\t \/\/ Use lowest intensity\n\t\tdata[0]=0x0A;\n\t\tdata[1]=0x0F;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\tcs_disable();\n\t \/\/  scan all digit\n\t\tdata[0]=0x0B;\n\t\tdata[1]=0x07;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\tcs_disable();\n\t\t\/\/ Turn on chip\n\t\tdata[0]=0x0C;\n\t\tdata[1]=0x01;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n\t\t\n\t\tcs_disable();\n\t\t\/\/ clear display \n\t\tfor (int i=0;i&lt;9;i++)\n\t\t\t\t\t{\n\t\t\t\t\tdisplay_number(i,0x0f);\n\t\t\t\t\t}\n\n\t\t}\n<\/pre><\/div>\n\n\n\n<p>For displaying single number on single digit, we can use the 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  display_number (uint8_t digit, uint8_t number)\n\t\t\t{\n\t\t\t\n\t\tuint8_t data[2];\n\t\tdata[0]=digit; data[1]=number;\n\t\tcs_enable();\n\t\tspi1_transmit(data,2);\n   \tcs_disable();\n  }\t\n<\/pre><\/div>\n\n\n\n<p>For clearing the display:<\/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 clear_display(void)\n\t\t{\n\t\t\t\n\t\tfor (int i=0;i&lt;9;i++)\n\t\t\t\t\t{\n\t\t\t\t\tdisplay_number(i,0x0f);\n\t\t\t\t\t}\n\t\t\n\t\t}\n\t\t\t<\/pre><\/div>\n\n\n\n<p>Now, in main file, we can call the initializing function and start display numbers 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;}\">#include &quot;max7219.h&quot;\n\n\nint main(void)\n\t{\n\tfor(volatile int i=0;i&lt;100000;i++){}\n\t\tmax7219_init();\n\tfor(volatile int i=0;i&lt;100000;i++){}\n\t\twhile(1)\n\t\t\t{\n\t\t\tfor (int i=0;i&lt;9;i++)\n\t\t\t\t{\n\t\t\t\t\tfor (int j=0;j&lt;10;j++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdisplay_number(i,j);\n\t\t\t\t\t\t\tfor (volatile int k=0;k&lt;200000;k++){}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\tfor (volatile int k=0;k&lt;200000;k++){}\n\t\t\tclear_display();\n\t\t\t\t\n\t\t\t\t}\n\t\t\n\t}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You can download the source code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/MAX7219_8-digit.zip\">MAX7219_8-digit<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/MAX7219_8-digit.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\">4. Demo:<\/h2>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7922.mp4\"><\/video><\/figure>\n\n\n\n<p>Happy coding :<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall take a look at MAX7219 8-Digit LED Display Drivers and how to use them with STM32. In this guide, we shall cover the following: MAX7219 Connection with STM32 Code Demo 1.1 MAX7219: Unlike the 74HC595 shift register, we don\u2019t need to control each digit of 7-segment display individually by adding [&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-774","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\/774"}],"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=774"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/774\/revisions"}],"predecessor-version":[{"id":782,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/774\/revisions\/782"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}