ESP32 and TFT ST7735

KHOAPHAM
Posts: 12
Joined: Wed Jan 19, 2022 3:03 am

ESP32 and TFT ST7735

Postby KHOAPHAM » Wed Jan 19, 2022 3:19 am

Hello,
I need you guys help. :?: :?: :?: :?: :?:
I'm trying to show image on LCD. After many efforts, it's still showing blank. Could you give me some advices?. Thank you in advance.
I use ESP32-WROOM32, tft ST7735 LCD and SPI_master.h
Here is my code.
  1. [code]#include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/task.h"
  6. #include "esp_system.h"
  7. #include "driver/spi_master.h"[Codebox=c file=Untitled.c]
#include "driver/gpio.h"

#define PIN_NUM_MOSI GPIO_NUM_23
#define PIN_NUM_CLK GPIO_NUM_18
#define CS GPIO_NUM_5
#define DC GPIO_NUM_2
#define RST GPIO_NUM_4

void send_cmd (spi_device_handle_t spi, const uint8_t cmd){
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.flags = SPI_TRANS_USE_TXDATA;
t.length = 8;
t.tx_data[0] = cmd;
gpio_set_level(DC, 0);
esp_err_t ret = spi_device_polling_transmit(spi, &t);
assert(ret == ESP_OK);
}

void send_data(spi_device_handle_t spi, const uint8_t *data, int length){
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = 8*length;
t.tx_buffer = data;
gpio_set_level(DC, 1);
esp_err_t ret = spi_device_polling_transmit(spi, &t);
assert(ret == ESP_OK);
}


void lcd_Init (spi_device_handle_t t){
//Initial parameter
//Display on
//send_cmd (t, 0x01);
//Memory data access control
uint8_t MDAC = 0b00000000;
send_cmd (t, 0x36);
send_data (t,&MDAC,1);
//Interface pixel format
uint8_t IPF = 0x55;
send_cmd (t, 0x2A);
send_data (t,&IPF,1);
//Sleep out
send_cmd (t, 0x11);
//Display on
send_cmd (t, 0x29);
}


void app_main(void)
{
gpio_set_direction (DC, GPIO_MODE_OUTPUT);
gpio_set_direction (RST, GPIO_MODE_OUTPUT);

esp_err_t ret;
spi_device_handle_t spi;
spi_bus_config_t Busconfig={
.mosi_io_num=PIN_NUM_MOSI,
.sclk_io_num=PIN_NUM_CLK,
.quadwp_io_num=-1,
.quadhd_io_num=-1,
.max_transfer_sz=128*160*2
};

spi_device_interface_config_t DeviceConfig={
.command_bits = 0,
.address_bits = 0,
.dummy_bits = 0,
.mode = 0,
.clock_speed_hz = 8000000,
.spics_io_num = GPIO_NUM_5,
.queue_size = 10000
};
gpio_set_level(RST, 0);
vTaskDelay(100);
gpio_set_level(RST, 1);
ret = spi_bus_initialize (SPI3_HOST, &Busconfig, SPI_DMA_CH2);
assert(ret == ESP_OK);
ret = spi_bus_add_device(SPI3_HOST, &DeviceConfig, &spi);
assert(ret == ESP_OK);
lcd_Init(spi);

uint8_t data[]= {/*image to binary, 8bit, 2byte/pixel*/};
uint8_t caset[] = {0x00, 0x00, 0x00, 0x7F};
uint8_t raset[] = {0x00, 0x00, 0x00, 0x9F};
send_cmd(spi, 0x2A);
send_data(spi, caset, 4);
send_cmd(spi, 0x2B);
send_data(spi, raset, 4);
send_cmd(spi, 0x2C);
send_data (spi, data, sizeof(data));
}[/code]
[/Codebox]

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 and TFT ST7735

Postby ESP_Sprite » Wed Jan 19, 2022 4:37 am

Are you sure your hardware works, as in: if you take the SPI_master LCD example (and potentially change it over to the pinout that your LCD uses), does it work?

KHOAPHAM
Posts: 12
Joined: Wed Jan 19, 2022 3:03 am

Re: ESP32 and TFT ST7735

Postby KHOAPHAM » Wed Jan 19, 2022 5:17 am

The program LCD in SPI_Master directory read data from LCD and do initial step. Mine only have SDA connect to MOSI pin. So it is not suitable for my hardware. And some parameters seem like wrong. I think there is not any problem with my LCD which I just bought. I guess my code has been wrong.

KHOAPHAM
Posts: 12
Joined: Wed Jan 19, 2022 3:03 am

Re: ESP32 and TFT ST7735

Postby KHOAPHAM » Wed Jan 19, 2022 6:10 am

ESP_Sprite wrote: Are you sure your hardware works, as in: if you take the SPI_master LCD example (and potentially change it over to the pinout that your LCD uses), does it work?
Thank you for reply,
I'm quite sure my hardware is good.. I guess the problem is in my code.
Thank you.

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 and TFT ST7735

Postby ESP_Sprite » Wed Jan 19, 2022 8:06 am

You can disable (or override) the LCD reading code by setting the lcd type in menuconfig, I think. Still suggest you do this because it tests if your entire hardware setup works, including your wiring, power supply etc.

Who is online

Users browsing this forum: MicroController and 68 guests