mcu_friend 3.5" & chipkit uno32

Hi All,
I am currently trying to use a mcu_friend 3.5" TFT (with touch sensitive screen) on a chipKit Uno32 board. I think it is close to be ok, but i can not display anything on the screen :confused: I can only get ID, width and height, and it is right!
here is the code i added to the mcufriend_shield.h library for compatibility:

//################################### PIC32 CHIPKIT UNO32   ############################
//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0  | |RD |WR |RS |CS  |RST |
//PIC32 pin |PD9|PD2|PD1|PF1|PD0|PD8|PD3|PD10| |PB2|PB4|PB8|PB10|PB12|
//									|RG3 |?

#elif defined (__PIC32MX3XX__)


#define RD_PORT LATB
#define RD_PIN  2
#define WR_PORT LATB
#define WR_PIN  4
#define CD_PORT LATB
#define CD_PIN  8
#define CS_PORT LATB
#define CS_PIN  10
#define RESET_PORT LATB
#define RESET_PIN  12


#define FMASK		  0x02
#define DMASK         0x070F    

			 
#define write_8(x)    { LATF &= ~FMASK; \
						LATD &= ~DMASK; \
						LATD |= (((x) & (1<<0)) << 10); \
						LATD |= (((x) & (1<<1)) << 2); \
						LATD |= (((x) & (1<<2)) << 6); \
						LATD |= (((x) & (1<<3)) >> 3); \
						LATF |= (((x) & (1<<4)) >> 3); \
						LATD |= (((x) & (3<<5)) >> 4); \
						LATD |= (((x) & (1<<7)) << 2);	}

#define read_8()       (((PORTD & 0x400 ) >> 10)| \
						((PORTD & 0x08  ) >> 2) | \
						((PORTD & 0x100 ) >> 6) | \
						((PORTD & 0x01 )  << 3) | \
						((PORTF & FMASK)  << 3) | \
						((PORTD & 0x06 )  << 4) | \
						((PORTD & 0x200 )  >> 2) )
						
#define setReadDir()  { TRISF |=  FMASK; TRISD |=  DMASK; }
#define setWriteDir()  { TRISF &= ~FMASK; TRISD &= ~DMASK; }
#define WRITE_DELAY   { WR_ACTIVE2; }   //-Os=5.43s @20MHz always_inline. (-O1=5.41s, -O3=5.25s) 
#define READ_DELAY    { RD_ACTIVE2; } 
//#define setWriteDir() { TRISF |=  FMASK; TRISD |=  DMASK; }
//#define setReadDir()  { TRISF &= ~FMASK; TRISD &= ~DMASK; }
#define write8(x)     { write_8(x); WRITE_DELAY; WRITE_DELAY; WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; READ_DELAY; READ_DELAY;  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))

I had some issues with the pic32 RB4 output (LCD_WR), which seemed to be uncontrolled, but i solved the problem, setting the ODCB register to 0 (it controls open drain outputs).

Curiously i can get ID, width and height informations, but nothing displays on the screen.
I tried to add some WRITE_DELAY and READ_DELAY in the write8/read_8 functions but nothing better happened :confused:
I have two questions:
Is there anyone knowing something about that issue?
If the problem is solved, where can i upload the patched library?
Thanks a lot
Dominique

I don't have a chipKit. No one has ever asked for chipKit support !!

Do you have a GitHub account?
It is probably better to discuss on GitHub.

//################################### PIC32 CHIPKIT UNO32   ############################
//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0  | |RD |WR |RS |CS  |RST |
//PIC32 pin |PD9|PD2|PD1|PF1|PD0|PD8|PD3|PD10| |PB2|PB4|PB8|PB10|PB12|
//                                                |RG3 |?

Are you are sure that this wiring is correct?
Should you use RG3 instead of PB4 ?

I have checked your macros. (by printing on paper). I am impressed. You have got them correct.

Having never used PIC32 I assume that TRISx registers work like PIC18 TRISx
With all the bit-shifts I doubt that you will need any write delays. But you can add as many as you like.

What ID do you receive?
Have you forced the ID e.g. tft.begin(0x9486);

David.

Hi David,
Thank you for your answer :slight_smile:
I have got some few arduino boards but i have that chipKit board for many years (When i started playing with arduinos i bought that board because i believed it was an arduino :slight_smile: ) Then i bought real arduinos :smiley: :smiley: (but I used some Pics before (16f and 18f))
About the wiring, yes i am sure about it (i agree with you, that it is very stange :stuck_out_tongue: )
Yes TRISx is the dir register .

About the macros, i had to study how the other macros (for other boards) work to write my own :sweat_smile: thanks to the guy who wrote them! i am pleased that you are impressed :slight_smile:

The ID it returns is 0x6814, it is the same that my arduino mega's got ( the screen works perfectly with mega2560 board)
I will try by forcing that ID (i remember that i tried another one but still same effect :slight_smile: )
I will try to ask on Github, thanks for the piece of advice :slight_smile:
(maybe my english seems strange, it is because i am french )
Thanks again!
Dominique.

0x6814 is a Raydium RM68140. It should work fine.

You must select the A4 pin by JP6
You need to disable JTAG because you need A3, A4 as control signals LCD_CS, LCD_RST

I don't know whether any "Arduino ChipKit Core" interferes with the header sockets used by the display.
You can use pinMode(pin, OUTPUT) for 2-9, A0-A4 before you call tft.begin(0x6814);

David.

I will try this. i have already tried to disable JTAG, but the JTAGEN name is not known by the system (i will find what is its right name), the open drain register fixed the first issue, so i forgot to manage with the jtag :stuck_out_tongue:
Thanks again,
dominique

