Saturday, April 21st 2018, 11:25pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

jj8431

Beginner

Date of registration: Jul 15th 2016

Posts: 2

1

Friday, July 15th 2016, 2:46pm

Touch screen driver can read A/D value but not detecting touch ?

Hi I'm using STemWin 5.22, got stuck at the touch driver.

It's a 3.2" LCD with analog touch screen, the touch screen controller is XPT2046. I've already written the 4 hardware routines GUI_TOUCH_X_ActivateX(), GUI_TOUCH_X_ActivateY(), GUI_TOUCH_X_MeasureX(), and GUI_TOUCH_X_MeasureY(), and I've called the GUI_TOUCH_Exec() every 10ms from an interrupt.

When I tried to run the TOUCH_Calibrate.c in the Win32 simulator's /sample/tutorial folder, the code was stuck at the welcome screen because it couldn't detect the touch at the screen.

screenshot of TOUCH_Calibrate.c



Then I tried TOUCH_Sample.c, it ran and I could see the displayed "Analog input" was changing with the move of the pen, but the "Position" display was always 'x:0000 y:0000'. This could be an evidence that the A/D converter was working properly, it's also verified by written a small code of just calling the 4 hardware routine and display the return values. I've also checked the interface with a oscilloscope and I'm sure the touch screen chip was read every 10ms as required.
screenshot of TOUCH_Sample.c without pen touch
screenshot of TOUCH_Sample.c with pen touch.




I read the user manual again and again but still couldn't figure out the problem, could any body help or give some advice? Thanks.


the source code of TOUCH_Sample.c

/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
GUI_PID_STATE TouchState;
int xPhys;
int yPhys;

GUI_Init();
//
// Check if recommended memory for the sample is available
//
if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
GUI_ErrorOut("Not enough memory available.");
return;
}
GUI_CURSOR_Show();
GUI_CURSOR_Select(&GUI_CursorCrossL);
GUI_SetBkColor(GUI_WHITE);
GUI_SetColor(GUI_BLACK);
GUI_Clear();
GUI_DispString("Measurement of\nA/D converter values");
while (1) {
GUI_TOUCH_GetState(&TouchState); // Get the touch position in pixel
xPhys = GUI_TOUCH_GetxPhys(); // Get the A/D mesurement result in x
yPhys = GUI_TOUCH_GetyPhys(); // Get the A/D mesurement result in y
//
// Display the measurement result
//
GUI_SetColor(GUI_BLUE);
GUI_DispStringAt("Analog input:\n", 0, 20);
GUI_GotoY(GUI_GetDispPosY() + 2);
GUI_DispString("x:");
GUI_DispDec(xPhys, 4);
GUI_DispString(", y:");
GUI_DispDec(yPhys, 4);
//
// Display the according position
//
GUI_SetColor(GUI_RED);
GUI_GotoY(GUI_GetDispPosY() + 4);
GUI_DispString("\nPosition:\n");
GUI_GotoY(GUI_GetDispPosY() + 2);
GUI_DispString("x:");
GUI_DispDec(TouchState.x,4);
GUI_DispString(", y:");
GUI_DispDec(TouchState.y,4);
//
// Wait a while
//
GUI_Delay(100);
};
}

jj8431

Beginner

Date of registration: Jul 15th 2016

Posts: 2

2

Saturday, July 16th 2016, 12:38pm

Hi guys,

Thanks for viewing. I've found the problem and solved the problem. Hope this could also help you.

The reason for what was happening is emWin need the calibration function to be called before you can use the touch screen, even if you still don't have the calibration data! Segger never mentioned this in the manual and I thought I would run the calibrate code to get the values for the calibration and then add the calibration to the code, but the truth is if you don't call the GUI_TOUCH_Calibrate() routine at the initialization, the touch screen won't work. I guess you can call this a bug, or at least something missed in the user's manual.

So what I did was just use some theoretical data to call the calibration function at initialization, like:

GUI_TOUCH_Calibrate(GUI_COORD_X, 0, 240, 0, 4095);

and then get the real calibration value by running the calibrate program and go back to change the code.