STM32-LTDC, LCD-TFT, LVGL(MCU3) Lecture 31| Testing TFT-LCD command sending

 

Testing TFT-LCD command sending

 

In this article, we initialize the SPI peripheral first and then call the function LCD_SPI_Enable() to activate it.

Figure 1. LCD_SPI_Enable
Figure 1. LCD_SPI_Enable

The code is shown in Figure 1. It just sets the SPE bit of the control register 1. After that, you reset the board and you send commands to the LCD and these are the commands. 

In the LCD_SPI_Init function, we are currently in the controller mode and BIDI mode. However, we have not yet configured whether we want to transmit or receive on the bidirectional data line, which needs to be done separately.

To achieve this, we can use the BIDIOE bit, which is the output enable in bidirectional mode. This bit must be set to 1 whenever we want to transmit data. As we intend to transmit data, we should set this bit to 1.

Figure 2.BIDIOE
Figure 2.BIDIOE

 

Please make the changes shown in Figure 3 by utilizing the ‘REG_SET_BIT(pSPI->CR1, SPI_CR1_BIDIOE_Pos)‘ function.

Figure 3. Code
Figure 3. Code

 

You need to connect the logic analyzers to all of the pins to trace the signals. Once this is done, load the code onto the board and activate the IDE’s debug mode. I’ll open the logic analyzer software now.

Here I set the sample rate to 24. I’ll select 24, and then let’s click start.

Figure 4. Logic analyzer
Figure 4. Logic analyzer

 

Look at the trace in Figure 5. 

Figure 5. Trace
Figure 5. Trace

 

As you can see(Figure 5), this trace appears incorrect. Although we are correctly setting DCX low after making CS low, the clock signal is being generated outside the expected timing. Ideally, data transactions should occur only after the CS line has been asserted to low, but it appears to be happening outside of that boundary in this case. This indicates that there may be an issue with our code.

There is actually a mistake that I made here, which is mentioned in the reference manual. You can check the SR for the Busy flag.

Figure 6. Busy flag
Figure 6. Busy flag

Busy flag must be used with caution:  refer to section 28.3.7 for more information. 

 

Testing TFT-LCD command sending
Figure 7. BIDIMODE

Here you can see that, when BIDIMODE = 1, and BIDIOE=1, wait until TXE =1, so this we are not doing.

After the last data is written into the SPI_DR register: 

  1. wait until TXE = 1, 
  2. then wait until BSY = 0, 
  3. Disable the SPI (SPE=0) and, eventually, enter the Halt mode. (You can conclude that it is the end of the transfer)

 

Let’s go back to our bsp_lcd.c code, and here we will add the following line.

while(!REG_READ_BIT(pSPI->SR, SPI_SR_TXE_Pos)); (line 199 and 213, as shown in Figure 8).

Testing TFT-LCD command sending
Figure 8. Code

 

Let’s take a look at the trace. I’ll reset the board first.  

Look at Figure 9, now it is happening correctly. So, the transaction is happening inside this CS assertion.

Testing TFT-LCD command sending
Figure 9. Trace

 

To decode the data line, navigate to the Analyzers section and select SPI. MOSI is referred to as SDA, so select number 4 – ‘SDA’. However, MISO is not present, so select ‘None’. Clock is number 3 – ‘SCLK’, and Enable is number 1 – ‘CSX’. MSB is transmitted first, 8 bits per transfer, CPOL = 0, CPHA is 0. Finally, click on ‘Save’.

Figure 10. Analyzer setting
Figure 10. Analyzer setting

 

Look at Figure 11, it decoded the data line.

Testing TFT-LCD command sending
Figure 11. Decoded data line

 

Is it necessary to raise the CS signal between parameter transfers? 

I think you can keep this low. You need not deassert and assert again. Because, if you check the timing diagram in the datasheet of ILI9341, and page number 35. It says CSX can be “High” between command/command and parameter/command. SCL and SDA during CSX-’H’ is invalid.

Testing TFT-LCD command sending
Figure 12. CSX

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

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.