I suspect that JTAG is disabled by default. Otherwise you could not use A3, A4 for Analog in regular Arduino sketches.

Oops. The PIN_OUTPUT() macro assumes that address of TRISx is LATx - 1 when it is LATx - 0x20

But since your control pins are always on LATB I would just say:

#define PIN_OUTPUT(p, b)     TRISB &= ~(1<<(b))

or perhaps

#define PIN_OUTPUT(p, b)     *(&p-32) &= ~(1<<(b))

note that TRISx is inverse of AVR DDRx register.

David.

You are right, JTAG is disabled by default ( the right command was:

DDPCONbits.JTAGEN = 0;

Oh yes, i did not notice the PIN_OUTPUT macro, and you're right, there LATx - TRISx = 0x20
so i corrected it, with your second guess :

#define PIN_OUTPUT(p, b)     *(&p-32) &= ~(1<<(b))

because i am not sure that PIN_OUTPUT macro is only used fot TRISB :confused:

i noticed it is inverse of DDRx (it is why i have two commented lines in my code :stuck_out_tongue: )
Thanks a lot, i keep in touch !

Here is some lines i had to the main code before asking on the forum :slight_smile:
I had to put that lines to have the good IDs:

if i do not deactivate the opendrain with that command

ODCB=0x00;

I get ID=0x00 (because control line could not work properly)

and i had to put the TRISB line in the code to get 0x6814, instead, i got 0xD3D3.

TRISB &= ~0x1514; //0001 0101 0001 0100

With the PIN_OUTPUT macro you guessed to correct, i expected that the TRISB line will not be usefull at all. but 0xD3D3 just came back, so i had to uncomment the TRISB code line :confused:

Maybe i have to find a small bug somewhere in my macros ... :confused:

You can extend the PIN_OUTPUT macro to write to ODCx as well as TRISx. e.g.

#define PIN_OUTPUT(p, b)     { *(&p+16) &= ~(1<<(b)); *(&p-32) &= ~(1<<(b)); }

The PIN_OUTPUT() macro is only called at the start of the library. i.e. in tft.begin()

When everything is working reliably, please experiment with the WRITE_DELAY() macro by running the Adafruit tests in graphictest_kbv

Make a note of the "total" time.

David.

Edit. Corrected the ODCx offset from LATx. i.e. +0x10

Ok! That explains why i get a bad ID if i remove TRISx command before tft.readID() (which is before the tft.begin() :slight_smile:
seems we can not put it in constructor :confused:
ok for the macro extension

I am a bit confused, i was looking for "re download" the library on github, and i noticed that YOU are the author of that library!! many many many thanks to help me and take time for !!! :slight_smile: :slight_smile: it is an amazing job you've done with that library!!

Me again , (the display still not works :frowning: )
The PicKit works at 80Mhz, is there a chance that WR_STROBE is not long enough? as you suggested it, i will experiment ...
the different timings i can test are WRITE_DELAY, READ_DELAY (not sure since readID works fine) WR_STROBE ?

Another thing, picKit is 3.3V, i do not think it would be a problem, do you?

Apologies for the wrong ODCx offset. I typed from a different PC. I have edited #8

I would expect the Beta on GitHub to work with your conditional block. i.e. with the amended PIN_OUTPUT() macro. No changes in sketches.

If readID() works correctly the other methods should work too.

3.3V GPIO is no problem. In fact it solves the Mcufriend pcb design errors. i.e. HC245 instead of LVC245 buffers.
Your board has a 3.3V pin and a 5V pin. Both pins can provide sufficient current to the backlight.
The missing AMS1117 is no problem for your ChipKit.

The DELAY macros are used on 200MHz Cortex-M4 and Cortex-M7 targets. 80MHz is ok.

I will put a test Branch on GitHub tomorrow if you are still having problems.

David.

Ok for the delays and 3.3V gpio , so the problem is not there :confused:

Thank you for all!
I am sorry that it takes you so much time :confused:
Dominique

Does your display work on a Uno or Due ?
Does it have HC245 or LVC245 ?
Does it have AMS1117 ?
Does the screen get hot ?

David.

Hello David,
It works on a Mega, but i do not have UNO (i have nanos) I will have a DUE in a short time (it is somewhere between the seller and my home :smiley: :smiley: )
my tft board has HC245 (directly powered by 3.3) and no AMS1117, and the screen does not get hot .

I made a test last night, I just put some leds instead of the screen on the control line (i wish i had my oscilloscope (with a logic analyzer inside) it is at work but i can not go there because of covid... )
I saw something strange, CS pin blinks off regularly and when it blinks off there is also a small fast blinking (on the mega). On the chipKit, almost same thing: the CS has a long blink off, but it is the wr pin which blinks fastly!
So, is there another point where there is a test with board selection in the code? i did not find anywhere, but i am sure you know about it :wink:
Dominique

MCUFRIEND_kbv should work on any board with proper Arduino headers (to receive the Uno display Shield)

I will post a Branch for Uno32 on GitHub later.

David.

I have put a "test_Uno32" Branch on GitHub. Obviously untested.

If you have a GitHub account you can simply change Branch on your local PC.
If not, you should select "test_Uno32" instead of "master" branch on GitHub. Download ZIP.

Leave IDE. Delete previous MCUFRIEND_kbv directory. Start IDE. Install from ZIP.

Run graphictest_kbv from Examples.
Note ID reported on Serial Terminal. Should be 0x6814

Run LCD_ID_readreg from Examples.
You should get the same report on Serial Terminal that you got from running on Mega.

David.

Thank you very much David,
I open a new issue on Github, here is the URL :slight_smile:

as you suggested yesterday, it is a better place to talk about chipKit :slight_smile: