3.2.3.4. Interfacing SPI TFT displays with touch¶
This document describes how to connect a SPI interface based TFT display with touch support to the E2 connector, without the need for specific FPGA code. The given setup has advantages and drawbacks.
PROS:
It uses only
MIO
signals so it can be used with any FPGA image.Only extension connector E2 is used.
SPI is not wired through the FPGA so maximum clock speeds can be used.
CONS:
MIO signals shared with SPI, I2C and UART are consumed. So this interfaces can not be used for other purposes.
On board I2C EEPROM can not be accessed. This might cause issues in programs which store calibration data in the EEPROM.
Backlight control is not supported.
3.2.3.4.1. Hardware setup¶
3.2.3.4.1.1. pinctrl¶
It is possible to reconfigure Zynq MIO signals using the pinctrl
kernel driver.
This TFT display setup takes advantage of this by repurposing SPI, I2C and UART signals
on the E2 connector as SPI and GPIO signals which are required by the TFT display interface.
The reconfiguration is performed by including the tft-E2
device tree.
SPI TFT+touch |
MIO |
function |
pin |
pin |
function |
MIO |
SPI TFT+touch |
---|---|---|---|---|---|---|---|
GND |
|
|
GND |
GND |
|||
ADC_CLK- |
|
|
ADC_CLK+ |
||||
GND |
|
|
GND |
||||
AO[3] |
|
|
AO[2] |
||||
AO[1] |
|
|
AO[0] |
||||
AI[3] |
|
|
AI[2] |
||||
AI[1] |
|
|
AI[0] |
||||
I2C_GND |
|
|
common |
||||
TFT RESETn |
51 |
I2C SDA |
|
|
I2C_SCK |
50 |
SPI_SSs[1], touch |
touch pendown |
9 |
UART_RX |
|
|
UART_TX |
8 |
TFT D/C |
SPI_SSn[0], TFT |
13 |
SPI_CS |
|
|
SPI_CLK |
12 |
SPI_SCLK |
SPI_MISO |
11 |
SPI_MISO |
|
|
SPI_MOSI |
10 |
SPI_MOSI |
-4V |
|
|
+5V |
+5V |
Since some of the signals share the I2C bus which already contains an EEPROM, there is a possibility there will be functional conflicts. Although the probability of the I2C EEPROM going into an active state are low. I2C devices only react after an I2C start condition is present on the bus. The start condition requires both SDA and SCL signals to be low at the same time. Here it is assumed TFT display RESETn (active low) will not be active at the same time as the touch controller SPI SSn (active low) signal.
Attempts to access the I2C EEPROM will not interfere with the display, but they will return a timeout. This might (probably will) cause issues with applications using the I2C EEPROM, for example calibration access from Oscilloscope app.
There is no MIO pin left for backlight control, the easiest solution is to hard wire the display backlight pin to VCC.
3.2.3.4.1.2. SPI clock speed¶
Only a limited set of SPI clock speeds can be set depending on
the clock driving the SPI controller.
The SPI controller itself provides only power of 2 clock divider options.
See the Zynq TRM
(section B.30 SPI Controller (SPI) register BAUD_RATE_DIV
) for details.
The next table provides available frequencies for two SPI controller clock settings. The maximum clock speed for this SPI controller is 50MHz.
SPI controller clock |
f/4 |
f/8 |
f/16 |
f/32 |
f/64 |
f/128 |
f/256 |
---|---|---|---|---|---|---|---|
166.6MHz |
41.6 |
20.8 |
10.4 |
5.21 |
2.60 |
1.30 |
0.63 |
166.6MHz |
41.6 |
20.8 |
10.4 |
5.21 |
2.60 |
1.30 |
0.63 |
200.0MHz |
50.0 |
25.0 |
12.5 |
6.25 |
3.125 |
1.56 |
0.781 |
3.2.3.4.2. Software setup¶
Instructions for starting XFCE on the TFT display.
A script which can be used to generate an image with full support
is available on GitHub tft.sh
.
A set of Ubuntu/Debian packages should be installed:
apt-get -y install \
python3 python3-numpy build-essential libfftw3-dev python3-scipy \
xfonts-base tightvncserver xfce4-panel xfce4-session xfwm4 xfdesktop4 \
xfce4-terminal thunar gnome-icon-theme \
xserver-xorg xinit xserver-xorg-video-fbdev
An X11 configuration file should be added to the system 99-fbdev.conf
.
Over SSH start the X server:
startx
3.2.3.4.3. Tested/Supported devices¶
The next table lists supported devices and corresponding of device tree files each supporting a set of displays depending on the used TFT and touch drivers.
screen name |
specifications |
technical details |
device tree |
|||
---|---|---|---|---|---|---|
size |
resolution |
touch |
TFT controller |
touch controller |
||
2.8” |
240x320 |
|||||
3.5” |
480x320 |
resistive |
3.2.3.4.3.1. MI0283QT Adapter Rev 1.5¶
The device is powered by +5V, and it generates 3.3V using an on board LDO. Therefore all IO are 3.3V, so there are no conflicts.
Connector pinout based on the MI0283QT Adapter Rev 1.5 schematic.
SPI TFT+touch |
pin |
pin |
SPI TFT+touch |
||
---|---|---|---|---|---|
ADS_VREF |
|
|
ADS_VBAT |
||
ADS_AUX |
|
|
ADS_IRQ |
touch pendown |
|
TFT D/C |
BUSY-RS |
|
|
A-ADS_CS |
SPI_SSs[1], touch |
SPI_SCLK |
A-SCL |
|
|
SDO |
SPI_MISO |
SPI_MOSI |
A-SDI |
|
|
A-LCD_CS |
SPI_SSn[0], TFT |
TFT RESETn |
A-LCD_RST |
|
|
LCD_LED |
backlight |
+5V |
VCC |
|
|
VCC |
|
GND |
GND |
|
|
GND |
Backlight control is not available on the E2 connector. A simple solution is to connect the LCD_LED signal to +5V VCC, this can be done with a simple jumper between the two display connector pins. Otherwise it would be possible to repurpose a LED on Red Pitaya.
The 95-ads7846.rules
> UDEV rule will create a
symbolik link /dev/input/touchscreen
.
3.2.3.4.3.2. Adafruit PiTFT 3.5”¶
There are two versions of this display the older Assembled (sometimes called Original and the newer Plus.
PiTFT - Assembled 480x320 3.5” TFT+Touchscreen for Raspberry Pi (high resolution image)
PiTFT Plus 480x320 3.5” TFT+Touchscreen for Raspberry Pi (high resolution image)
While the newer Plus version can be used out of the box, The older Assembled requires hardware modifications, for details see below <assembled_hw_mods>.
The device is powered by +5V (for backlight LED) and +3.3V for TFT and touch controllers (should be taken from the E1 connector on Red Pitaya). Therefore all IO are 3.3V, so there are no conflicts.
Male connector pinout based on the Adafruit PiTFT 3.5” Touch Screen for Raspberry Pi schematic.
SPI TFT+touch |
pin |
pin |
SPI TFT+touch |
---|---|---|---|
SPI_SSs[1], touch |
|
|
GND |
SPI_SSn[0], TFT |
|
|
SPI_SCLK |
TFT D/C |
|
|
SPI_MISO |
GND |
|
|
SPI_MOSI |
touch pendown |
|
|
|
|
|
||
GND |
|
|
|
|
|
||
|
|
GND |
|
|
|
||
GND |
|
|
|
|
|
||
+5V |
|
|
+3.3V |
The 95-stmpe.rules
UDEV rule will create a
symbolic link /dev/input/touchscreen
.
A calibration file should be added to the system
99-calibration.conf
3.2.3.4.3.2.1. Block diagram¶
3.2.3.4.3.2.2. Assembled version hardware modifications¶
3.2.3.4.3.2.2.1. Explanation¶
The device is powered by a single +5V supply, and it generates 3.3V using an on board LDO. So 3.3V interfaces between Red Pitaya and the display have a different power source on each side. Since the two power sources do not wake up at the same time there is a race condition affecting touch controller SPI interface configuration during power-up reset. The LDO on the TFT board is faster then the switcher on Red Pitaya.
The STMPE610 touch controller datasheet (section 5.2) describes how CPOL/CPHA SPI configuration options depend on the power up reset state of a pair configuration pins.
CPOL_N (I2C data/SPI CS pin) |
CPOL |
CPHA (I2C address/SPI MISO pin) |
Mode |
---|---|---|---|
1 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
2 |
0 |
1 |
1 |
3 |
On the original setup (before pinctrl
device tree is applied)
for the E2 connector the touch chip SPI CS signal is used as I2C_SCK.
The SPI MISO pin is not affected by pinctrl
changes.
There appears to be a race condition between:
the configuration read event timed by the STMPE610 power coming directly from the +3.3V LDO (5V USB power connector)
and waking up of the 3.3V power supply on Red Pitaya, which powers the pull up resistors on the I2C pins and FPGA pull-ups for the SPI MISO pin on the E2 connector
In most cases the LDO on the TFT board would wake
before the switcher on Red Pitaya, so the CPOL_N
would be detected as 0
, which inverts the SPI clock polarity.
As an unreliable fix, the spi-cpol
attribute can be provided
in the device tree.
Note
It is not yet confirmed the power supply race condition is responsible for touch not working in certain setups, more testing might be necessary.
The provided oscilloscope image shows a 3.3V power up sequence and its relation to SPI configuration signals. It is evident configuration signals are stable.
Channels:
CPHA (the signal is low during power-up),
CPOL_N (the signal is linked to 3.3V with a pull-up and rising simultaneously),
3.3V (it takes about 1.5ms to ramp up from 0V to 3.3V).

3.2.3.4.3.2.2.2. Modifications¶
To avoid the power supply race condition, the LDO on the Assembled TFT board can be disabled, and instead +3.3V from Red Pitaya is used. This makes the Assembled power supply similar to the Plus version.
The next modifications have to be done:
Remove the +3.3V LDO, or at least rise the power output pin off the board.
Connect pin 1 on the JP1 connector to a +3.3V power line.
The next image shows a TFT board with a rised LDO power output and pin 1 on the JP1 connector connected to an unmounted resistor pad.

3.2.3.4.4. Debugging/Troubleshooting¶
3.2.3.4.4.1. pinctrl
, GPIO and interrupts¶
To see current pinctrl
settings try:
$ cat /sys/kernel/debug/pinctrl/pinctrl-maps
To see the status of GPIO signals try:
$ cat /sys/kernel/debug/gpio
To see the status of interrupts try:
$ cat /proc/interrupts
3.2.3.4.4.2. Touch¶
evtest
can be used to see low level touch events (and keyboard/mouse):
sudo apt-get install -y evtest