-->
Page 1 of 1

XPT2046 SPI problems

PostPosted: Mon Apr 04, 2016 1:53 pm
by Cross
Based on Paul's repo (https://github.com/PaulStoffregen/XPT2046_Touchscreen) I have tried to get the XPT2046 to work with an ESP8266 chipset. It looks like the data is there- but not arriving in the order I would expect. I understand that SPI reads are delayed and arrive with the next read but that does not match the results below.

My code to get x/y/z values is below
Code: Select all#define SPI_SETTING     SPISettings(2000000, MSBFIRST, SPI_MODE0)
void XPT2046_Touchscreen::update()
{
    SPI.beginTransaction(SPI_SETTING);
    digitalWrite(csPin, LOW);
    SPI.transfer(               0b10110001); //z1
    int16_t z1 = SPI.transfer16(0b11000001) >> 3; //z2
    int16_t z2 = SPI.transfer16(0b11010001) >> 3; //x
    int16_t  x = SPI.transfer16(0b11010001) >> 3; //x
    int16_t  x2= SPI.transfer16(0b10010001) >> 3; //y
    int16_t  y = SPI.transfer16(0b10010001) >> 3; //y
    int16_t  y2= SPI.transfer16(0) >> 3;
    digitalWrite(csPin, HIGH);
    SPI.endTransaction();

    Serial.printf("z1,z2, x,x, y,y = %d,%d,  %d,%d, %d,%d", z1, z2, x, x2, y, y2);
}


Typical output looks like this:
z1,z2, x,x, y,y = 2579,2342, 2431,1559, 1512,16

The z2 and x1 values are always close to each other, as are x2 and y1. The y2 value remains orders of magnitudes off.

Any ideas what's going wrong?

Re: XPT2046 SPI problems

PostPosted: Mon Apr 04, 2016 10:53 pm
by Cross
For reference, this is what the SPI capture looks like:
spi.png

Re: XPT2046 SPI problems

PostPosted: Tue Apr 05, 2016 1:25 am
by Cross
There's a bug in the SPI library causing this.
I have submitted a fix here: https://github.com/esp8266/Arduino/pull/1859

Re: XPT2046 SPI problems

PostPosted: Tue Apr 05, 2016 3:37 am
by schufti
did you try this XPT2046 library?
since it is based on the same spi lib and gives (most of the time*) plausible results, it would be worth a look.
* when the stylus is moved to fast, "ghost" points appear in tpdraw