MCUfriend TFT LCD pin re-assignment

@david_prentice if you are out there, help! I will be forever thankful. I will even name my firstborn after you!

HOLY FLUKE im stuck ! , I modded the mcufriend_shield file , it works! But only if I just use ,say PORTA.
BUT the dude who did the layout of the board i'm programming for, (he doesn't know how to code) and he connected
PC7 as LCD_D0,
PA0 as LCD_D1,
PA1 as LCD_D2,
PA2 as LCD_D3,
PA3 as LCD_D4,
PA4 as LCD_D5,
PA5 as LCD_D6,
PA6 as LCD_D7,

I KNOW ITS INSANE! PA7 is not even used, Wtf right?

I wrote the follwing code, and tested the output , the bitwise seems correct the I/O output is correct , it compiles no errors! but dislplay just doesn't work.

//################################### MEGA2560

#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)       //regular UNO shield on MEGA2560
#define RD_PORT PORTF
#define RD_PIN  0
#define WR_PORT PORTF
#define WR_PIN  1
#define CD_PORT PORTF
#define CD_PIN  2
#define CS_PORT PORTF
#define CS_PIN  3
#define RESET_PORT PORTF
#define RESET_PIN  4


#define AMASK         0x7F
#define CMASK         0x80
 

#define write_8(x)   { \
                    PORTA &= ~AMASK; \
                    PORTC &= ~CMASK; \
                    PORTA = (x>>1);  PORTC = ((0x01 & x) <<7) ;        }


#define read_8()     ( ((PINC & CMASK) >> 7) | ((PINA & AMASK)<< 1) )

                   
#define setWriteDir() { DDRA = 0xFF;    DDRC = 0xFF; }//JUST FOR TESTING IM NOT MASKING

#define setReadDir()  { PORTC &= ~CMASK;    PORTA &= ~AMASK; }
                               


#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

Your setReadDir() macro is wrong.
Your setWriteDir() is wrong but it should work.
Everything else looks ok.

First off. You should set the defines in LCD_ID_readreg sketch. Make sure that your wiring is correct.
When the wiring is verified, make a nice cup of tea. Correcting your two macros will take less than half a biscuit.

Note that this should be in mcufriend_special.h

David.

thank you for your reply David! the port direction error you caught was a hasty copy paste error,
but it was correctly written in the file!

I ran the LCD_ID_readreg as you suggested and because it almost always worked, I figured out it was a dirty solder on that PC7 pin. The worst type of problem: not broken, but not working.

You sir are my hero!

I am trying to use the 3.5 MCUFriend tft for radio project and having sda scl conflicts. As I dont need the touch screen , is it possible to shift RS CS and RST towards pin A0 A1 and A2 and to free pins A3 and A4. Thanks

David Sir, Thanks a lot for your hard work.
Do we need to rewire the tft sheild and cant use as such after changing the pin with help of Special.h.

LCD_RST pin is A4 on the shield.
I2C SDA pin is A4 on a Uno.

You can only use I2C on a Uno if you make a hardware mod to the Shield.
I only advise this for a MIPI-style controller e.g. ILI9341.

The easiest solution is to change to a MEGA2560 or DUE.
Since you are using a 3.5 inch shield, it is the same size as a MEGA2560.
So it will physically fit in any project.

Personally, I would NEVER buy the current 3.5 inch Mcufriend shield which omits the AMS1117 regulator.
The Uno or Mega can not provide backlight current from the wimpy 3.3V pin.
The Due can provide backlight current because it has a bigger 3.3V regulator.

David.

Hi David,

Sorry for my ignorance, but if I get it right, doesn't the MCUfriend library support display tft breakout?

Why would the LCD_WR and LCD_RD pins, for example, not exist on the breakout board?

Excuse me if I'm wrong!

Thanks

God invented Shields that plug into the Arduino.

The MCUFRIEND_kbv library was designed to support Shields plugged into regular Arduino headers.

The Devil might persuade you to hand-wire the Shield to random pins on a random Arduino.
I do not advise it. Especially since Shields mate nicely with Arduino headers.

