ST7735 1.8″ TFT Display with STM32

In this tutorial, I will cover how to interface ST7735 1.8″ TFT Display with STM32, and to do so, I will use the SPI peripheral of STM32.
This particular display uses 8 pins for controlling the display, and the pins are shown below

1. LED :: Backlight -> Connect to 3.3V
2. SCK :: Serial clock input -> connect to SPI SCK pin
3. SDA :: Serial data input -> Connect to SPI MOSI pin
4. DC :: Data/Command selection -> Connect to PA9
5. RESET :: Reset -> Connect to PC7
6. CS :: Chip Select -> Connect to PB6
7. GND :: Ground -> GND
8. VCC :: Power Supply -> 3.3V

CubeMX Setup

I have selected SPI for the purpose, and I am keeping the Baud Rate around 5 MB/s. You can test higher baud rates also.


Other than SPI pins, we need to select three more pins as output. I have selected PB6 for CS, PC7 for RESET, and PA9 for DC. You are free to choose any other pins also, whatever suits the requirement

Other than this, you also need to include ST7735.h and ST7735.c in the project folder.

That’s all the setup needed here. Let’s take a look at some part of the code



Some Insight into the CODE

First of all we need to set the parameters according to our setup. All the changes needed to made are only in the ST7735.h file

extern SPI_HandleTypeDef hspi1;
#define ST7735_SPI_PORT hspi1

Change the SPI handler according to your setup


/****** PIN DEFINES ******/
#define CS_PORT GPIOB
#define CS_PIN  GPIO_PIN_6
#define DC_PORT GPIOA
#define DC_PIN  GPIO_PIN_9
#define RST_PORT GPIOC
#define RST_PIN  GPIO_PIN_7

If you are not using the default pins, Change them above


/****** TFT DEFINES ******/
//#define ST7735_IS_160X80 1
//#define ST7735_IS_128X128 1
#define ST7735_IS_160X128 1
#define ST7735_WIDTH  128
#define ST7735_HEIGHT 160

Also, if you have any other variant of ST7735, you need to uncomment the respective define above.
Change the width and the height parameters too


main function

int main ()
{
  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();
  MX_SPI1_Init();

  ST7735_Init(0);
  fillScreen(BLACK);
  testAll();
  HAL_Delay(1000);

  while (1)
  {

  ST7735_SetRotation(0);
  ST7735_WriteString(0, 0, "HELLO", Font_11x18, RED,BLACK);
  HAL_Delay(1000);
  fillScreen(BLACK);

  ST7735_SetRotation(1);
  ST7735_WriteString(0, 0, "WORLD", Font_11x18, GREEN,BLACK);
  HAL_Delay(1000);
  fillScreen(BLACK);

  ST7735_SetRotation(2);
  ST7735_WriteString(0, 0, "FROM", Font_11x18, BLUE,BLACK);
  HAL_Delay(1000);
  fillScreen(BLACK);

  ST7735_SetRotation(3);
  ST7735_WriteString(0, 0, "ControllersTech", Font_16x26, YELLOW,BLACK);
  HAL_Delay(1000);
  fillScreen(BLACK);
  }
}

You can see the output of the above code in the result section



Result

Check out the Video Below




Info

You can help with the development by DONATING Below.
To download the project, click the DOWNLOAD button.

Subscribe
Notify of

25 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
keyboard_arrow_up

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add controllerstech.com to your ad blocking whitelist or disable your adblocking software.

×