ST7789 DMA configuration: Yellow displayed instead of red
Posted: Mon Jun 10, 2024 1:15 pm
Hello,
I have a ESP32-S3-R8N16 board with a TFT screen 170x320. When I use Adafruit_GFX library everything works fine but I want to use DMA on the screen to have more reactivity and I try to display many thing but come back to the beginning and now I just want to display red screen but I have this:
I don't understand where is my error, can you help me please ? You can find my code here:
Thanks a lot
Ygles
I have a ESP32-S3-R8N16 board with a TFT screen 170x320. When I use Adafruit_GFX library everything works fine but I want to use DMA on the screen to have more reactivity and I try to display many thing but come back to the beginning and now I just want to display red screen but I have this:
I don't understand where is my error, can you help me please ? You can find my code here:
- #include <SPI.h>
- #include "driver/spi_master.h"
- #define TFT_CS 10
- #define TFT_DC 11
- #define TFT_MOSI 13
- #define TFT_SCLK 12
- #define TFT_RST 1
- #define TFT_BL 14
- #define WIDTH 170
- #define HEIGHT 320
- spi_device_handle_t spi;
- void setup() {
- Serial.begin(115200);
- // Initialiser les broches
- pinMode(TFT_CS, OUTPUT);
- pinMode(TFT_DC, OUTPUT);
- pinMode(TFT_RST, OUTPUT);
- pinMode(TFT_BL, OUTPUT);
- digitalWrite(TFT_CS, HIGH);
- digitalWrite(TFT_BL, HIGH);
- // Configuration du SPI
- spi_bus_config_t buscfg = {
- .mosi_io_num = TFT_MOSI,
- .miso_io_num = -1,
- .sclk_io_num = TFT_SCLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = WIDTH * HEIGHT * 2
- };
- spi_device_interface_config_t devcfg = {
- .mode = 0,
- .clock_speed_hz = 20 * 1000 * 1000,
- .spics_io_num = TFT_CS,
- .queue_size = 7,
- .pre_cb = NULL,
- .post_cb = NULL,
- };
- esp_err_t ret = spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO);
- if (ret != ESP_OK) {
- Serial.printf("Failed to initialize bus: %s\n", esp_err_to_name(ret));
- while (1)
- ;
- }
- ret = spi_bus_add_device(SPI3_HOST, &devcfg, &spi);
- if (ret != ESP_OK) {
- Serial.printf("Failed to add device: %s\n", esp_err_to_name(ret));
- while (1)
- ;
- }
- // Reset
- digitalWrite(TFT_RST, LOW);
- delay(100);
- digitalWrite(TFT_RST, HIGH);
- delay(100);
- // Init
- sendCommand(0x01); // Software reset
- delay(150);
- sendCommand(0x11); // Sleep out
- delay(500);
- sendCommand(0x36); // Memory data access control
- sendData(0x00);
- sendCommand(0x3A); // Interface pixel format
- sendData(0x55); // 16-bit/pixel
- sendCommand(0x29); // Display on
- sendCommand(0x13); // Normal display
- }
- void sendCommand(uint8_t cmd) {
- digitalWrite(TFT_DC, LOW);
- digitalWrite(TFT_CS, LOW);
- spi_transaction_t t;
- memset(&t, 0, sizeof(t));
- t.length = 8;
- t.tx_buffer = &cmd;
- spi_device_transmit(spi, &t);
- digitalWrite(TFT_CS, HIGH);
- }
- void sendData(uint8_t data) {
- digitalWrite(TFT_DC, HIGH);
- digitalWrite(TFT_CS, LOW);
- spi_transaction_t t;
- memset(&t, 0, sizeof(t));
- t.length = 8;
- t.tx_buffer = &data;
- spi_device_transmit(spi, &t);
- digitalWrite(TFT_CS, HIGH);
- }
- void loop() {
- sendCommand(0x2A); // Column address set
- sendData(0x00);
- sendData(0x23); // Offset because there is 35px before and after ((240 - 170) / 2)
- sendData(0x00);
- sendData(0xCC);
- sendCommand(0x2B); // Row address set
- sendData(0x00);
- sendData(0x00);
- sendData((HEIGHT - 1) >> 8);
- sendData((HEIGHT - 1) & 0xFF);
- sendCommand(0x2C); // Memory write
- digitalWrite(TFT_CS, LOW);
- delay(100);
- digitalWrite(TFT_DC, HIGH);
- delay(100);
- uint16_t lineBuffer[WIDTH];
- for (int y = 0; y < HEIGHT; y++) {
- for (int x = 0; x < WIDTH; x++) {
- // RED in RGB565
- lineBuffer[x] = 0xF800;
- }
- sendLine(lineBuffer);
- }
- delay(500);
- }
- void sendLine(uint16_t* lineBuffer) {
- digitalWrite(TFT_DC, HIGH);
- digitalWrite(TFT_CS, LOW);
- spi_transaction_t t;
- memset(&t, 0, sizeof(t));
- t.length = WIDTH * 16;
- t.tx_buffer = lineBuffer;
- spi_device_transmit(spi, &t);
- digitalWrite(TFT_CS, HIGH);
- }
Thanks a lot
Ygles