Advertise here

TFT ST7789 And SAMD21/L21-L22

TFT LCD ST7789 And SAMD21/L21-22

In this article I will show you how to control TFT display with ST7789 driver using ASF4(Atmel "Advanced" Software framwork 4 ) with any SAM D/L/E Microcontroller (In this example SAMD21 Xplained pro).


this display require SPI bus with DC pin (switch between Command and Data signal).

I used a TFT 1.54 Inch diplay module 240*240 pixel ( Link )
Connection:



I'm using SAMD21 SPI SERCOM 0 , you only need to change the SERCOM and the SPI SCLK & SPI MOSI pin if you want to change the SERCOM.



        DISPLAY         SAMD21
VCC +5V(or +3.3 based on your module)
SDA PA06
SCL PA07
RST PB06
DC PB07

CS PB03

  You will find 2 examples 

  1. Standard internal 8MHz  clock for the CPU and 4MHz for SPI.
  2. DFLL 48MHz for the CPU and 11MHz for SPI for faster graphics refersh rate.

To download the code please visit my Github from this link here

inside a folder called Graphic Library you will find all the files necessary to run the code, you can also replace the SPI driver to work with other MCU.

each example will show you how to use different function like draw lines / rectangles/ circles and draw bitmap.


how to use your Own Bitmap ?


  1. resize the image you want to 240x240 pixel and save it as Monochrome (Black and white).


  2. using LCD assistance for Windows convert the image to an array.


  3. copy the array and paste it inside Bitmap_logo.h files and then use (ST7789_drawBitmap) command to draw it.


   and here's the results






Things to improve:

the speed of the refresh rate for the display with CPU Clock@ 8MHz is so slow due to SPI clock gap between each Clock burst 



with 48MHZ for the CPU this time reduced to 1/8th with SPI clock 8MHz  and around 1/9th with 11MHz.



refreshing the display on each command using draw pixel caused this issue so if you want to solve it I recommend you using an array to save all the graphic and text you want to show it on the display and call a command (for example showDisplay) to update the screen much faster.

implement a faster method to control DC / CS GPIO using Port (SET/CLEAR Register).



No comments

Powered by Blogger.