ESP32 driving HY-TFT320 display

January 10, 2020

I have been interfacing the ESP32 to a HY-TFT320. This module integrates a TFT display, SSD1289 display controller, XPT2046 (ADS7843) touch screen controller and SDCARD connector all connected through to a 2×20 pin socket.

The SSD1289 TFT interface has a 16 bit parallel data interface and needs 22 connections in total (CD, WR, RS, CS, RSET, LEDA and DB0-DB15). In addition, the touch interface has 6 connections (DCLK, CS, DIN, BUSY, DOUT and PENIRQ). The SDCARD reader has a further 4 pins (MISO, SCK, MOSI and CS). The remaining 8 pins are GND, VCC and 6 NC pins (i.e. not connected).

The ESP32 has 19 available R/W pins (13, 12, 14, 27, 26, 25, 33, 32, 15, 2, 4, 16, 17, 5, 18, 19, 21, 22 and 23) and 4 R/O pins (35, 34, 39 and 36). There are an additional 2 R/W pins (1, 3) that are used by UART 0.

Clearly the ESP32 19 available R/W pins aren’t enough to directly drive the SSD1289 controller (22 pins alone) so we need to find some way of increasing the number of available pins.

74HC573 Octal Buffered Latch

The first method I tried was to incorporate two 74HC573 octal buffered latches between the ESP32 and the SSD1289 data lines (DB0-DB15). The outputs (1Q-8Q) of the first latch were connected to DB0-DB7 and the outputs (1Q-8Q) of the second latch were connected to DB8-DB15. Both 74HC573 latches data input pins (1D-8D) were connected in parallel to the same 8 pins on the ESP32. In addition a further 2 pins on the ESP32 were required to connect to the LE pin on each of the 74HC573 latches.

The basic process of passing data to the SSD1289 was now to output the lower 8 bits from the ESP32 and then tell the lower 74HC573 to load those values into its buffer by pulsing its LE (latch enable) pin. Similarly the higher 8 bits were output and the higher 74HC573 was told to load those values into its buffer by pulsing its LE pin. We now have 16 bits using only 10 pins – hardly a massive reduction but enough to control the display and touch screen but not enough to try the SDCARD interface.

Pin Usage

  • 10 R/W pins to control 74HC573 devices.
  • 6 R/W pins to control (CD, WR, RD, CS, RSET and LEDA).
  • 3 R/W pins connected to (DCLK, CS and DIN) – Note DIN refers to input to touch controller and therefore output from ESP32.
  • 3 R/O pins connected to (DOUT, BUSY and PENIRQ) – Note DOUT refers to output from touch controller and therefore input to ESP32.

Performance

The general performance of the display using the this setup was actually quite responsive and was more than adequate providing you that animation or video isn’t required.

MCP23017

The MCP23017 provides an additional 16 GPIO lines accessible via an SPI interface. The 16 bits on the MCP23017 are used to buffer the 16 data lines required by the display. The none-data lines are still connected directly to pins on the ESP32 (CD, WR, RD, CS, RSET and LEDA).

This configuration requires 4 pins to drive the MCP23017 using SPI and a further six pins to drive the control lines (CD, WR, RD, CS, RSET and LEDA).

We could probably reduce the number of pins further by connecting LEDA directly to VCC and seeing as I am not intending on reading the display the RD lines could likewise be connected to VCC.

Pin Usage

  • 4 R/W pins to control MCP23017 devices.
  • 4 R/W pins to control (CD, WR, CS, and RSET).
  • 3 R/W pins connected to (DCLK, CS and DIN) – Note DIN refers to input to touch controller and therefore output from ESP32.
  • 3 R/O pins connected to (DOUT, BUSY and PENIRQ) – Note DOUT refers to output from touch controller and therefore input to ESP32.
  • 1 R/O pins available.
  • 8 R/W pins available.

Performance

The performance of the display using this setup is very disappointing, taking just over 2 seconds to redraw every pixel on the screen. It might be acceptable if your are planning to do only very minor changes to the display.

Conclusions

A display using the parallel interface there is a trade off between number of pins and performance. If you want reasonable performance then you have to use a lot of pins on the MCU which then means there aren’t enough pins to interface with anything else. If you reduce the number of pins using the MCP23017 then the performance is so poor that it becomes unusable.

One of the problem with using the MCP23017 is that you have to transmit 32 bits to load the 16 bit registers . Each 32 bits transfer consists of a 8-bit control byte (sync?), an 8-bit operation code and 16 bits of data.

I had originally got the display with the 16 bit parallel interface because I wanted to drive it quickly. This ended up using so many pins that I had to develop my own serial protocol to free up some pins. On reflection, a better approach is to look for another display that can be programmed directly via the SPI bus (e.g. ILI9341) – it will save pins, simplify the circuit and reduce the number of external components.

Future Improvements

I haven’t given up using the parallel interface. It should be possible to use a single 74HC573 + 8 data pins and some multiplexing of CS pins .

Tags: esp32 hy-tft320_262k ssd1289 tft