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.
- [code]#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_system.h"
- #include "driver/spi_master.h"[Codebox=c file=Untitled.c]
#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]