I've bought one of those cheap 2.4" TFT LCD resistive touchscreens, one of these:
It works great on my Arduino Uno, using the code from this github repository. Now I'm trying to get this to work on my Arduino Mega.
On the Arduino Uno, the LCD controller data lines are configured as:
data[0:7] = PORTB[0:1] | PORTD[2:7]
ie. data pins 8, 9, 2, 3, 4, 5, 6, 7 make up the LCD controller data lines.
On the Mega, the pin numbers are the same but the ports are configured differently, so that:
data[0:7] = ((PORTH >> 5) & 0x03) | ((PORTH << 3) & 0xc0) | ((PORTG >> 1) & 0x10) | ((PORTE >> 2) & 0x0C) | ((PORTE << 2) & 0x20)
I've rewritten the
TFTLCD::write8 functions accordingly.
The screen doesn't work, though. I've cut example code down to just resetting the LCD controller and reading the chip ID register, ie:
Tft.writeData(0); Tft.writeData(0); Tft.writeData(0); Tft.writeData(0); Tft.writeCommand(0); unsigned id = Tft.readData();
Now, 9 times out of ten, this obtains the correct device ID,
0x9325. But the other time, it obtains the device ID of
I initially suspected that this was due to the Mega running somewhat faster, but liberally sprinkling
delayMicroseconds(10) through the
readData functions doesn't seem to make any difference.
Is there something that I'm missing that is messing with the use of the PWM lines on the Arduino Mega as ordinary digital port pins?