Page 1 of 1

UART Communication

Posted: Thu Jan 05, 2023 6:45 pm
by AbhijitR
Hello!

I am working with PIC18F27K42 and Nextion display, the settings are as following,
Oscillator: 8Mhz with PLL
Channel: 2 (Tx:B6 and Rx:B7)
Baud: 57600

The problem I am facing is inconsistent working/starting/communication/initialization of the PIC and Nextion, I have noticed at few power ON of the circuit the communication between PIC and display fails and then nothing is displayed on the screen, if I press the reset button (MCLR) then the communication between both is correctly initialized and works absolutely fine, but at few power ON it do not start correctly I notice as if the initialization has gone wrong.

Can someone point out what could be the problem, or I am missing something (some delay before or after) One of the thoughts I am getting in my mind is after powering the circuit wait for a moment and somehow reset (MCLR) the PIC, as I see every time I press the reset button the display and PIC initialize perfect and works fine after that, but at few power ON I am facing this problem of both not getting initialization correctly.

Kindly correct me.

Thank you.

Abhi

Re: UART Communication

Posted: Thu Jan 05, 2023 7:07 pm
by chipfryer27
Hi Abhi

Could it be your config? That chip has a Power Up Timer and default is 64mS. You can change in Project Options etc.

Hope this helps

Regards

Re: UART Communication

Posted: Thu Jan 05, 2023 7:47 pm
by AbhijitR
Hi! Chipfryer

Thank you for your comments, indeed the timer was at its default value of 64mS, but I disabled that, I thought that was causing the problem, I am going to check that tomorrow morning and keep you posted.

Thank you again for your word.

Abhi

Re: UART Communication

Posted: Wed Jan 11, 2023 1:24 pm
by AbhijitR
Hi! Chipfryer

Kindly excuse for the delayed reply, I was traveling to Mumbai (Bombay) last week.

For my surprise the communication between PIC and display works in both the conditions of Power Up Timer, but sometimes it miss, may be 2 times in 10 power ON cycles.

I am still trying on my development board for the moment, let me check the same in real hardware to conclude.

Abhi

Re: UART Communication

Posted: Thu Jan 12, 2023 9:13 am
by Bachman
Hi Abhi!

Try to add 250-300 ms delay before UART initialization. If you turn on the Nextion display, it's send out some data and it can make overflow condition in the PIC's receive side. Or, right after the UART initialization, try this C code:

Code: Select all

U1CON2bits.RUNOVF=1;
U1 means UART1, modify it, if using other than UART1. I don't know, how Flowcode initializes UART module, maybe this help.


ScreenShot_591.png
ScreenShot_591.png (167.28 KiB) Viewed 17094 times
ScreenShot_593.png
ScreenShot_593.png (190.96 KiB) Viewed 17094 times

Re: UART Communication

Posted: Thu Jan 12, 2023 11:38 am
by AbhijitR
Hi! Bachman
good afternoon

Thank you for your feedback, I will try the method you suggested and also keep you posted.

Thank you again.

Abhi

Re: UART Communication

Posted: Thu Jan 12, 2023 1:51 pm
by AbhijitR
Hello! Bachman

Your suggestion (300mS) solved the problem, now on every power ON communication between both is established successfully.

Thank you for your quick answer, cheers....

Abhi

Re: UART Communication

Posted: Thu Jan 12, 2023 11:26 pm
by Bachman
Looks like, i've mixed up the things... :D Well, the Nextion display needs around 250 - 300 ms after power up to initialize itself. Just an idea, you can use this time. In the display, create a "welcome" screen (logo, picture etc.) as the startup screen (page 0). Initialize the controller, after initialization done, wait 1-2 seconds and start with screen 2 in the Nextion.

Re: UART Communication

Posted: Fri Jan 13, 2023 8:02 am
by AbhijitR
Hi! Bachman
good morning

You speak my mind, exactly the same has been done with the opening screen and the following screens, now it works perfect.

Thank you, my friend.

Abhi