Touchscreen 3.2" (SSD1289 & XPT2046) sporadically work on MEGA 2560.

Hi all,
I'm using a LCD TFT display for an application. It is the quite famous TFT_320QVT, a 3.2" TFT LCD display based on SSD1289 and XPT2046 controllers.
I mount it over an Arduino MEGA 2560 using an adaptor shield (to adjust the voltage level to 3.3 V), the LCD Mega shield v2.2.
SW side i use the UTFT libraries, UTouch and its the example code, UTouch_ButtonTest.

The display work very well but the touch sometimes does not start to work. e.g. if the touch work at start, then it continue to work up to shut down. Likewise, if the touch does not work at start, then it does not begin to work during runtime (I need to power off and on the device but sometimes it still does not work for some minutes). I don't know when it work or doesn't work! It seems random.

Arduino is powered by an external 7.1 V (12 V 1 A regulated to 7.1 V by LM317) and internal regulated +5 V power line is exactly 4.96 V thus it's a good power supply: ripple is <80mV and Vdc is stable.
I measured SPI signal of touch controller (D_CLK, and D_OUT that's probably MISO of XPT2046) with my oscilloscope and I can see some good signals when touch work and I cannot see anything (0V line) when touch does not work.

I try a different Arduino MEGA 2560 (a clone) and a different LCD module but the problem still alive!
I'm quite sure the SW is ok because I use the example's code anyhow the problem still exist with my application custom code.

What is the source of the problem? HW, SW?
Any ideas ?

Examine the soldering with a magnifying glass. If the TFT and the Touch work sometimes, you must have the correct shield HW and software constructor()s.

As a general rule, shields are very reliable but sometimes you get a bad joint. If you had trailing wires, I would have about 50% confidence in reliability. Shields should be 99% reliable.

David.

Examine the soldering with a magnifying glass.

Already done. They seems ok.
Furthermore I've soldered some wires to check SPI clock at Arduino output (pin D6, before the shield). Also at Arduino pins the signal is flat when the touch controller is not working. So I think it's a SW problem but the example code work for everyone... :confused:

SPI clock only operates in bursts as a transfer is made, 8 clocks per byte transferred.
You could write a simple test to just do transfers and confirm the pin is working
[code]
#include <SPI.h>
void setup(){
pinMode (10, OUTPUT); // SS
SPI.begin();
}
void loop(){
SPI.transfer(0x55); // should see 4 MHz clocks on SCK pin and MOSI pin toggling
}

[/code]

This is a long running issue with Sainsmart hardware. I appreciate your TFT shield is not Sainsmart but bear with me!

A long time ago, I was doing a project for a friend, and he had Coldtears Electronics TFT shield and 7" display. And he started having intermittent Touch related problems on a MEGA based setup, and so did I. So the hardware was different but the problems were common.

Upload, work, upload not work, upload not work, upload work......etc.......... upload work, power off, power on, not work........... etc....... No real pattern other than, sometime yeah, sometimes nah.

Back then......... Using IDE V1.0.6 made the touch functions reliable and consistent, the problems came back when using IDE V1.5.x or later.

If you are ONLY using a MEGA, then I would suggest you try IDE V1.0.6....... if that cures your problems yippee.... But if you would like to use a later version of the IDE then you could try changing your Arduino\Libraries\UTouch\hardware\avr\HW_AVR.inc to look like this :-

void UTouch::touch_WriteData(byte data)
{
	byte temp;

	temp=data;
	cbi(P_CLK, B_CLK);

	for(byte count=0; count<8; count++)
	{
		if(temp & 0x80)
			sbi(P_DIN, B_DIN);
		else
			cbi(P_DIN, B_DIN);
		temp = temp << 1; 
		cbi(P_CLK, B_CLK);                
		sbi(P_CLK, B_CLK);
	}
}

word UTouch::touch_ReadData()
{
	word data = 0;

	for(byte count=0; count<12; count++)
	{
		data <<= 1;
		sbi(P_CLK, B_CLK);
		cbi(P_CLK, B_CLK); 
		delayMicroseconds(1); //// added to get more stable readings?   
		if (rbi(P_DOUT, B_DOUT))
			data++;
	}
	return(data);
}

No promises, but worth a shot.

Regards,

Graham

Thank you, ghlawrence2000! Now I've uploaded the code with the delay you've suggested in the file HW_AVR.inc and the touch response seems more reactive. I hope the touch finally work forever. I will let you know if it work also the following days.
Thank you all!! :slight_smile: :slight_smile:

3 days and several test. It seems the solution proposed by ghlawrence2000 (delay in file HW_AVR.inc) work well on my LCD/MEGA2560!!

I had some problem with 7 Inch TFT LCD and it's Touchscreen.
The controller is XPT2046 like your TFT.
You have change something on your shield(if you use) or buffer.
All pin on the LCD work with the 3.3 Volts and has VinHigh and VinLow according to Vcc(+3.3V) but Mega2560 digital I/O pin's work with the +5V level.
Use some buffer to mach this two level then you can see your touch is grate :slight_smile:

bahman89:
I had some problem with 7 Inch TFT LCD and it's Touchscreen.
The controller is XPT2046 like your TFT.
You have change something on your shield(if you use) or buffer.
All pin on the LCD work with the 3.3 Volts and has VinHigh and VinLow according to Vcc(+3.3V) but Mega2560 digital I/O pin's work with the +5V level.
Use some buffer to mach this two level then you can see your touch is grate :slight_smile:

Yes you are correct, there does need to be level translation when using with a MEGA. However, the situation being discussed here, is that even when this has been accounted for, there still appears to be issues with touch functions on some displays when used with a MEGA. The solution I gave, copes with those occasions.

Regards,

Graham