problem with PJRC TFT touchscreen and Teensy LC

I have a 3.2" PJRC color 320x240 display connected to a Teensy LC, with the TFT display and touchscreen both connected to the default SPI port (pins 11, 12, 13) and separate pins for CS (10 and 8, respectively). The display DC is connected to 20.
If I just display on the screen, it works.
If I display nothing and read from the touchscreen, it works.
But if I read the touchscreen and then display something once on the screen, the touchscreen starts generating random touches forever!
I'm powering the Teensy from USB, and the screen from the 5V pin on the Teensy. I have decoupling caps on the power to the screen.
Here's the test program.
Code:
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
//#include <ILI9341_t3.h>  // not for Teensy LC
#include <XPT2046_Touchscreen.h>


#define TS_CS 8
XPT2046_Touchscreen ts(TS_CS);


#define TFT_CS 10
#define TFT_DC 20
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC); // not for Teensy LC


void setup(void) {
   Serial.begin(9600);
   tft.begin();
   if (ts.begin()) Serial.println("Touchscreen started.");
   tft.fillScreen(ILI9341_BLUE); 
   ts.getPoint(); delay(300); ts.getPoint(); // discard bogus touches
   delay(300);}


void loop() {
   if (ts.touched()) {
      TS_Point p = ts.getPoint();  // get raw point
      Serial.print(p.x); Serial.print(", ");
      Serial.print(p.y); Serial.print(", ");
      Serial.println(p.z);
      tft.drawCircle(100, 100, 10, ILI9341_WHITE);  // causes touchscreen to go crazy!
      delay(300); } }
I've tried it with two different displays and get the same behavior. Any idea what's going on, or what I should look for?
 
Well, you were exactly right in your suggestion that a MISO conflict was the cause of the problem: the touchscreen was always driving it.
But I'm embarrassed to admit that it was my screwup, not the design of the touchscreen. As I was wiring in the tri-state buffer suggested by the article, I discovered that I had originally wired the touchscreen CS to pin 9 on the Teensy instead of pin 8. That's a high-impedance input, which I guess the touchscreen interpreted as low. But then I don't understand why the display would have worked at all.
In any case, with the correct CS wiring both devices coexist and are working fine. Thank you for your help, and sorry for the false alarm!
 
Back
Top