Hello,
I am experiencing a problem with the XPT2046 touch controller when using hardware SPI in Flowcode 11.
Hardware
- LCDWiki E32R40T
- ESP32-32E
- Display controller: ST7796S
- Touch controller: XPT2046
- Display resolution: 320 x 480
The display and touch controller share the same SPI bus, as intended by the board manufacturer:
- MOSI: GPIO13
- MISO: GPIO12
- CLK: GPIO14
- Display CS: GPIO15
- Touch CS: GPIO33
- Touch IRQ: GPIO36
Flowcode configuration
Both components are configured to use:
- Hardware SPI Channel 1
- Identical SPI prescaler, tested at 2 MHz and lower
- Separate CS pins
- XPT2046 analogue mode: Differential
- Display and touch orientation: 1
Problem
When both components use hardware SPI:
- The ST7796S display works correctly.
- The XPT2046 touch controller produces incorrect results.
- SampleSensor() sometimes returns 254 even when the screen is not being touched.
- The returned X/Y coordinates are completely incorrect.
When I change the XPT2046 component to software SPI:
- Touch detection works correctly.
- The X/Y coordinates are correct.
- However, the ST7796S hardware-SPI display then stops working because both devices share GPIO12, GPIO13 and GPIO14, and the software-SPI component appears to reconfigure these pins.
I also tested:
- Different initialization orders
- Both components using software SPI
- Lower SPI clock frequencies
- Single Ended and Differential analogue modes
These tests did not provide a usable configuration for both devices.
Similar existing report
I found a very similar report involving an ESP32 CYD and XPT2046:
viewtopic.php?t=3564
In that case, hardware SPI also produced incorrect coordinates, while software SPI solved the touch problem.
Software SPI is not a viable workaround for the E32R40T because the ST7796S display and XPT2046 are permanently connected to the same physical SPI pins.
The board works with the manufacturer's software, so the hardware and wiring appear to be correct.
Could Matrix please investigate whether the XPT2046 component has a problem using ESP32 hardware SPI, especially when sharing the SPI channel with a graphical display component?
I can attach my complete Flowcode test project for reproduction.
Thank you.
XPT2046 wrong coordinates using shared hardware SPI on ESP32
-
Kimba
- Posts: 2
- http://meble-kuchenne.info.pl
- Joined: Tue Nov 21, 2023 5:21 pm
-
BenR
- Matrix Staff
- Posts: 2289
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 634 times
- Been thanked: 840 times
Re: XPT2046 wrong coordinates using shared hardware SPI on ESP32
Hello,
Please can you attach your project file for me to investigate further.
The main thing I am assuming is the SPI mode for the display and the touch sensor are different and that's what is causing the problem.
Please can you attach your project file for me to investigate further.
The main thing I am assuming is the SPI mode for the display and the touch sensor are different and that's what is causing the problem.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: XPT2046 wrong coordinates using shared hardware SPI on ESP32
In the Flowcode simulation, the touch areas assigned to the Display Manager objects work correctly. I have not verified the exact numerical X/Y values in simulation.
The problem occurs on the physical ESP32 hardware.
Please let me know if you need any further tests on the E32R40T hardware.
Regards,
A.C
The problem occurs on the physical ESP32 hardware.
Please let me know if you need any further tests on the E32R40T hardware.
Regards,
A.C
- Attachments
-
- E32R40T_E32N40T_Specification_V1.0.pdf
- (1.96 MiB) Not downloaded yet
-
- ESP32_4inch_ST7796_XPT2046_Display_Test.fcfx
- (31.12 KiB) Downloaded 1 time
- (view online)