TFT User Manual
TFT User Manual
1 Overview
This tutorial shows how to configure the PSoC to communicate with an ILI9341 TFT display
using 8-bit SPI (Serial Peripheral Interface). This tutorial also explains the basic steps for
writing pixels to the display as well as how to include emWin, a graphic library which
provides functions for drawing and displaying text on the LCD.
This tutorial is accompanied by two Creator projects, TFT and TFT with emWin, which
can be found on the course website. We will start by looking at the TFT project, which is
intended to get you comfortable communicating with the display.
2 Hardware
The pins colored red (also boxed) are used in this demo. Everything else can be left uncon-
nected. The pin assingments can be found in the projects .cydwr file.
1
Although the TFT display module can be powered off of 5V, it uses 3.3V logic. If the
PSoC is powered with 5V, all its outputs going to the TFT must be passed though a voltage
divider to drop the 5V to 3.3V. Outputs of the TFT, such as SDI, will be at 3.3V and can
be connected directly to an input pin on the PSoC.
2
• GND - Ground
• DC - Data/Command select. When the DC line is low, data received by the LCD
is interpreted as commands. When this DC line is high, data is interpreted as data
(arguments to commands, pixel data, etc.)
• LED - This pin is used to control the intensity of the backlight. If not controlled by
an analog voltage, connecting this pin to 3.3V will set the display to full brightness.
3
Make sure the SPIM component is set up to send 8-bit data and that the shift direction
is set to MSB first. The TFT can handle bit rates of up to around 3 Mbps.
In addition to the typical SPI connections, the TFT uses the DC line to specify whether
the information being received should be interpreted as a command or as data. We will use
the PSoC’s output pin labeled “DC” to control the TFT’s DC line. This pin must be set
high or low in software depending on whether we want to send data or commands to the
display. The other output pins, labeled “RESET” and “LED”, should be tied to Vcc using
the Logic High component. We will not use them in this tutorial. The diagram below shows
the SPI write sequence.
4
3 Firmware
3.1 Sending Commands/Data
If you navigate to the file tft.c, you will find two functions, write8_a0() and write8_a1(),
which we will use to write commands and data to the TFT. write8_a0() sends an 8-bit
value to the TFT (via the SPIM component) with the DC line set low. Data sent using this
function are thus interpreted as commands. write8_a1 sends 8-bit values with the DC line
set high. Data sent using this function are interpreted as data.
Typically, communication with the TFT involves sending a command followed by zero or
more parameters (sent to the TFT as data). A list of commands and their parameters can
be found in the ILI9341 datasheet. For example, the command Column Address Set (0x2A)
defines the range of frame memory columns the MCU can access. This command expects
four 8-bit parameters, which specify the 16-bit addresses of the start column (SC) and end
column (EC). The command and parameters would be sent as follows:
This block of code would set the start column to 10 and the end column to 20.
5
3.3 Writing Pixels
The process of writing pixels to the the TFT begins with defining a rectangular window of
frame memory where you would like to write pixels. This is done using the Column Address
Set (0x2A) and Page Address Set (0x2B) commands, which are responsible for setting the
start column (SC), end column (EC), start page (SP), and end page (EP).
Once this window has been set, you can begin filling in pixels using the Memory Write
(0x2C) command. This command takes an arbitrary number of 16-bit parameters, with each
parameter specifying the color of a pixel (16-bit parameters should be sent MSB first). The
Memory Write command begins filling in pixels starting in the top left corner. This means
the first parameter will specify the color of the top left pixel. Successive parameters will
fill in pixels moving left to right. When the end column is reached, the next row will be
filled starting at the start column position. Once the Memory Write command has been
sent, all successive data received by the driver will be interpreted as pixel data until another
command is sent (i.e. a byte is sent with the DC line low).
6
The following is pseudo code outlining the typical pixel writing sequence described above:
7
4 Adding emWin Graphic Library
This section describes how to add the emWin library to a PSoC project. emWin is an
embedded graphic library which has been licensed to Cypress by SEGGER and provides a
wide range of functions for drawing and displaying text on an TFT. The following steps walk
through how to add emWin to a project.
1. From the course website, download the PSoC project TFT with emWin. The emWin
library is designed to support a large number of LCD/TFT controllers, including the
ILI9341. However, the user must provide the appropriate hardware/software to com-
municate with display, as well as an initialization function. In addition to tft.c (which
contains our functions for reading and writing to the display and our initialization
function), you will find several other configuration files which have been provided by
Cypress to set up the emWin library. The necessary changes have already been made
to these files to facilitate communication with our TFT.
1
http://www.cypress.com/go/comp emWin
8
• Next, navigate to ARM GCC 4.9-2015-q1-update → Linker → General
and click on Additional Link Files. Add the following file:
– ..\emWinGraphics v5 46\LinkLibrary\PSoC5\GCC\libemWin nosnts cm3 gcc.a
9
• Click on Additional Libraries and add m (the math.h library)
4. The emWin should now be added to your project. In main.c, make sure ”GUI.h” is
included. The file should look something like this:
#include <project.h>
#include "GUI.h"
void MainTask(void);
int main()
{
CyGlobalIntEnable;
SPIM_1_Start();
MainTask();
for(;;){}
}
void MainTask(void)
{
GUI_Init(); // must be called before any other GUI function
.
.
.
}
It is typical to use the function MainTask() as the entry point for the emWin functions.
Also note that GUI_Init() must be called before any other GUI functions can be used.
5. Program the PSoC with the TFT with emWin project. The code should fill the screen
black and then print “6.115 Rocks!”.
10
A complete description of the emWin setup process can be found here here2 . The emWin
user manual can be found here 3 .
2
https://www.cypress.com/file/440296/download
3
https://www.segger.com/downloads/emwin/UM03001
11