Go Down

Topic: LCD interface intermittent on Mega, works on Uno (Read 37 times) previous topic - next topic

tomkcook

Sorry if this is the wrong forum for this.  I've bought one of those cheap 2.4" TFT LCD resistive touchscreens. as near as I can tell identical to this:



I've got it working (at least the screen; haven't tried the touchscreen or SD slot yet) using the code from this github repository.  Now I'm trying to get it to work with an Arduino Mega.

The main difference that I can see is in the port mappings of the data bus.  The shield has an 8-bit data bus, with bits[0:7] mapped to digital pins 8, 9, 2, 3, 4, 5, 6, 7.  On the Uno, that works out to:

Code: [Select]
data = (PIND & 0xFC) | (PINB & 0x03);

AFAICT, on the Mega, that works out to:

Code: [Select]
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, as well as TFTLCD::setReadDir and TFTLCD::setWriteDir.  The screen doesn't work, though.  I've cut the example code down to just resetting the LCD controller and reading the chip ID register, ie:

Code: [Select]
Tft.writeData(0);
Tft.writeData(0);
Tft.writeData(0);
Tft.writeData(0);

Tft.writeCommand(0);
unsigned id = Tft.readData();


About four times out of five, this obtains the correct ID, 0x9325.  But the other time out of five, it returns 0.  I initially suspected this was due to the Mega running faster, but a liberal sprinkling of
Code: [Select]
delayMicroseconds(10) has made no 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?


tomkcook

Never mind; this was me making a mess of the bit masking.  See this repository for working Mega support.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy