Hi All,
I have done a little bit more tests. Still no success. But I am able to share the code that I run that provides the expected results when the screen is plugged into a MEGA and does not provide the result when on a DUE.
In my "setup" function I call this "TestTouch" function of mine:
void testTouch()
{
pinMode(TFT_INT_PIN,OUTPUT);
Serial.println("Touch test Started");
while(1)
{
if (my_touch.Pressed()) // Note this function updates coordinates stored within library variables
{
Serial.print("Pressed RawX= "); Serial.print(my_touch.RawX()); // The values returned were captured when Pressed() was called!
Serial.print("[X= "); Serial.print(my_touch.X()); // The values returned were captured when Pressed() was called!
Serial.print("] | RawY"); Serial.print(my_touch.RawY()); // The values returned were captured when Pressed() was called!
Serial.print("[Y= "); Serial.print(my_touch.Y()); // The values returned were captured when Pressed() was called!
Serial.println("]");
}
else
{
Serial.println("Not pressed");
}
Serial.print(" PIN 44="); Serial.println(digitalRead(TFT_INT_PIN));
delay(1000);
}
}
The functions that I call are based on the Bodmer Touch library
/* Detects if the touch screen is currently pressed. Returns TRUE if pressed */
boolean TFT_Touch::Pressed(void)
{
Serial.print("TFT_Touch::Pressed [");
Serial.print("_xyswap="); Serial.print(_xyswap);
Serial.print(" | _xflip="); Serial.print(_xflip);
Serial.print(" | _yflip="); Serial.print(_yflip);
Serial.print("] ==> ");
// Get the raw contact coordinates
_xraw = _ReadAxis(_axis);
_yraw = _ReadAxis(!_axis);
Serial.print("_xraw="); Serial.print(_xraw);
Serial.print(" | _yraw="); Serial.print(_yraw);
Serial.print(" ==> ");
// Now double check the touch is still near the initial contact point
// also calculates the proper values for X & Y
// No issue in this part of code, the logics works
}
The issue i face is that I get meaning full readings with the MEGA and always zero with the DUE.
The works is done in these functions:
/* Reads one of the axis (XAXIS or YAXIS) raw coordinates. */
int16_t TFT_Touch::_ReadAxis(boolean Axis)
{
int Data;
digitalWrite(_CS, LOW);
digitalWrite(_CS, LOW); // HL CHANGE: as recommended by JM
delayMicroseconds(MICRO_WAIT);
if (Axis)
{
_OutputData(0x90);
}else
{
_OutputData(0xD0);
}
delayMicroseconds(MICRO_WAIT);
Data = _ReadData();
digitalWrite(_CS, HIGH);
digitalWrite(_Din, LOW);
return Data;
}
/* Reads the raw data from the touch screen */
// SPI mode 1 protocol: The base value of the clock is always 0 and data is always sent or received on the rising edge of the clock.
uint16_t TFT_Touch::_ReadData(void)
{
uint16_t Data = 0;
for (uint8_t index = 12; index > 0; index--) // Read the first 12 bits
{
digitalWrite(_Clk, HIGH); delayMicroseconds(MICRO_WAIT); digitalWrite(_Clk, LOW); delayMicroseconds(MICRO_WAIT); //_PulseClock();
Data += digitalRead(_Dout) << (index-1);
}
for (uint8_t index = 4; index > 0; index--) // Ignore the next 4 the first 12 bits
{
digitalWrite(_Clk, HIGH); delayMicroseconds(MICRO_WAIT); digitalWrite(_Clk, LOW); delayMicroseconds(MICRO_WAIT); //_PulseClock();
}
return Data;
}
/* Writes to the touch screen's configuration register */
void TFT_Touch::_OutputData(byte Data)
{
for (uint8_t index = 8; index > 0; index--)
{
digitalWrite(_Din, (Data >> (index -1)) & 1);
delayMicroseconds(MICRO_WAIT);
digitalWrite(_Clk, HIGH); delayMicroseconds(MICRO_WAIT); digitalWrite(_Clk, LOW); delayMicroseconds(MICRO_WAIT); //_PulseClock();
}
}
The doubling up of the "digitalWrite(_CS, LOW)" is something I did on the advices of JM. I believe I understand the rationale (making sur that the touch screen is 100% aware of the communication being started). but this does not appear to work.
I have also pepered the code with "delayMicroseconds(MICRO_WAIT);" in case the DUE was going too fast for the Touch Screen to follow and I have tried many different values for the delay (1,3,6,20,100 micro-seconds).
None of this has worked.
With the MEGA I get these results:
###################### PROGRAM STARTED ###############
Touch test Started
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=1518 | _yraw=2158 ==> Pressed RawX= 1518[X= 185] | RawY2158[Y= 381]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=1512 | _yraw=2158 ==> Pressed RawX= 1512[X= 185] | RawY2158[Y= 381]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=538 | _yraw=1793 ==> Pressed RawX= 538[X= 85] | RawY1793[Y= 446]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=3191 | _yraw=1524 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=1033 | _yraw=1730 ==> Pressed RawX= 1033[X= 135] | RawY1730[Y= 458]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=676 | _yraw=3645 ==> Pressed RawX= 676[X= 99] | RawY3645[Y= 112]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=3061 | _yraw=624 ==> Pressed RawX= 3061[X= 343] | RawY624[Y= 658]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=2073 | _yraw=670 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=609 | _yraw=814 ==> Pressed RawX= 609[X= 92] | RawY814[Y= 623]
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=4095 ==> Not pressed
PIN 44=1
And with the DUE all I get is this:
###################### PROGRAM STARTED ###############
Touch test Started
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=0 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=0 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=0 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=0 ==> Not pressed
PIN 44=0
TFT_Touch::Pressed [_xyswap=0 | _xflip=0 | _yflip=1] ==> _xraw=0 | _yraw=0 ==> Not pressed
PIN 44=0
And I really dont know why.
I cannot do any more tests for now as my compiler has stopped working for the DUE.
Some internal error I cannot fathom out.
I will create another post for this.
Regards
H