{"id":14648,"date":"2023-05-13T09:31:26","date_gmt":"2023-05-13T04:01:26","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=14648"},"modified":"2023-05-13T09:31:26","modified_gmt":"2023-05-13T04:01:26","slug":"stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/","title":{"rendered":"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 27| Configuring GPIO pins for SPI functionality"},"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; font-family: 'Roboto Slab'; font-weight: 400; line-height: 50px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>Configuring GPIO pins for SPI functionality<\/strong><\/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-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;\">In this diagram, you can see that we have PF9 and PF7 pins that need to be configured for SPI functionality. The SPI peripheral being used is SPI5.<\/span><\/p>\n<figure id=\"attachment_14651\" aria-describedby=\"caption-attachment-14651\" style=\"width: 705px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-14651 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-1-3.png\" alt=\"Figure 1. ILI9341 programming interface\" width=\"705\" height=\"367\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png 1647w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3-300x156.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3-1024x533.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3-768x400.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3-600x312.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3-1536x799.png 1536w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><figcaption id=\"caption-attachment-14651\" class=\"wp-caption-text\">Figure 1. ILI9341 programming interface<\/figcaption><\/figure>\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;\">For that, you have to follow these steps.&nbsp;<\/span><\/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=\"text-decoration: underline; color: #172f73;\"><b>C<\/b><b>onfiguring GPIO pins for SPI functionality<\/b><\/span><\/p>\n<ul 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=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Configure the GPIO pin to alternate function mode.<\/span><\/li>\n<\/ul>\n<p class=\"\" style=\"text-align: left; padding-left: 40px; 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;\">Because, the pin is now used for an alternate function, that is SPI.&nbsp;<\/span><\/p>\n<ul 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=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Configure the alternate function mode number in the alternate function register (you can get the alternate function mode number from MCU datasheet).&nbsp;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">For SPI communication, No pull up or pull down resistors are required.<\/span><\/li>\n<\/ul>\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;\">That&#8217;s why we will not be using the pin in the open drain setting. You can just use an output type as push-pull.&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=\"font-weight: 400; color: #000000;\">The pins we need to touch are GPIO port F, pin numbers 9 and 7. Refer to the datasheet to identify the alternate functions supported by these pins.<\/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;\">In the STM32F429zi datasheet, navigate to the Pinouts and Pin Description section and locate the appropriate device, which in this case is the STM32F429 as shown in Figure 2. From there, navigate to Port F and specifically to Pin PF7 which can be configured to act as an SPI clock when its alternate function is set to 5. The mode number for this pin should also be set to 5.<\/span><\/p>\n<figure id=\"attachment_14652\" aria-describedby=\"caption-attachment-14652\" style=\"width: 773px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14652\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-2-3.png\" alt=\"Configuring GPIO pins for SPI functionality\" width=\"773\" height=\"537\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-3.png 1437w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-3-300x209.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-3-1024x712.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-3-768x534.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-2-3-600x417.png 600w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><figcaption id=\"caption-attachment-14652\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. STM32F427xx and STM32F429xx alternate function mapping<\/span><\/figcaption><\/figure>\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;\">Similarly, Pin PF9 can act as SPI5_MOSI, but only if its alternate function mode is set to 5.<\/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;\">Where to configure this value 5? That you have to do in the alternate function register of the GPIO.&nbsp;<\/span><\/p>\n<figure id=\"attachment_14653\" aria-describedby=\"caption-attachment-14653\" style=\"width: 700px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14653\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-3-3.png\" alt=\"Configuring GPIO pins for SPI functionality\" width=\"700\" height=\"225\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-3.png 1409w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-3-300x96.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-3-1024x329.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-3-768x247.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-3-3-600x193.png 600w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption id=\"caption-attachment-14653\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3.STM32F427xx and STM32F429xx alternate function mapping<\/span><\/figcaption><\/figure>\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 head to the GPIO registers section. In the Mode register, you need to select the alternate function mode. Next, in the Output Type register, simply choose push-pull. After that, you can select a high speed in the Output Speed register (as shown in Figure 4).&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=\"font-weight: 400; color: #000000;\">The pull-up, and pull down settings are not required, and then go all the way to GPIO alternate function low register or high register.<\/span><\/p>\n<figure id=\"attachment_14654\" aria-describedby=\"caption-attachment-14654\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14654\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-4-2.png\" alt=\"Configuring GPIO pins for SPI functionality\" width=\"650\" height=\"357\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2.png 2942w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-300x165.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-1024x562.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-768x422.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-600x330.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-1536x844.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-4-2-2048x1125.png 2048w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><figcaption id=\"caption-attachment-14654\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. GPIO registers<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_14655\" aria-describedby=\"caption-attachment-14655\" style=\"width: 688px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14655\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-5-1.png\" alt=\"Configuring GPIO pins for SPI functionality\" width=\"688\" height=\"331\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1.png 1735w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1-300x144.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1-1024x493.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1-768x370.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1-600x289.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-5-1-1536x739.png 1536w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><figcaption id=\"caption-attachment-14655\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. GPIO alternate function low register(GPIOx_AFRL)<\/span><\/figcaption><\/figure>\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;\">First, we need to configure the alternate function for PF7. Since PF7 is a pin number less than 8, we must configure the function low register. In the low register, each pin takes a 4-bit field.<\/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;\">By using the low register, we can configure the alternate function for 8 pins, ranging from 0 to 7. Therefore, for PF7, which is the 7th pin, we need to configure the appropriate fields(AFRL7 &#8211; 0101). Here we have&nbsp; to store the value 5. To achieve this, we can use the REG_SET_VAL macro.<\/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;\">By doing so, we can easily configure the alternate function for PF7.<\/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;\">After that, for PF9, as 9 is greater than 8, you cannot use the low register and must switch to a high register. Therefore, you need to modify the bit fields in the alternate function high register for pin number 9 and store the value 9 there.<\/span><\/p>\n<figure id=\"attachment_14656\" aria-describedby=\"caption-attachment-14656\" style=\"width: 620px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14656\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-6-1.png\" alt=\"Configuring GPIO pins for SPI functionality\" width=\"620\" height=\"310\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1.png 1743w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1-300x150.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1-1024x512.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1-768x384.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1-600x300.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-6-1-1536x768.png 1536w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><figcaption id=\"caption-attachment-14656\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. GPIO alternate function high register(GPIOx_AFRH)<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Initialize the GPIO pin to SPI functionality<\/b><\/span><b><br \/>\n<\/b><\/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 start with SPI SCL, that is SPI_CLK and the pin is PF7(Figure 7).<\/span><\/p>\n<figure id=\"attachment_14657\" aria-describedby=\"caption-attachment-14657\" style=\"width: 730px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14657 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-7-1.png\" alt=\"Figure 7. LCD pin initialization code\" width=\"730\" height=\"706\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-1.png 1079w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-1-300x290.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-1-1024x990.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-1-768x742.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-7-1-600x580.png 600w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><figcaption id=\"caption-attachment-14657\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. LCD pin initialization code<\/span><\/figcaption><\/figure>\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: #008000;\"><b>REG_SET_VAL(pGPIOF-&gt;MODER,2U, 0x3U, (LCD_SCL_PIN * 2U));<\/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=\"font-weight: 400; color: #000000;\">This line sets the mode of a pin, which is connected to the clock signal of an SPI (Serial Peripheral Interface) device, as an output pin with an alternate function mode. The macro REG_SET_VAL is likely a macro that sets the value of a specific bit range in a memory-mapped register. The pGPIOF-&gt;MODER pointer likely points to the register that controls the mode of all the pins on a specific GPIO port (port F in this case). 2U specifies the position of the two bits that control the mode of the specific pin being configured, which is calculated by multiplying the pin number (LCD_SCL_PIN) by 2. 0x3U is the value that will be written to those two bits to set the mode to alternate function mode.<\/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: #008000;\"><b>REG_CLR_BIT(pGPIOF-&gt;OTYPER, LCD_SCL_PIN);<\/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;\">After that, the output type we can keep push-pull. This line clears a bit in the register that controls the output type of a pin, which is connected to the clock signal of the SPI device. The macro REG_CLR_BIT likely takes a pointer to the register and the bit position to be cleared (LCD_SCL_PIN in this case).<\/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: #008000;\"><b>REG_SET_VAL(pGPIOF-&gt;OSPEEDR, 2U, 0x3U, (LCD_SDA_PIN * 2U));<\/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;\">After that, speed. This line sets the output speed of a pin, which is connected to the data signal of the SPI device, to high speed. The macro REG_SET_VAL likely sets the value of a specific bit range in a memory-mapped register. pGPIOF-&gt;OSPEEDR likely points to the register that controls the output speed of all the pins on the GPIO port. 2U specifies the position of the two bits that control the output speed of the specific pin being configured, which is calculated by multiplying the pin number (LCD_SDA_PIN) by 2. 0x3U is the value that will be written to those two bits to set the output speed to high.<\/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: #008000;\"><strong>REG_SET_VAL(pGPIOF-&gt;AFR[1], 5U, 0xFU, ((LCD_SDA_PIN % 8) * 4U));<\/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 sets the alternate function of a pin, which is connected to the data signal of the SPI device, to a specific function. The macro REG_SET_VAL is likely being used to set the value of a specific bit range in a memory-mapped register. pGPIOF-&gt;AFR[1] likely points to the second register in a pair of registers that control the alternate function of all the pins on the GPIO port. 5U specifies the position of the four bits that control the alternate function of the specific pin being configured. 0xFU is the value that will be written to those four bits to select the specific alternate function. ((LCD_SDA_PIN % 8) * 4U) calculates the offset within the register where the four bits for the specific pin being configured are located since each pin&#8217;s alternate function is specified by four bits within the register. The %8 operation is used to ensure that the offset is within the range of 0 to 31 since there are 32 bits in each 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;\">Our LCD_Pin configuration is over.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>SPI terminologies<\/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;\">In this article, I will redefine the SPI signal names.&nbsp;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<figure id=\"attachment_14658\" aria-describedby=\"caption-attachment-14658\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14658 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-8.png\" alt=\"Figure 8. Redefining SPI signal names\" width=\"711\" height=\"316\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8.png 1785w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-300x133.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1024x455.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-768x341.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-600x267.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-8-1536x682.png 1536w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><figcaption id=\"caption-attachment-14658\" class=\"wp-caption-text\">Figure 8. Redefining SPI signal names<\/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: #000000;\"><span style=\"font-weight: 400;\">We will not be using master and slave terminology anymore in this article. <\/span><span style=\"font-weight: 400;\">Instead, we will shift to new signal names. The name &#8220;Master&#8221; will be replaced with &#8220;Controller,&#8221; and &#8220;Slave&#8221; will be replaced with &#8220;Peripheral.&#8221; Additionally, instead of &#8220;MOSI&#8221; and &#8220;MISO&#8221; terminology, you can use &#8220;PICO&#8221; or &#8220;POCI&#8221; terminology, or in simpler terms, I will be using the terminology &#8220;SDI&#8221; and &#8220;SDO.&#8221; &#8220;SDI&#8221; stands for &#8220;serial data in,&#8221; and &#8220;SDO&#8221; stands for &#8220;serial data out.&#8221; Please note this change.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>MCU SPI peripheral configuration&nbsp;<\/b><\/span><\/p>\n<ul 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=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s use the below settings for SPI configuration<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">SPI mode: Half-duplex Controller<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">Data format: 8 bits, msb first<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">CPOL and CPHA: Check the peripheral datasheet to obtain the correct setting it requires<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">SPI Clock: Check the peripheral datasheet and obtain the max speed it can support(&lt;6Mhz)<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">Chip select is handled by the software<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\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;\"><strong><span style=\"text-decoration: underline; color: #000080;\">CPOL and CPHA:<\/span><\/strong><span style=\"font-weight: 400;\"> Check the <a href=\"https:\/\/cdn-shop.adafruit.com\/datasheets\/ILI9341.pdf\">peripheral datasheet<\/a>(page number 36) to obtain the correct setting it requires.<\/span><\/span><\/p>\n<figure id=\"attachment_14659\" aria-describedby=\"caption-attachment-14659\" style=\"width: 588px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14659 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-9.png\" alt=\"Figure 9. Timing diagram\" width=\"588\" height=\"224\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9.png 1398w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-300x114.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-1024x390.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-768x292.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-9-600x228.png 600w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><figcaption id=\"caption-attachment-14659\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Timing diagram<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>CPOL:<\/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;\">CPOL refers to clock polarity, which determines the state of the clock during the IDLE state. When CPOL is set to 0, the IDLE state of the clock will be low. If CPOL is set to 1, the IDLE state will be high. However, if the datasheet specifies CPOL = 0, do not use the alternate polarity.<\/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;\">CPHA, or clock phase, determines when data is sampled on the data line. In the timing diagram, the arrow indicates that data is sampled at the rising edge of the clock. This means that the master must update the data in the previous edge of the clock, which occurs when CPHA = 0.<\/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;\">To determine the appropriate settings, refer to the SPI section of the microcontroller&#8217;s reference manual, as shown in Figure 10. When CPHA = 0 and CPOL = 0, the controller updates the data on the falling edge and the peripheral samples the data on the rising edge. Therefore, select CPHA as 0 to ensure that the data is correctly updated and sampled. Thus, the recommended settings are CPOL = 0 and CPHA = 0.<\/span><\/p>\n<figure id=\"attachment_14660\" aria-describedby=\"caption-attachment-14660\" style=\"width: 723px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14660 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/05\/Figure-10.png\" alt=\"Figure 10. Data clock timing diagram\" width=\"723\" height=\"688\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10.png 1167w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-300x286.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-1024x975.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-768x731.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-10-600x571.png 600w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><figcaption id=\"caption-attachment-14660\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Data clock timing diagram<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>SPI Clock<\/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;\">This will be produced by the controller. And you have to check the peripheral datasheet and obtain the maximum speed it can support. You keep the SPI clock speed is less than 6MHz.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Chip select<\/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;\">Chip selection is handled by the software. And there is a dedicated pin for Chip Select, and you have to toggle the chip select whenever you want to activate the peripheral. This is a simple GPIO which we have to toggle.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" 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>&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; Configuring GPIO pins for SPI functionality &nbsp; In this diagram, you can see that we have PF9 and PF7 pins that need to be configured for SPI functionality. The SPI peripheral being used is SPI5. &nbsp; For that, you have to follow these steps.&nbsp; Configuring GPIO pins for SPI functionality Configure the GPIO pin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14651,"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":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","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":"default","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-14648","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>Configuring GPIO pins for SPI functionality<\/title>\n<meta name=\"description\" content=\"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.\" \/>\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-27-configuring-gpio-pins-for-spi-functionality\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring GPIO pins for SPI functionality\" \/>\n<meta property=\"og:description\" content=\"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/\" \/>\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-13T04:01:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1647\" \/>\n\t<meta property=\"og:image:height\" content=\"857\" \/>\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=\"9 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-27-configuring-gpio-pins-for-spi-functionality\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 27| Configuring GPIO pins for SPI functionality\",\"datePublished\":\"2023-05-13T04:01:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/\"},\"wordCount\":1629,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-1-3.png\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/\",\"name\":\"Configuring GPIO pins for SPI functionality\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-1-3.png\",\"datePublished\":\"2023-05-13T04:01:26+00:00\",\"description\":\"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-1-3.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Figure-1-3.png\",\"width\":1647,\"height\":857,\"caption\":\"Figure 1. ILI9341 programming interface\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\\\/#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 27| Configuring GPIO pins for SPI functionality\"}]},{\"@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":"Configuring GPIO pins for SPI functionality","description":"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.","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-27-configuring-gpio-pins-for-spi-functionality\/","og_locale":"en_US","og_type":"article","og_title":"Configuring GPIO pins for SPI functionality","og_description":"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.","og_url":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2023-05-13T04:01:26+00:00","og_image":[{"width":1647,"height":857,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"STM32-LTDC, LCD-TFT, LVGL (MCU3) Lecture 27| Configuring GPIO pins for SPI functionality","datePublished":"2023-05-13T04:01:26+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/"},"wordCount":1629,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/","url":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/","name":"Configuring GPIO pins for SPI functionality","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png","datePublished":"2023-05-13T04:01:26+00:00","description":"Configuring GPIO pins for SPI functionality. Configuring GPIO pins for SPI functionality. Configure the GPIO pin to alternate function mode.","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/05\/Figure-1-3.png","width":1647,"height":857,"caption":"Figure 1. ILI9341 programming interface"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/stm32-ltdc-lcd-tft-lvgl-mcu3-lecture-27-configuring-gpio-pins-for-spi-functionality\/#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 27| Configuring GPIO pins for SPI functionality"}]},{"@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\/14648","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=14648"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14648\/revisions"}],"predecessor-version":[{"id":14684,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14648\/revisions\/14684"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/14651"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=14648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=14648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=14648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}