Interface TFT display with STM32 in parallel mode || CubeIDE || CubeMX || HAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone today in this tutorial I am going to show you guys how to interface TFT display with stm32 this is going to be a long ride so buckle up kindly pay attention to every detail there are a lot of settings involved I am using HX 3 4 7g display and it is 240 by 320 TFT display as shown in the picture before starting this tutorial I want to mention that this is a port from MCU friends is arduino code I have made some changes to make it compatible with cube MX let's start by creating the project in cube ide i am using stm32 f103 controller the method should work with others too I have tested it on F 446 and F 407 controllers okay first things first setup the RCC and serial wire debug we need the delay in microseconds so I am using timer 1 to do that I am assuming I don't need to explain this part you can check my other video if you don't know how to use delay in microseconds here comes the main part all these TFTs have eight data pins and five control pins it will be good for you if you choose the port pins of any one port from zero to seven to connect them in the same order to the LCD data pins but just to show you guys how to program in the random cases I will choose some of the pins as random Here I am choosing pb0 and pv one and then three four five six to be connected in the same order to the LCD data pins then pa5 to be connected to LCD d7 and P a 15 to LCD D to pin the connections are as follows d0 d1 d2 d3 d4 d5 d6 d7 we have to select five control pins also this is for reset then C s then W R than RS and finally Rd is selected as input the final setup of the pins is as shown in the picture next complete the rest of the setup for the clock and once done just click Save you now we need to copy some library files into the project folder just follow me [Music] let's just refresh the project once next we need to include those files in our project [Music] if you take a look at the functions dot H file these are all the functions that you can use for the TFT all the modification that you are required to do is in the user settings dot H file I forgot to include the functions dot H file coming back to modification first of all changed the pins and ports according to your setup most of them are fine let's take a look at the connections once LCD d7 is connected to GPIO a5 I need to change that here you define the width and height of the LCD here you need to uncomment the type of display you are using I am using HX 8 3 4 7g so that one is defined microsecond delay function is defined here change it accordingly if you are not using time or one here comes the most important part of the setup I have even written everything in the comments you can read it here we are going to modify the right eight function first we need to clear all the data pins and to do that we need to set the higher bits of BSR our register for example to clear pins b3 before b8 and b9 we will write one two third fourth eighth and ninth position and shift it left sixteen times so in the gpio be BSS our register i am going to write one in 0th first third fourth fifth and sixth positions because these are the GPIO B pins that are connected to LC D data pins for GPIO a only pins a two and a fifteen are connected to the LCD data pins so one is only written in the fifth and 15th position next we need to write data to these pins and to do so we will write to the lower bits of BS SR register here I have mentioned an example that if LCD d4 is connected to b7 and LCD d6 is connected to B 2 then in order to write the data we need to select the 4th bit of data because we are doing it for LCD d4 and then shift that bit by 3 to make it 7 that's where the d4 is connected and similarly to write to the LCD d6 we will first select the 6th bit of data and this time we will shift it to the right by 4 that will be like subtracting and the final result would be 2 that's where the d6 is connected in our actual case the LCD D 2 pin is connected to a 15 so in the GPIO a BS SR register we need to first select the second bit and then shift it by 13 to make a total of 15 also LCD d7 is connected to a 5 so first we will select the seventh bit of the data and then we need to shift that bit to fifth location so shifted right by two you next coming to GPIO be LCD d0 is connected to b0 pin so we don't need to shift it anywhere similarly other pins are also connected in a proper order so no shifting is required that's why I told you to choose and connect in order it makes things a bit easy this was the writing data to the pins now to read the value on the pins we need to read the input data register again I have mentioned an example here you can read it basically unlike last time where we selected the LCD pins first here we are going to select the GPIO pins first after selecting the GPIO pin we will shift it to make it equal to the LCD pin it is connected to you will get an idea of what I am talking about in a while let's take b0 first it is connected to d0 so we won't shift it same for the b1 also now here I have selected a 15 and as it is connected to LCD d2 I am shifting it by 13 to the right 15 minus 13 makes up to next b3 b4 b5 and b6 are connected to the respective pins so no shifting is required now in the end I am selecting Pinay five and then shifting it by two in the left to make it seven because a five is connected to LCD D seven this completes the important part of the setup next you need to uncomment these lines based on your clock frequency you let's write the main function now I am defining a variable to store ID of the LCD next we need to start the timer for the delay to work [Music] first of all read the ID of the display and store it in the variable that we created give some delay next initialize the TFT with the ID then I am writing some tests [Music] okay print new STR prints the string in a row its parameters are the row number text color the font type that you can find in the fonts dot C file size of the text and the string itself and in the end I am putting the display in the continuous scrolling let's compile the code and debug it I am setting the live expression to monitor the ID so I am getting correct ID here I will continue the execution you can see all the tests being performed by the display let's put this outside the while loop and I will add a code to invert the display correct the size of the string also let's disable these and run the program again you so the things are working as expected this is it guys these are some more functions that you can use for now some of them are in TFT dot H file I hope you will get yours working too I will make another video for the TFT displays that use SPI this code might have some errors at the moment I didn't test it thoroughly yet you can download the code from the link in the description you
Info
Channel: ControllersTech
Views: 81,304
Rating: undefined out of 5
Keywords: tft, stm32, 240, 320, hx8347, display, stm32cubeide, cube, ide, mx, hal, example, how to, f103, f4
Id: UTeNyY_g5i0
Channel Id: undefined
Length: 19min 19sec (1159 seconds)
Published: Sun Oct 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.