RS232

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

Moderators: Benj, Mods

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

RS232

Postby jollybv » Tue Oct 26, 2010 12:20 pm

Hi i am pretty new to flowCode and it is getting the better of me, i was wondering is there anyone out there that can help I am trying to send an receive characters from one pic to another using RS232. I think i have the sending part rite as i see the numbers i key in appear in the RS232 component. But the receiving part has me totally confused me I know there is a get character instruction but how do you use it...??? is there any examples out there..?? Can someone please help

PS is there any way of simulating the receive character????

Regards
Brian :roll:

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

Re: RS232

Postby Benj » Tue Oct 26, 2010 1:09 pm

Hello Brian,

The read Byte RS232 macro returns a byte value. If this value is less then 255 then it is valid data. 255 represents a timeout without any valid data being received.

You can simulate a received character by adding a byte to the receive queue and then when the read byte macro is called the byte will move from the queue to the received window.

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Tue Oct 26, 2010 5:46 pm

Thanks benj

how do you add a bite to the receive cue Is there a example I can look at as i have no idea how to do this..???

I have attached a small bit of code could you please tell me where I am going wrong

Regards
Brian
Attachments
RS232 Receive.fcf
(6 KiB) Downloaded 229 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Tue Oct 26, 2010 8:24 pm

jollybv wrote:how do you add a bite to the receive cue

Add to Queue.jpg
Add to Queue.jpg (41.42 KiB) Viewed 7910 times


It depends on what you want to retrieve from RS232 data to how the flowchart would work.
So here is a flowchart (created with FlowcodeV3) that converts the received 232Char into ASCII, Displays text on LCD display and stores the 16 charectors in a variable.
I have only included lower case a to z, just to give you an idea one way to detect and convert received data into a string. There maybe a direct conversion function from byte received to ASCII, but since not sure what that is?

If this is not what you want, then if you let me know what format you want the received data in e.g bytes 0 to 255 then I will see what I can do.
Attachments
RS232 Receive_Modified.fcf
(5.5 KiB) Downloaded 278 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Wed Oct 27, 2010 5:45 am

Hi Benj

Thanks a lot this is starting to make a bit of seance. Let me explain what I'm trying to do I have is a keypad connected to me HP488 board that when i key in a number from 0 to 999 sends it via RS232 to a second chip, the second chip must read it as a number from 0 to 999 put it in a veritable then I want to use a decision to compare it and the second chip must output something eg if a 3 then pin A3 must go high and so on.

Regards
Brian

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Wed Oct 27, 2010 12:31 pm

Here you are try this version.
Attachments
RS232 Receive_Modified_V2.fcf
(6 KiB) Downloaded 229 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Wed Oct 27, 2010 1:16 pm

Updated to a better version.
This will work with values from 0 - 999 and will dispaly values on LCD Display
Also if you just enter the number 3, port A0 will go high.
Any other number entered, will cause A0 to go low.
Attachments
RS232 Receive_Modified_V3.fcf
(8 KiB) Downloaded 272 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Wed Oct 27, 2010 3:47 pm

Thanks Ben

Will try it and let you know

Regards
Brian

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Wed Oct 27, 2010 7:15 pm

Hi Ben

That program works like a treat from 1 to 9 but when I inset a 10 it gives me the same return as a when I insert a 1 (100) and the same for a 2 and 20 (200) what can i do to rectify it. i have tried numerous things without any luck.

I have attached the program and you should be able to see what im trying to do a bit better.

regards
Brian
Attachments
RS232 Receive_Modified_V2.fcf
(11.5 KiB) Downloaded 252 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Wed Oct 27, 2010 8:19 pm

Hello jollybv
Sorry about that. I realised that after posted it, so I modified it to work correctly and posted it an hour later. Have a look at the post Wed Oct 27, 2010 2:16 pm
that has a corrected V3 version, which has not been downloaded yet. As stated above, it works from number 0 to 999. and I have set it up to light a LED only if number sent is a 3 only. Give that a try and let me know how you get on please.

