Swap between UARTS

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

Moderator: Benj

Post Reply
kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Swap between UARTS

Post by kabouras_33 »

My next challenge in which i am already trying for a few days now is the capability to swap bewteen uarts.
The challenge is to Receive a char RX1(UINT) and sent char TX1(UINT) and TX2 (UINT)
if the RX1 stop receiving data then it should change to Receive a char RX2 (UINT) and sent char TX1(UINT) and TX2 (UINT)
and when RX1 starts receiving again switch back to Receive a char RX1(UINT) and sent char TX1(UINT) and TX2 (UINT).
Currently i tried if statements from reading the receive variable but with no success i also tried buffer yet again with no success,for some reason that i cannot understand i cannot make the if statement to work correctly...
Currently i cannot upload any code because i tries so many the past days with absolutly nooo result.
If someone has some pointers to get me started it would be a gift!!! :D

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

And this is one of my efforts that looks good on simulation but in real life once again no!!
Awaiting your valuable suggestions!! :D
Attachments
Flowcode1.fcfx
(11.11 KiB) Downloaded 218 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Swap between UARTS

Post by LeighM »

Hi,

ReceiveChar() returns 255 if nothing is received and it times out (not 0)
So your loop test needs to test for 255 not 0.

In your "bytes1" processing loop you are looping while "bytes" (which should be bytes1 != 255)

Also the test should be at the end of the loop to ensure that the ReceiveChar is called at least once.

If you step through your code you will see that once data has been received on one channel the main program will come to an end,
you need another loop to get the flow back to looking for data on the other channel.

Hope that moves you on,
Leigh

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Thank you very much in the afternoon i will return to my workshop and try it and post the data!!!
I think i didnt try that but on the other hand i have tried so many the past days that i do not remember!
I try and report back!!!!
THANK YOU!!!!! :) :) :)

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

So as always you are right on target,
But this time it looks as you already know that it doesn't return back I added receive byte to the byte 1 section in order for the loop to detect it but it crash...I also added a macro call from the byte 1 loop to make the detection same result..... :twisted:

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Also I would like to add that by removing the two loops and let the programm check the if statement every time it also crash..... :?:

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Swap between UARTS

Post by kersing »

When you say it crashes, what do you mean? Does Flowcode crash? Does the generated code crash in the target controller? If so, what are the symptoms? Could you attach your latest attempt so we're able to see what is happening?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Goodmorning and thanks for the prompt reply!!
The generated code crash in the real contoller.The symptoms are that while it starts receiving and transmitting signals from RX1 when i cut the signal and it is supposed to go to the RX2 input it stucks completly no RX1 no RX2.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Swap between UARTS

Post by kersing »

It is very hard to find the error if we can not check your code, please post (or PM if sensitive) your flowchart.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Goodmorning and thanks for the prompt reply!!
The generated code crash in the real contoller.The symptoms are that while it starts receiving and transmitting signals from RX1 when i cut the signal and it is supposed to go to the RX2 input it stucks completly no RX1 no RX2.
I attach 2 photos from the 2 desighns
Attachments
FLOWCODE2.png
(18.44 KiB) Downloaded 4346 times
flowcode 1.png
(18.43 KiB) Downloaded 4346 times
Last edited by kabouras_33 on Thu Aug 17, 2017 10:06 am, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Swap between UARTS

Post by LeighM »

Hi,
You will need an outer loop, to get you back to looking for data on the other channel, something like this ...
loop.jpg
loop.jpg (30.56 KiB) Viewed 9430 times

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Thanks again LeighM!!!
I ll try to work on it!!And report you back immediatly!!

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

I think i found it with your help please see attached
I will test it in real this afternoon i hope it works!

NOTE : Please forgive my ignorance as you noticed i am triyng to learn i am still young in this field.
Attachments
Flowcode1.fcfx
(11.7 KiB) Downloaded 169 times

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

There is a mistake in the second while loop i corrected from 250 to 255 so please do not mind it!

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Swap between UARTS

Post by LeighM »

Hi,
Not far away now :)
Just some things to check...
1) Check which UART you are reading from (just before the "if bytes" test), you currently are testing the same one twice
2) With this new flowchart you might as well just use one variable "bytes"
3) Check the while tests, both should be while bytes != 255 (edit: OK you spotted that yourself :)
4) Once in the while loops, do the two sends first, before then doing the next receive, otherwise you will lose the first character (assuming that's not intended)
5) Also check which UART you are receiving from in the while loops
6) The bytes1 while loop should be in the Yes branch, not the No branch

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

I dont no why but every minute that passes it looks more and more far :D :D :lol:
But its unbelievably amusing and interesting!!
So i will check all your notes in the afternoon for which i thank you very much,but i would like to clarify (because i know that i have the tentacy to confuse people :D ) that what i try to accomplish is the following
UART RX1 is the primary recipient of the nmea signal and TX1 // TX2 are both outputs.
UART RX2 is the backup recipient for the time that the RX1 is down (no data received) and also TX1 // TX2 are both outputs.
When RX1 receive data again the program should detect it and return back to the primary input.
So back brain squeez!!!!

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Sorry for the big delay in responce.
So i am stucked i the following point which i try for 1 week now...
photo 1 : The hotswap works but i think that because Nmea signals are not received continiously,but rather every 1 or 2 secs
the programm swaps all the time from one to the other.
photo1.png
(50.69 KiB) Downloaded 4205 times
I try to add a delay in my if statement but i dont know how to put delay in the loop statement for example maybe( loop until byte=255 && delay=3sec )would work.
Then i trien to put an interupt to timer one so when i have 15 counts in a macro timercount i will have (loop until byte=255 && timercount=14)
so even if data is not detected in the time i will specify from the timercount it will continue in the same loop or else go the second loop...
but ofcourse for some reason it looses many data because it goes to the second loop search and return so i think the byte=255 variable is always true and cannot be detected correctly so only the timercount works
Flowcode2.fcfx
(9.35 KiB) Downloaded 168 times
crazy...... :D :D :D

kabouras_33
Posts: 128
Joined: Thu Jul 27, 2017 5:23 am
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Swap between UARTS

Post by kabouras_33 »

Whatever i try to do the byte amd byte1 variable seems to never be able to read from the loop....only the timercount can be read...

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Swap between UARTS

Post by Benj »

Hello,

Don't you need an addition while loop around your current two while loops to ensure the program runs forever. Currently as soon as you exit the second while loop the program is over and the micro will essentially just sit there doing nothing.

Post Reply