RS232 RF!

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

Moderator: Benj

Post Reply
jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

RS232 RF!

Post by jgu1 »

Hi!

In a project I am working on, with RF module ( HC12, I can recommend, good module and cheep with high power) I try to send and receive string´s.

In my experiment, I can send two string when I press button 1 "Hello" and when I press button 2 "Bye bye".

I want when I press the one of the command, it write on line 0 in the display in the receiver. And if I press the other command it should shift to line 1 and write in line 1 in the receiver.

My question is, how do i get the recipient to see the difference between the two different String´s. Please hope some can help :D

Thank´s in advance

Jorgen
Attachments
StringRX.fcfx
(11.66 KiB) Downloaded 165 times
StringTX.fcfx
(13.32 KiB) Downloaded 158 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: RS232 RF!

Post by mnf »

Hi Jorgen,

Currently you have the interrupt (Rx_hello) displaying the string.
it would be better if the interrupt routine received the string (to a global string) - the main routine can then compare (using Compare$)/ display as required.

(ie (in pseudocode)
In Rx_hello:
Hello = receive_string
str_received = true.

In Main:
If (str_received)
if hello = "case1" then do_something.
if hello = "case2" then do_something_else.

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: RS232 RF!

Post by jgu1 »

Hi Martin!

Thank´s for fast reply. I dare to ask you, please, will you try to give me an examble or change in my receiver. Please. :D

Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: RS232 RF!

Post by mnf »

Ok - an example..

I've used an Arduino Nano - receiving on a software UART (2) on pins D2 (Rx) and D3 (Tx - but not used)
UART1 - is the standard UART and is used to echo the messages received to the PC. (I use the interrupt on D2 (Int0) If you use a Mega - you can use the Rx interrupt for the port you use here..)

I used a FDTI convertor to transmit strings to the Nano (but this could be another Nano etc)

One problem - you have two different length strings ("Hello" and "Bye Bye") - so ideally need an 'end marker' to signal the end of the string. I used 0x0D (which is the return character sent by putty - you can use most anything in Send program (for example SendChar(0x0D) after sending the string)

The receive interrupt stores characters to the string (for which Hello is probably the wrong name now) - and sets a flag (rcv_string) to true if it gets an end of string marker (0x0D)

The Main loop echos the received string (if rcv_string is true) to UART (echoed to PC) and compares the string to "hello" (case is ignored) - turns on the inbuilt LED if a match.
It also compares the string to "bye bye" - and in this case turns off the LED.
Other strings are echoed but do not effect the LED state.
As an aside - I put the comparisons one after the other for clarity (you should probably move the second into the 'false' branch of the first - in this simple example it won't affect anything - but if there were lots of comparisons - there would be 'neater' (ie less coding) ways to do things)
If processing a 'command' was likely to take a long time - then the Rx interrupt should check if rcv_string is set and ignore (or some other action - buffer the command for later for example) the input until the flag is reset.
StringRX example.fcfx
(16.04 KiB) Downloaded 167 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: RS232 RF!

Post by jgu1 »

Hi Martin!

Wow! Many thanks for your help.

But in the meantime I came up with another way and idea I could do it. Please try look at my program. I will definitely test what you have made for me later.

I hope I can return and get your always great help again, get many Ideas from you :wink:

Br Jorgen.
Attachments
StringRXFlag.fcfx
(13.67 KiB) Downloaded 173 times
StringTXFlag.fcfx
(13.28 KiB) Downloaded 158 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: RS232 RF!

Post by mnf »

Hi Jorgen,

Yes - looks good.. Just using a single character for commands.

Usually many ways to do something ("There are many ways to skin a cat" is the odd, English phrase, that describes this!)

I'd change the loops in Send to

Repeat
b3->flag
delay
until flag = 0

Rather than using a GOTO ! - but that's a matter of taste :-)

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: RS232 RF!

Post by jgu1 »

Hi Martin!

Glad to hear you like the way I do it. Yes an concerning the cat, there are many way to program :D

I hear often that the hard ( like you )programmer, don`t like the GOTO, how could that be, it work?

Br Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: RS232 RF!

Post by mnf »

Goto has it's place... It can also produce hard to read code (see https://en.wikipedia.org/wiki/Spaghetti_code)

"The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time." - Tom Cargill

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: RS232 RF!

Post by jgu1 »

Well ok Martin, thank you for the explanation :D

Br Jorgen.

Post Reply