RS232 Communications

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

mrclauds
Posts: 14
Joined: Fri May 13, 2011 6:25 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

RS232 Communications

Postby mrclauds » Mon Jun 19, 2017 11:17 am

Hi All
Was hoping to get some help on this...

I have a UART working perfectly, but the system I need to connect to has the following RS232 settings:
Baud 9600
Data Bits 7
Stop Bits 2
Handshaking None or Xon/Xoff
Parity Even

To change to 7 data bits, I have to switch to software controlled, and that's when reliability falls to practically nothing...
Also, where do I set info for the chip to use 2 stop bits, handshaking and parity?

Info
Flowcode V4
Pic 16F877A

Thanks

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

Re: RS232 Communications

Postby Benj » Mon Jun 19, 2017 12:22 pm

Hello,

If you keep the data bits to 8 then you can remain using the hardware channel and simply add the parity bit as part of your data. The stop bit will be a logic 1 so you can simply add a bit delay or more in between your byte sends.

To calculate the parity bit you need to count the number of 1's in your 7-bits of data.

What version of Flowcode are you using and I will try and generate you a quick example. Sorry I see, FC4...
These users thanked the author Benj for the post:
mrclauds (Tue Jun 20, 2017 6:11 pm)
Rating: 5.88%
 

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

Re: RS232 Communications

Postby Benj » Mon Jun 19, 2017 12:33 pm

Here you go, a quick example using a hardware UART and using the 8th data bit as a parity bit.

ParityDemo.fcf
(6.5 KiB) Downloaded 173 times
These users thanked the author Benj for the post:
mrclauds (Tue Jun 20, 2017 6:11 pm)
Rating: 5.88%
 

mrclauds
Posts: 14
Joined: Fri May 13, 2011 6:25 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: RS232 Communications

Postby mrclauds » Tue Jun 20, 2017 2:29 pm

Hi

Thank you so much
Would it be possible for you to explain the code a little?
Also, I want to receive characters rather than send... is it a matter of changing from send rs232 to receive rs232?

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

Re: RS232 Communications

Postby Benj » Tue Jun 20, 2017 3:26 pm

Hello,

The code should be reasonably straight forward. When you want to send out a value simply call the TxWithParity macro and it will take care of the rest for you. The macro loops through the 7 lower bits of the data byte and counts the number of set bits before appending the parity bit to the 8th bit. Currently the eighth bit contains odd parity as it will be set if the number of set bits is an odd number. You could change this to even parity by adding 1 to the count value directly after the loop.

For receiving you can probably just mask off the lower 7-bits of data unless you want to explicitly check the parity bit is correct. For most applications this shouldn't be necessary.

To do this just call the receive function and then and the returned value with 0x7F to mask off the lower 7-bits.

ComponentMacro: data = ReceiveByte (10)
Calculation: data = data & 0x7F
These users thanked the author Benj for the post:
mrclauds (Tue Jun 20, 2017 6:11 pm)
Rating: 5.88%
 

mrclauds
Posts: 14
Joined: Fri May 13, 2011 6:25 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: RS232 Communications

Postby mrclauds » Tue Jun 20, 2017 6:10 pm

Hi

Thank you very much... just spent the last few hours decoding your code in detail and understood it... Very clever and straight forward :) Doing Binary arithmetic has given me such a brain workout, but glad I did it :)
Also figured going through first 7 bits was all I needed :)

Thanks very much
These users thanked the author mrclauds for the post:
Benj (Wed Jun 21, 2017 10:37 am)
Rating: 5.88%