Kind regards
Martin.
Not Ben (he is the clever one :P) lol
These users thanked the author medelec35 for the post:
Benj (Thu Oct 28, 2010 9:11 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Thu Oct 28, 2010 4:57 am

Thanks Martin

You guys are great this works like a dream now to build the board an see if all is working

Regards
Brian :P

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Thu Oct 28, 2010 3:05 pm

Hi Martin

One quick question the RS232 signal from the transmitter should it be a square wave 0 to 5v TTL ?? I have checked mine on the scope and it is giving me a sort of a ramp form and the second board is not reading it i am using TX Pin 25 RC6 of the PIC16f877 and connecting it to the RX pin of the PIC 16F876A PIN 18 RC7. As i have never worked with RS232 should I to put a line driver as I'm only transmitting about 1m.

Regards
Brian

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Thu Oct 28, 2010 6:05 pm

I have not done what you are trying to achieve, but I believe TX O/P should be a TTL compatible square wave. You could try reducing Baud to 4800. if o/p signal is changing to fast, could the capacitive i/p of pic + connecting wire integrate the signal slightly?
How about you disconnect the TX o/p then scoping it.

I will have to leave it for people that know more about this aspect than I do to advise you. But good luck
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
jollybv
Flowcode v5 User
Posts: 342
Joined: Thu Feb 12, 2009 5:20 am
Has thanked: 77 times
Been thanked: 24 times
Contact:

Re: RS232

Postby jollybv » Fri Oct 29, 2010 4:54 am

Hi guys

I am still having problems with RS232 is sending from the main board it is a 5v high pulsing low TTL but my board on the other side dose not read it I put another program in to see if the board was working and the board runs fine, is there something i am doing with the connections or what. I have TX pin 25 of the Pic16F788 connected to RX pin 18 of the PIC16f876 and the TX pin 17 connected to the RX pin 26 of the PIC16F788 i am using the same power supply so the ground is common. When i simulate my programs they both work in flowcode so to me this should all work but alas I'm stumped again someone please "HELP" :cry:

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Fri Oct 29, 2010 6:17 am

If is was me, I would 1st check that both flowcharts are configured for same baud rate. Then I would check characters are sent correctly by connecting TX to a RS232 to usb converter, and check what is displayed in HyperTerminal, I would then connect RS232 to usb converter to RX is still getting correct characters displayed, that would mean the transmission length and stray capacitance's are not causing a problem. If all is OK then It would be down to receiving end. If you have LCD display connected, what characters appear on the display?

Just a thought if you are sending a number like 15, that has two bytes. So could the receiver be treating it like a single 1, then acting on that, then treating as a separate 5, instead of 15?
If so there needs to be a time out routine in the receiver so after receiving a number, the receiver keeps waiting for a timed period for the next number. If this timed period has elapsed e.g. 100 ms then no more numbers are sent, so do the if number = ... then do something routine.

Also with the transmitting side there must be a good delay between groups of numbers sent. Don't just send for example 15 then 184 one after the other, have a delay in between e.g. 200ms.

Hopefully someone else can help you. If not I have an idea how they can be altered. Can you post the two flowcharts you have got (that's if you have added to the ones posted on here).
Then I will modify them and re-post.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8472
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3482 times
Contact:

Re: RS232

Postby medelec35 » Fri Oct 29, 2010 6:19 pm

sent you a pm with modified files.
This is what i have sent
"Try these. Cant guarantee they will work, as not tried this before, or got hardware to test this out, since you need two separate target devices. I have removed the CR on TX, and on RX added a 200 ms time out. After 1st char is received ,a timer starts and waits for the 2nd. 3rd etc. As soon as 200ms has elapsed, then the routine of determining numbers sent starts.
Can you please let me know how you got on.
Thanks"
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.