I'm in the latter stages of a large project involving 8 different kinds (not qty) of hardware attached to a mega2560. I ran into a maddening bug with the touch input on this display, I found the touch interface stopped working COMPLETELY, requiring me to POWER DOWN the arduino board for several seconds to reset the touch input. And then it seemed to stop working almost immediately after I resumed development.
The problem boiled down to this: even in the simplest of sketches, UTouch's dataAvailable would stop returning false, and would produce only -1,-1 on reads. This appeared to be somewhat random but extremely frequent. I was just starting the touch interface so it was a huge problem. Removing all the hardware didn't help. Finally, reverting back to bare-bones TFT/shield and the touch examples, the problem remained. As well as with a different mega, different shield, and different TFT. So it's not a hardware problem.
Driver debugging commenced. After several hours, I was finally getting a consistent problem. I had a sketch that was only a screen long, that would run fine until I opened a serial window, DID NOT touch the screen, and closed the serial window. When the arduino came back up from the serial closing, the touch was dead until I pulled the USB cable for a bit.
Continuing to distill the problem, the sketch now very small, it swapped behavior, and opening/closing the serial port was not a problem. However, uploading would kill the touch every time and require pulling the USB. When reconnected, the touch worked, until I uploaded again.
After trying MANY things, I thought this seems like a problem with the sketch starting over, and resetting the touch again. So I go into the UTouch driver and comment out sbi(P_IRQ, B_IRQ);
This allowed me to upload and open/close serial windows again without the touch going out. I still have seen one or two cases of it going out, but it's not continuous like it had been.
I'm not familiar with use of "ports" to interact with hardware, so why this works (or why this fails to just plain completely disable the touch) is a mystery to me. But I'm sure a few here are smart enough to figure it out so I thought I'd share. As I spent quite a bit of time with google trying to find out why my serial window was shutting down my touch, and finding only hundreds of threads of people trying to stop serial from rebooting their arduino.
FWIW, I found out much to my surprise that another way to recover the touch was to unplug the TFT from the shield. Not too safe I know, but when I plugged it back in, it worked immediately WITHOUT rebooting the arduino, meaning it worked without any init code being sent to it. Which is what gave me the idea to try to disable some of the inits, thinking maybe it doesn't like getting them twice in one bootup.
I am attaching the smallest sketch I have that reliably kills the touch when you upload it after running it. (so the second run you will see it fails to fast-flash LED13 when you touch it, forcing you to kill power to the TFT)
again you will need to comment out "sbi(P_IRQ, B_IRQ);" in UTouch.cpp if you want it to work properly.
db.ino (2.15 KB)