XPT2046 touch IRQ issue

Status
Not open for further replies.
I just got the touch screen from the pjrc store. It is working great connected to a teensy 3.2.

Touch works just fine as long as I dot not enable IRQ usage.

For example with the ILI9341Test example (teensyduino), touch works as long as I do not use IRQs. I tried both the default IRQ 2 and using IRQ on digital pin 6.
I have connected a LED to the IRQ pin, when I touch the screen the LED lights up. So hardware wise the IRQ is working.

I am on arduino IDE 1.6.8 with teensyduino 1.28.
When running the below code with IRQs enabled, the serial print for 'Touch event' never occurs. WIthout IRQs enabled it works fine.

Code:
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <XPT2046_Touchscreen.h>
#include <SPI.h>

#define CS_PIN  8
#define TFT_DC  9
#define TFT_CS 10
// MOSI=11, MISO=12, SCK=13

//XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN  6 // Was 2
//XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255);  // Param 2 - 255 - No interrupts
XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling

ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(38400);
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  ts.begin();
  while (!Serial && (millis() <= 1000));
}

boolean wastouched = true;

void loop() {
  boolean istouched = ts.touched();
  if (istouched) {
    Serial.println("Touch event");
    TS_Point p = ts.getPoint();
    if (!wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_YELLOW);
      tft.setFont(Arial_60);
      tft.setCursor(60, 80);
      tft.print("Touch");
    }
    tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
    tft.setTextColor(ILI9341_GREEN);
    tft.setFont(Arial_24);
    tft.setCursor(100, 150);
    tft.print("X = ");
    tft.print(p.x);
    tft.setCursor(100, 180);
    tft.print("Y = ");
    tft.print(p.y);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.println(p.y);
  } else {
    if (wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_RED);
      tft.setFont(Arial_48);
      tft.setCursor(120, 50);
      tft.print("No");
      tft.setCursor(80, 120);
      tft.print("Touch");
    }
    Serial.println("no touch");
  }
  wastouched = istouched;
  delay(100);
}
 
I dug a little further to find the cause of T_IRQ not working. I have added some Serial.println debug statements to XPT2046_Touchscreen.cpp (hardware/teensy/avr/libraries/XPT2046_Touchscreen).
The isrPin() function is never called so isrWake is never set to true. So somehow interrupts are not working for me :confused:
Help would be appreciated!
 
Status
Not open for further replies.
Back
Top