Skip to content

Using SoftSPI with XPT2046 on a ESP32 #13

@JeanRenier

Description

@JeanRenier

Hi everybody,

For a project I like to use the TFT, the TS and the SD on the CYD (cheap yellow display) board at the same time. The hardware has a separate set of SPI ports for each, yet there is only 2 hardware SPIs available on the ESP32. Hence my attempt to use the softSPI for the TS, I used this library: https://github.com/PaulStoffregen/XPT2046_Touchscreen.

The SoftSPI works fine when using the loopback example provided, the typical SPI signals were seen on the oscilloscope.
The example touch screen test for the CYD (2-TouchTest.ino) on the hardware SPI (VSPI) of the ESP32 works fine also.
Combining the touch screen test with SoftSPI does not seem to work however, active signals on the CS, but none on the MOSI, MISO or SCK.

Here after the relevant lines of code, using Arduino IDE 1.8.19 with ESP32 core 2.0.11

#include <SPI.h>
#include <SoftSPI.h>
#include <XPT2046_Touchscreen.h>

#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33

SoftSPI mySPI(XPT2046_MOSI, XPT2046_MISO, XPT2046_CLK);
XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);

and in the setup part :
ts.begin(mySPI);

Tried also to initiate the SPI ports in setup with
pinMode(XPT2046_CS, OUTPUT);
digitalWrite(XPT2046_CS, HIGH);
pinMode(XPT2046_CLK, OUTPUT);
digitalWrite(XPT2046_CLK, LOW);
pinMode(XPT2046_MOSI, OUTPUT);
digitalWrite(XPT2046_MOSI, LOW);
pinMode(XPT2046_MISO, INPUT);
pinMode(XPT2046_IRQ, INPUT);

this should be redundant however, and initiate the softSPI explicitly with
mySPI.begin();

also redundant I think. Alas, to no avail, the 2-TouchTest.ino example modified for softSPI as here above compiles with no errors or warnings, but it does not work properly, the touch position being always x=0 and y=0.
Also there is no activity on the SPI ports MOSI or SCK to be seen on the oscilloscope, the CS port seems to work though.

Would be very grateful for any clue, pointer or suggestion.
Thanks and all the best, Jean.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions