UART Communication

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

UART Communication

Post 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

chipfryer27
Valued Contributor
Valued Contributor
Posts: 662
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: UART Communication

Post 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

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: UART Communication

Post 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

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: UART Communication

Post 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

User avatar
Bachman
Posts: 116
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Has thanked: 9 times
Been thanked: 53 times
Contact:

Re: UART Communication

Post 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 12388 times
ScreenShot_593.png
ScreenShot_593.png (190.96 KiB) Viewed 12388 times

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: UART Communication

Post 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

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: UART Communication

Post 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

User avatar
Bachman
Posts: 116
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Has thanked: 9 times
Been thanked: 53 times
Contact:

Re: UART Communication

Post 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.

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: UART Communication

Post 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

Post Reply