STM32H750 & XPT2046 Touchscreen in Arduino IDE
Posted: Fri Oct 20, 2023 8:33 am
I was using Teensy 3.2 with 2.8" 240x320 TFT Touchscreen in this configuration
https://www.pjrc.com/store/display_ili9341_touch.html
and it was working OK.
Now I`m going to use STM32H750/743 processor with this display, but I`m not able to make touch work.
Display is working OK, but I`m receiving on touch
Pressure = 4095, x = 8191, y = 8191
from serial ( USB ). Configuration is the same as above Teensy: both ILI9341 and XPT2046 share the same SPI1, of course with different CS pins.
I`m using Adafruit libraries for display and PaulStoffregen`s XPT2046_Touchscreen library.
Does anyone have some tip?
Thanks.
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
#include <Fonts/ContextRepriseCondensedSSiCondensed16pt7b.h> //vyherca
#include <Fonts/ContextRepriseCondensedSSiCondensed45pt7b.h> //vyherca
#define CS_PIN PIN_A3 //PC3_C
#define TFT_CLK 8 //PB3
#define TFT_MOSI 6 //PB5
#define TFT_MISO 7 //PB4
#define TFT_DC PIN_A2 //PC2_C
#define TFT_CS 20 //PA15
#define TFT_RST 44 //PE4
#define TIRQ_PIN 15 //PD1
int DispDrv = PD0;
int DisplayOrientation = 1;
//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
XPT2046_Touchscreen ts(CS_PIN);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
void setup() {
SysClkHalfSpeed();
pinMode ( DispDrv, OUTPUT );
digitalWrite(DispDrv, HIGH);
Serial.begin(38400);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
ts.begin();
ts.setRotation(1);
while (!Serial && (millis() <= 1000));
}
boolean wastouched = true;
void loop() {
boolean istouched = ts.touched();
if (istouched) {
TS_Point p = ts.getPoint();
if (!wastouched) {
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(&ContextRepriseCondensedSSiCondensed45pt7b);
tft.setCursor(60, 80);
tft.print("Touch");
}
tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.setFont(&ContextRepriseCondensedSSiCondensed16pt7b);
tft.setCursor(100, 150);
tft.print("X = ");
tft.print(p.x);
tft.setCursor(100, 180);
tft.print("Y = ");
tft.print(p.y);
Serial.print("Pressure = ");
Serial.print(p.z);
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(&ContextRepriseCondensedSSiCondensed16pt7b);
tft.setCursor(120, 50);
tft.print("No");
tft.setCursor(80, 120);
tft.print("Touch");
}
Serial.println("no touch");
}
wastouched = istouched;
delay(100);
}
https://www.pjrc.com/store/display_ili9341_touch.html
and it was working OK.
Now I`m going to use STM32H750/743 processor with this display, but I`m not able to make touch work.
Display is working OK, but I`m receiving on touch
Pressure = 4095, x = 8191, y = 8191
from serial ( USB ). Configuration is the same as above Teensy: both ILI9341 and XPT2046 share the same SPI1, of course with different CS pins.
I`m using Adafruit libraries for display and PaulStoffregen`s XPT2046_Touchscreen library.
Does anyone have some tip?
Thanks.
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
#include <Fonts/ContextRepriseCondensedSSiCondensed16pt7b.h> //vyherca
#include <Fonts/ContextRepriseCondensedSSiCondensed45pt7b.h> //vyherca
#define CS_PIN PIN_A3 //PC3_C
#define TFT_CLK 8 //PB3
#define TFT_MOSI 6 //PB5
#define TFT_MISO 7 //PB4
#define TFT_DC PIN_A2 //PC2_C
#define TFT_CS 20 //PA15
#define TFT_RST 44 //PE4
#define TIRQ_PIN 15 //PD1
int DispDrv = PD0;
int DisplayOrientation = 1;
//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
XPT2046_Touchscreen ts(CS_PIN);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
void setup() {
SysClkHalfSpeed();
pinMode ( DispDrv, OUTPUT );
digitalWrite(DispDrv, HIGH);
Serial.begin(38400);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
ts.begin();
ts.setRotation(1);
while (!Serial && (millis() <= 1000));
}
boolean wastouched = true;
void loop() {
boolean istouched = ts.touched();
if (istouched) {
TS_Point p = ts.getPoint();
if (!wastouched) {
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(&ContextRepriseCondensedSSiCondensed45pt7b);
tft.setCursor(60, 80);
tft.print("Touch");
}
tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.setFont(&ContextRepriseCondensedSSiCondensed16pt7b);
tft.setCursor(100, 150);
tft.print("X = ");
tft.print(p.x);
tft.setCursor(100, 180);
tft.print("Y = ");
tft.print(p.y);
Serial.print("Pressure = ");
Serial.print(p.z);
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(&ContextRepriseCondensedSSiCondensed16pt7b);
tft.setCursor(120, 50);
tft.print("No");
tft.setCursor(80, 120);
tft.print("Touch");
}
Serial.println("no touch");
}
wastouched = istouched;
delay(100);
}