Raspberry 3 and Pitft PLUS, Touch not working [SOLVED]
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Raspberry 3 and Pitft PLUS, Touch not working [SOLVED]

by gmbgmb on Tue Oct 18, 2016 1:07 pm

I recently bought the PiTFT Plus 480x320 3,5” touchscreen to add more capabilities to my aquarium controller raspberry pi project.

Unfortunately, in my brand new RPI3, no matter what I did, the screen worked (showing the console and X windows), but always without touch capabilities. I tried with the easy installation, the detailed install or downloading the Jessie-based PiTFT Resistive image from Adafruit web site, with no results.

Looking at the “dmesg" output, I always got:

[ 6.652386] spi spi0.1: setting up native-CS1 as GPIO 7
[ 6.654009] stmpe-spi spi0.1: unknown chip id: 0x0
[ 6.654044] stmpe-spi: probe of spi0.1 failed with error -22

It took me more than four days of hard work to find a solution (see below for the long story/troubleshooting guide for this error message if this is your case) but in my case the problem seems to be that the raspberry 3 is not able to transfer data with the touchscreen controller chipset (STMPE610) if the SPI is in mode 0 (the default). The good news is that is able to do so in any other of the three available modes (playing with CPHA & CPOL bits of SPI).

So, assuming you have done everything as instructed in Adafruit detailed guide, all you have to do is modify the way the SPI interface works with the STMP610 chipset doing the following:

[Successfully tested over the standard Raspbian Sept 2016 image after executing Adafruit's DIY installer script for the Resistive Touch 3.5" TFT]

Extract the source code for the pitft overlay with:
$ dtc -I dtb -O dts /boot/overlays/pitft35r-overlay.dtb -o pitft35r.dts

Save a copy, just in case:
$ sudo mv /boot/overlays/pitft35r-overlay.dtb /boot/overlays/pitft35r-overlay.dtb.orig

Edit the overlay description file
$ nano piftf35r.dts

and add "spi-cpha" method to the spi1 description, after the frequency:

pitft_ts@1 {
#address-cells = <0x1>;
#size-cells = <0x0>;
compatible = "st,stmpe610";
reg = <0x1>;
spi-max-frequency = <0x7a120>;

Compile the modified overlay back into place, with:
$ sudo dtc -@ -I dts -O dtb -o /boot/overlays/pitft35r-overlay.dtb pitft35r.dts

And reboot the system
$ sudo reboot

If everything goes well, dmesg should now show the STMPE610 device being detected:

[ 13.943487] spi spi0.1: setting up native-CS1 as GPIO 7
[ 13.948604] stmpe-spi spi0.1: stmpe610 detected, chip id: 0x811
[ 13.989833] input: stmpe-ts as /devices/platform/soc/3f204000.spi/spi_master/spi0/spi0.1/stmpe-ts/input/input2
[ 13.991584] spi spi0.0: setting up native-CS0 as GPIO 8

All needed device files (specially /dev/input/touchscreen) will be created and your touchscreen should work now..
Enjoy :-)

Posts: 15
Joined: Thu Jun 16, 2016 12:06 pm

Re: Raspberry 3 and Pitft PLUS, Touch not working [SOLVED]

by gmbgmb on Tue Oct 18, 2016 1:12 pm

DETAILED Explanation & Troubleshooting:
SYMPTOM: stmpe-spi spi0.1: unknown chip id: 0x0 in dmesg output.
The "stmpe-spi spi0.1: unknown chip id: 0x0" error is generated because the stmpe driver is trying to get the CHIP ID from the touchscreen controller and it fails, as seen from the driver source code, within function stmpe_chip_init:

ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID],
ARRAY_SIZE(data), data);
if (ret < 0)
return ret;

id = (data[0] << 8) | data[1];
if ((id & variant->id_mask) != variant->id_val) {

dev_err(stmpe->dev, "unknown chip id: %#x\n", id);
return -EINVAL;

Where EINVAL is errno number 22 also displayed in dmesg output.

For the chipset to be successfully identified, the driver tries to read two bytes from interface SPI1, at address 0x0 (the chipset CHIP ID register). The returned ID, as per STMPE610 specs should be 0x811, anything else will make the driver fail.
The problem is that there are many possible causes for this communication to fail:

0 - First of all, do you really HAVE a STMPE610 chip? If your touchscreen is capacitive, you don’t! So, most likely you are using the wrong kernel for your screen. Stop reading this and check the correct download page. If your TFT is resistive, keep reading.

1- The most likely cause for SPI (Serial Peripheral Interface) failing is a hardware problem. This protocol needs the following four pins to work: DATA IN, DATA OUT, CLK & CS (Chip Select). In Raspberry interface there are TWO CS connections, CS0 & CS1, corresponding to interfaces SPI0 and SPI1, and the piTFT uses both of them, one for the screen and the other for the touch controller.

So, if your are having SPI errors you should carefully check the connectivity of pins MOSI, MISO, SCLK, CE0 & CE1. In a Raspberry 3, that’s pins 19,21,23,24 & 26 respectively.

2- If the screen is displaying the console output or X-windows, then obviously SPI communication over SPI0 is working, so -if the cause is a bad connector- the problem can only be on pin CE1. Check it twice!.

3- If you have checked your hardware and still having the problem, you need to check for something else. You can test the SPI connection, but unfortunately the pitft overlay disables the SPI-DEV interface if installed, so the way to test if the SPI connection is working outside the pitft is as follows:
The SPI master driver is disabled by default on Raspbian. It should have already been enabled when installing your touchscreen, but check it again. To enable it, use raspi-config, or ensure the line dtparam=spi=on isn't commented out in /boot/config.txt, and reboot. If the SPI driver is correctly loaded, you should see the devices /dev/spidev0.0 & /dev/spidev0.1

- Be sure SPI is enabled and WITHOUT pitft overlay in /boot/config.txt (comment out the overlay loading)
- reboot.
- Check /dev/spidev0.0 & /dev/spidev0.1 are being created.

You can now check SPI1 connection to STMPE610 with the attached python code (it needs python developer modules, if not installed do so with “sudo apt-get -y install python-dev”). It tries to read three bytes from address 0x0 (and subsequent), For doing so you need to send 0x80 PLUS the requested address (so, it send 0x80, 0x81 and 0x82) through /dev/spidev0.1
If the STMPE610 is correctly detected, then congratulations: the problem with the touchscreen is software as it was mine, and the above solution is applicable.

With the python code you can test that -at least in my case- the touchscreen is correctly detected the using MODE=0x1, MODE=0x2 and MODE=0x3, but not in the default MODE=0x0.
I can only speculate about the reason, hardware or software for which the RPI3 interface is failing. As the different modes are pretty similar, changing CPHA & CPOL (clock polarity & phase) shouldn’t affect the software but the hardware behavior. Anyway, as it works with my workaround I am not going to employ more time investigating it, but someone should check the SPI drivers and RPI3 hw specs.

Finally, if the python program fails to detect the chip, you can also test SPI send and receive, removing the touchscreen, putting a wire between MOSI and MISO and running this test:
wget https://raw.githubusercontent.com/raspb ... dev_test.c
(1.12 KiB) Downloaded 22 times

Posts: 15
Joined: Thu Jun 16, 2016 12:06 pm

Re: Raspberry 3 and Pitft PLUS, Touch not working [SOLVED]

by adafruit_support_mike on Tue Oct 18, 2016 11:49 pm

Interesting.. thanks for posting the details of your solution!

Posts: 37362
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.