XPT2046 SPI problems
Posted: Mon Apr 04, 2016 1:53 pm
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
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?
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?