Author Topic: XPT2046 commands are different  (Read 1182 times)

0 Members and 1 Guest are viewing this topic.

Offline Jan AudioTopic starter

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
XPT2046 commands are different
« on: August 27, 2019, 12:45:39 pm »
Hi, the manual for this XPT2046 is incorrect to what i got.
I setup the channel for 000 or 010 to get X and Y axis, not 001 and 101 like the manual says.
I also setup for 8 bit mode, while i get 12 bit results.

I checked code examples online, they are the same as the manual.

Anyone has this also ?
Why would it be different then the manual ?
The XPT2046 is on this ILI9341 TFT that i got.

Its all working good, suppose this display has to be replaced, then maybe the version installed is not working this way.
btw : i have the 3.2 inch version ( no SPI version )
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14470
  • Country: fr
Re: XPT2046 commands are different
« Reply #1 on: August 27, 2019, 04:48:44 pm »
I took a look at an old project in which I used a touch panel with this controller.

I was using the following commands to read X and Y channels:
0xD0 for X (that's channel '101' indeed)
0x90 for Y (channel '001' indeed)

The '000' channel you mention is weird - according to the DS of the XPT2046 I have, that would be the temperature sensor reading?

Could you post a relevant extract of your code?
If you're sure your code is correct, could it also be that the controller is actually not an XPT2046?
 

Offline Jan AudioTopic starter

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: XPT2046 commands are different
« Reply #2 on: August 28, 2019, 11:26:27 am »
Yes, i looked : its a XPT2046 with another number underneath : 1624

Here is my code : ( X and Y might be swapped )

Code: [Select]

void ReadTouchScreen()
{
if( IRQ )
  {
  CS = 0;
 
  //SSPBUF = 0b11011011; // XPT2046 touch screen controller
           //X------- Start bit : 1 = start new command
           //-XXX---- Channel Select bits : 001 = X , 101 = Y
           //----X--- Mode : 0 = 12 bit conversion , 1 = 8 bit conversion
           //-----X-- SER/DFR : Single Ended/Differential Reference Select bit : 0 = differential
           //------XX Power Down Mode Select bits : 00 = Power-Down Between Conversions ( PENIRQ = Enabled  )
                                                 // 01 = Reference is off and ADC is on ( PENIRQ = Disabled )
                                                 // 10 = Reference is on and ADC is off ( PENIRQ = Enabled  )
                                                 // 11 = Reference is on and ADC is on  ( PENIRQ = Disabled ) Device is always powered
 
  SSPBUF = 0b10001011;
           //X------- Start bit : 1 = start new command
           //-XXX---- Channel Select bits : 010 = X , 000 = Y
           //----X--- Mode : 1 = 12 bit conversion , 0 = 8 bit conversion
           //-----X-- SER/DFR : Single Ended/Differential Reference Select bit : 0 = differential
           //------XX Power Down Mode Select bits : 00 = Power-Down Between Conversions ( PENIRQ = Enabled  )
                                                 // 01 = Reference is off and ADC is on ( PENIRQ = Disabled )
                                                 // 10 = Reference is on and ADC is off ( PENIRQ = Enabled  )
                                                 // 11 = Reference is on and ADC is on  ( PENIRQ = Disabled ) Device is always powered
 
  while( !BF );
  dummy = SSPBUF;
 
  SSPBUF = 0;
  while( !BF );
  temp1 = SSPBUF;
 
  SSPBUF = 0b10101011;
  while( !BF );
  temp2 = SSPBUF;
 
  sTemp = temp1;
  sTemp <<= 4;
  sTemp += temp2 >> 4;
  tX = sTemp;
 
  SSPBUF = 0;
  while( !BF );
  temp1 = SSPBUF;
 
  SSPBUF = 0;
  while( !BF );
  temp2 = SSPBUF;
 
  sTemp = temp1;
  sTemp <<= 4;
  sTemp += temp2 >> 4;
  tY = sTemp;
 
  DACOUT = tX >> 2;
 
  CS = 1;
  }
}

 

Offline Jan AudioTopic starter

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: XPT2046 commands are different
« Reply #3 on: August 28, 2019, 11:42:19 am »
Oh, by the way : the manual values : 001 and 101 give also a value,
only it is strange : its only the Y axis, with a bit of X axis mixed together, for both values.

I also cant get the Z axis to work, maybe there is some special trick needed ?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf