{"id":14685,"date":"2023-05-15T11:55:23","date_gmt":"2023-05-15T06:25:23","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=14685"},"modified":"2023-08-17T10:55:28","modified_gmt":"2023-08-17T05:25:28","slug":"stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/","title":{"rendered":"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 28| SPI peripheral configuration coding"},"content":{"rendered":"<div class=\"boldgrid-section color4-background-color color-4-text-contrast bg-background-color\">\n<div class=\"container\">\n<div class=\"row\">\n<div class=\"col-lg-1 col-md-12 col-sm-12 col-xs-12\"><\/div>\n<div class=\"col-lg-10 col-md-12 col-xs-12 col-sm-12\">\n<p class=\"\">&nbsp;<\/p>\n<h1 class=\"\" style=\"text-align: center; font-size: 35px; line-height: 50px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>SPI peripheral configuration coding<\/b><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<div class=\"bg-hr bg-hr-16 color2-color\" style=\"border-style: solid; border-width: 0px 0px 2px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let&#8217;s do the SPI_Init function.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here we do a microcontroller SPI configuration for controller mode.<\/span><\/p>\n<figure id=\"attachment_14688\" aria-describedby=\"caption-attachment-14688\" style=\"width: 735px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-14688 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-1-4.png\" alt=\"Figure 1. SPI peripheral configuration code\" width=\"735\" height=\"355\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-4.png 1219w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-4-300x145.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-4-1024x495.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-4-768x371.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-4-600x290.png 600w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><figcaption id=\"caption-attachment-14688\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. SPI peripheral configuration code<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The code provided shows the initialization and configuration of the SPI (Serial Peripheral Interface) peripheral on a microcontroller, as shown in Figure 1.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">To begin, we need to activate the peripheral clock for the SPI. The first step is to call the function LCD_SPI_Enable(), which sets the SPE (SPI Enable) bit in the CR1 (Control Register 1) of the SPI peripheral. This function doesn&#8217;t require any arguments, but it uses a pointer to the SPI peripheral, which we declare as pSPI. Here&#8217;s how the function looks:<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>void LCD_SPI_Enable(void) <\/b><b>{&nbsp;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>SPI_TypeDef *pSPI = SPI;&nbsp;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, SPI_CR1_SPE_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>}<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This function is called to enable the SPI peripheral for communication with an LCD controller.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">The second function, <\/span><span style=\"font-weight: 400;\">LCD_SPI_Init()<\/span><span style=\"font-weight: 400;\">, initializes and configures the SPI peripheral.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>SPI_TypeDef *pSPI = SPI;&nbsp;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>RCC_TypeDef *pRCC = RCC;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">These two lines define pointers to the SPI and RCC (Reset and Clock Control) peripheral registers.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The following code lines configure the SPI peripheral. Firstly, the SPI clock is enabled by setting the SPI5EN bit in the AHB2ENR (Advanced High-Performance Bus 2 Enable Register) of the RCC (Reset and Clock Control) peripheral. To do this, it is necessary to locate the SPI5 peripheral on the memory map and determine which bus domain it belongs to. To find this information, refer to the reference manual and navigate to the memory map. It can be observed that in our microcontroller, the SPI5 peripheral is part of the APB2 bus domain.<\/span><\/p>\n<figure id=\"attachment_14689\" aria-describedby=\"caption-attachment-14689\" style=\"width: 703px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14689 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-2-4.png\" alt=\"Figure 2. Memory map \" width=\"703\" height=\"240\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-4.png 1333w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-4-300x102.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-4-1024x350.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-4-768x262.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-4-600x205.png 600w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><figcaption id=\"caption-attachment-14689\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Memory map<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pRCC-&gt; AHB2ENR, RCC_APB2ENR_SPI5EN_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line sets a bit in the AHB2ENR register of the RCC peripheral to enable the clock for the SPI5 peripheral (this register is used to enable the clock to different peripherals).<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s check the SPI registers in the reference manual.<\/span><\/p>\n<figure id=\"attachment_14690\" aria-describedby=\"caption-attachment-14690\" style=\"width: 757px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14690 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-3-4.png\" alt=\"Figure 3. SPI register\" width=\"757\" height=\"402\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-4.png 1487w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-4-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-4-1024x543.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-4-768x407.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-4-600x318.png 600w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><figcaption id=\"caption-attachment-14690\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. SPI register<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s start with the first register, which is the control register(CR1). Control registers are used to control the peripheral. So, it has various bits here. So, let&#8217;s go as per our discussion.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">First, set the SPI mode to half-duplex controller mode. Remember, the \u2018controller\u2019 is the new word used for \u2018master\u2019.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Master selection or controller selection(MSTR):<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">You have to set this bit. By using this bit, you are telling the SPI that you want to use the SPI as controller mode.<\/span>&nbsp;<\/span><\/p>\n<figure id=\"attachment_14691\" aria-describedby=\"caption-attachment-14691\" style=\"width: 645px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14691 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-4-3.png\" alt=\"Figure 4. MSTR bit\" width=\"645\" height=\"120\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-3.png 1057w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-3-300x56.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-3-1024x191.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-3-768x143.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-3-600x112.png 600w\" sizes=\"(max-width: 645px) 100vw, 645px\" \/><figcaption id=\"caption-attachment-14691\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. MSTR bit<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, SPI_CR1_MSTR_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">This line sets the Master Mode bit in the CR1 register of the SPI peripheral. This sets the SPI to operate as the controller (master) in a multi-slave communication system. <\/span><span style=\"font-weight: 400;\">This is controller mode. But, we need a half-duplex. That you can do using the BIDIMODE.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, SPI_CR1_BIDIMODE_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line sets the Bidirectional Data mode bit in the CR1 register of the SPI peripheral. This enables the use of a single wire for both data input and output.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Data frame format (DFF):<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We want to use an 8-bit frame format for transmission or reception. Let&#8217;s clear this bit.&nbsp;<\/span><\/p>\n<figure id=\"attachment_14692\" aria-describedby=\"caption-attachment-14692\" style=\"width: 704px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14692 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-4-4.png\" alt=\"Figure 5. DFF bit\" width=\"704\" height=\"131\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-4.png 1057w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-4-300x56.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-4-1024x191.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-4-768x143.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-4-600x112.png 600w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><figcaption id=\"caption-attachment-14692\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. DFF bit<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><strong>REG_CLR_BIT(pSPI-&gt;CR1, SPI_CR1_DFF_Pos);<\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line clears the Data Frame Format bit in the CR1 register of the SPI peripheral. This sets the data frame size to 8 bits.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>SSM: software slave management<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">SSM bit has to be enabled. Why? Because, we have our dedicated CS line, which we will be toggling using software. So, we don&#8217;t want hardware to manage the peripherals. That&#8217;s why you must enable this. <\/span><\/p>\n<figure id=\"attachment_14693\" aria-describedby=\"caption-attachment-14693\" style=\"width: 663px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14693 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-6-2.png\" alt=\"Figure 6. SSM, SSI, LSBFIRST bit\" width=\"663\" height=\"265\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-2.png 1263w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-2-300x120.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-2-1024x409.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-2-768x307.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-2-600x240.png 600w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><figcaption id=\"caption-attachment-14693\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. SSM, SSI, LSBFIRST bit<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, SPI_CR1_SSM_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line sets the Software Slave Management bit in the CR1 register of the SPI peripheral. This allows the master to control the slave selection manually (without using a hardware chip select line).<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Internal slave select(SSI):<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">SSI bit has an effect only when SSM bit is set. So, the value of this bit is forced onto the NSS pin and the value of the NSS pin is ignored.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Don&#8217;t worry about this bits, just set this bit to high.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, SPI_CR1_SSI_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line sets the Internal Slave Select bit in the CR1 register of the SPI peripheral. This sets the slave select line to a high level, so that the slave device is initially not selected.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>LSBFIRST<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, we want to send MSB first. So, clear this bit. It just means that, in 8-bit data, so the MSB of the 8-bit that is most significant bit of the frame will be sent on the wire first.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_CLR_BIT(pSPI-&gt;CR1, SPI_CR1_LSBFIRST_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line clears the LSB (Least Significant Bit) first bit in the CR1 register of the SPI peripheral. This sets the transmission order of bits to be sent starting with the MSB (Most Significant Bit).<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>BR: Baud rate control<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Setting the baudrate of the SPI clock is the important part. So, this is generated by the controller.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<figure id=\"attachment_14694\" aria-describedby=\"caption-attachment-14694\" style=\"width: 682px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14694\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-7-2.png\" alt=\"SPI peripheral configuration coding\" width=\"682\" height=\"206\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-2.png 1247w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-2-300x91.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-2-1024x310.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-2-768x232.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-2-600x181.png 600w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><figcaption id=\"caption-attachment-14694\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Baud rate control bit<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 18px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #ff0000;\">What is a peripheral clock?<\/span><\/strong><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You know that, the SPI5 peripheral lies in the APB2 domain. So, we configured the APB2 bus clock as 90MHz.&nbsp;<\/span><\/p>\n<figure id=\"attachment_14695\" aria-describedby=\"caption-attachment-14695\" style=\"width: 661px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14695\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-8-1.png\" alt=\"SPI peripheral configuration coding\" width=\"661\" height=\"303\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png 1865w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1-300x138.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1-1024x469.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1-768x352.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1-1536x704.png 1536w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><figcaption id=\"caption-attachment-14695\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Setup AHB and APBx clocks(STM32F429)<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">To achieve the maximum frequency of 45 MHz, the clock should be divided by 2 since 90 MHz divided by 2 is 45 MHz. However, according to our LCD datasheet, the speed should be less than 6 MHz. To meet this requirement, we need to further divide the clock by 16, which will give us a speed of around 5 MHz.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">What happens is, when you select the 011 option(Figure 7), the 90MHz will be divided by 16.&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_SET_BIT(pSPI-&gt;CR1, 0X3U, 0X7U, SPI_CR1_BR_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line sets the SPI clock speed in the CR1 register of the SPI peripheral. It uses a bit mask to set the Baud Rate Prescaler (BR) bits to 0x03, which divides the system clock by 16. This sets the SPI clock speed to 90MHz\/16 = 5.625MHz, which gives you around 5.625 MHz.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>CPOL and CPHA<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, go to the CPOL and CPHA selection. <\/span><\/p>\n<figure id=\"attachment_14696\" aria-describedby=\"caption-attachment-14696\" style=\"width: 562px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14696\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-9-1.png\" alt=\"SPI peripheral configuration coding\" width=\"562\" height=\"208\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-1.png 955w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-1-300x111.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-1-768x285.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-1-600x222.png 600w\" sizes=\"(max-width: 562px) 100vw, 562px\" \/><figcaption id=\"caption-attachment-14696\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. CPOL and CPHA bit<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Clock Polarity must be 0.&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_CLR_BIT(pSPI-&gt;CR1, SPI_CR1_CPOL_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line clears the Clock Polarity bit in the CR1 register of the SPI peripheral. This sets the clock to idle at a low level.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And CPHA must be 0. The first clock transition is the first data capture edge. Let&#8217;s use CPHA as 0. This is also called SPI Mode 0.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_CLR_BIT(pSPI-&gt;CR1, SPI_CR1_CPHA_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line clears the Clock Phase bit in the CR1 register of the SPI peripheral. This sets the data to be sampled on the first edge of the clock.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see whether we have any configuration items in the CR2 register.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You have to select the frame format as SPI Motorola mode. Let&#8217;s do that.<\/span><\/p>\n<figure id=\"attachment_14697\" aria-describedby=\"caption-attachment-14697\" style=\"width: 771px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14697\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-10-1.png\" alt=\"SPI peripheral configuration coding\" width=\"771\" height=\"215\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1.png 1164w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1-300x84.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1-1024x285.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1-768x214.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1-600x167.png 600w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><figcaption id=\"caption-attachment-14697\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. FRF (Frame format) bit<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>REG_CLR_BIT(pSPI-&gt;CR2, SPI_CR2_FRF_Pos);<\/b><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This line clears the Frame Format bit in the CR2 register of the SPI peripheral. This sets the SPI to use the Motorola frame format, which is a standard format used by many devices.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><a href=\"https:\/\/www.st.com\/resource\/en\/reference_manual\/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf\">Reference manual<\/a><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">Click here:<\/span>&nbsp;<span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\">https:\/\/fastbitlab.com\/course1<\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<div class=\"col-lg-1 col-md-12 col-sm-12 col-xs-12\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; SPI peripheral configuration coding &nbsp; In this article, let&#8217;s do the SPI_Init function. Here we do a microcontroller SPI configuration for controller mode. The code provided shows the initialization and configuration of the SPI (Serial Peripheral Interface) peripheral on a microcontroller, as shown in Figure 1. &nbsp; To begin, we need to activate the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14695,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"enable","ocean_disable_heading":"default","ocean_post_title":"SPI peripheral configuration coding","ocean_post_subheading":"","ocean_post_title_style":"solid-color","ocean_post_title_background_color":"#004793","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"off","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[],"class_list":["post-14685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SPI Peripheral Configuration: Initialization and Settings<\/title>\n<meta name=\"description\" content=\"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SPI Peripheral Configuration: Initialization and Settings\" \/>\n<meta property=\"og:description\" content=\"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-15T06:25:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-17T05:25:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1865\" \/>\n\t<meta property=\"og:image:height\" content=\"855\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 28| SPI peripheral configuration coding\",\"datePublished\":\"2023-05-15T06:25:23+00:00\",\"dateModified\":\"2023-08-17T05:25:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/\"},\"wordCount\":1370,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-8-1.png\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/\",\"name\":\"SPI Peripheral Configuration: Initialization and Settings\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-8-1.png\",\"datePublished\":\"2023-05-15T06:25:23+00:00\",\"dateModified\":\"2023-08-17T05:25:28+00:00\",\"description\":\"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-8-1.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-8-1.png\",\"width\":1865,\"height\":855,\"caption\":\"Figure 8. Setup AHB and APBx clocks(STM32F429)\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 28| SPI peripheral configuration coding\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SPI Peripheral Configuration: Initialization and Settings","description":"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/","og_locale":"en_US","og_type":"article","og_title":"SPI Peripheral Configuration: Initialization and Settings","og_description":"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register","og_url":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2023-05-15T06:25:23+00:00","article_modified_time":"2023-08-17T05:25:28+00:00","og_image":[{"width":1865,"height":855,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 28| SPI peripheral configuration coding","datePublished":"2023-05-15T06:25:23+00:00","dateModified":"2023-08-17T05:25:28+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/"},"wordCount":1370,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/","url":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/","name":"SPI Peripheral Configuration: Initialization and Settings","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png","datePublished":"2023-05-15T06:25:23+00:00","dateModified":"2023-08-17T05:25:28+00:00","description":"Learn how to configure and initialize the SPI peripheral on a microcontroller in controller mode. Understand key functions and register","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1.png","width":1865,"height":855,"caption":"Figure 8. Setup AHB and APBx clocks(STM32F429)"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-28-spi-peripheral-configuration-coding\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 28| SPI peripheral configuration coding"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=14685"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14685\/revisions"}],"predecessor-version":[{"id":14708,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14685\/revisions\/14708"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/14695"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=14685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=14685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=14685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}