Most importantly, a Shield has known wiring. A shield is mechanically and electrically robust.

Yes, you can write a SPECIAL to match your random wiring.
I have made several custom Adapters by soldering custom wiring on Protoshields. This is mechanically and electrically robust.

David.

Ok, not wanting to bother you, could you tell me what would be the wiring for a common breakout display, with or without Touch for the MCUFRIEND library?

It's just that I have some breakout displays and would like to enjoy them with your library!

Thanks

I bended the a4 and joined it with uno reset pin and its working fine now. It sooved the reset pin issue. Now i need audio input at analogue pin. I tried it at a5 which was free of MCUFriend shield but its beiang scl sda it does conflict with i2c. So i need one more analogue free pin. I dont need touch. So how can i get one more analogue pic free preferably a0 or a1 plz.

Rnk:
I bended the a4 and joined it with uno reset pin and its working fine now. It sooved the reset pin issue. Now i need audio input at analogue pin. I tried it at a5 which was free of MCUFriend shield but its beiang scl sda it does conflict with i2c. So i need one more analogue free pin. I dont need touch. So how can i get one more analogue pic free preferably a0 or a1 plz.

Buy a Uno clone with SMD chip. These have two extra Analog pins A6, A7.

David.

Dancopy:
Ok, not wanting to bother you, could you tell me what would be the wiring for a common breakout display, with or without Touch for the MCUFRIEND library?

It's just that I have some breakout displays and would like to enjoy them with your library!

Thanks

Buy a regular Mcufriend Shield. It plugs into the Arduino header sockets.

The shield has the pinout printed on the pcb. If you want to use a breakout display you connect the pins exactly the same as the printed pinout on the shield via level shifters as appropriate.

David.

david_prentice:
Buy a Uno clone with SMD chip. These have two extra Analog pins A6, A7.

David.

I guess 8nhave uno clone but when i plug audio in then these get conflicts with i2c signla and i get no audio signal input there.

Post a link to the clone on your desk. e.g. Ebay sale

You might need to solder header pins for A6, A7.

Post a schematic of your wiring connections. e.g. pencil drawing. post photo of drawing.

Are you using a proven Tutorial sketch? Post link or attach project e.g. in ZIP file.

David.

I just got a nano and in need of extra analog pins i shifted MCUFriend tft sheild on nano. Now lcd is kind of staying wagely lit. Its 9388 as i checked its id on uno but on nano it show no id at all. Wires seems all tight and rechecked. It just serial display id =0x0. kindly suggest.

Buy a Uno clone. They are not expensive.

david_prentice:
Buy a regular Mcufriend Shield. It plugs into the Arduino header sockets.

David.

Could you link to this Mcufriend Shield from Aliexpress or eBay?

But it should work on nano.the lcd was showing id
4288 and was working on uno, now it is not working with nano. I checked all the connections. Does it need any change in library to make it work on nano or some register hardware tweeks? Thanks

I do not support any controllers with ID = 4288 (0x10C0)

You do not need any software changes for Nano. Simply wire all the Shield pins to the corresponding 3.3V, 5V, D2-D13 and A0-A4.

In fact I have two Nano Adapter boards. i.e. Arduino headers with a socket for Nano.
I can run regular Shields with Nano-328P, LGT8F328P, NANO-EVERY, NANO-THINARY

I strongly recommend that you buy a proper Uno clone i.e. with Arduino header sockets.
Or buy a Nano Adapter Board. i.e. with Arduino header sockets.

The current Mcufriend Shield design is WRONG. It powers the backlight from the Arduino 3.3V pin which is WRONG. The original Shields had a 3.3V regulator on the display pcb which was powered by the 5V pin.
The Nano 3.3V pin comes from the USB chip. It can not supply much current.

David.

Thanks for your kind response. I fixed the loose connections amd got it back on nano. Now the screen seems working but shows false colors and it doesnt kind of refresh. The sound bar i made on it keep lit and flashes but it nvr go all black when no sound. Thanks again.