0

I've bought one of those cheap 2.4" TFT LCD resistive touchscreens, one of these: 2.4" TFT LCD resistive touchscreens.

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::read8 and 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 0.

I initially suspected that this was due to the Mega running somewhat faster, but liberally sprinkling delayMicroseconds(10) through the writeData, writeCommand and 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?

| improve this question | | | | |
1

Never mind; this was me making a mess of the bit masking.

See this github repository for working code with Arduino Mega.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.