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

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

RS232 Communications

Post by mrclauds »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Communications

Post by Benj »

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

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: RS232 Communications

Post by Benj »

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 464 times

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

Re: RS232 Communications

Post by mrclauds »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Communications

Post by Benj »

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

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

Re: RS232 Communications

Post by mrclauds »

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

Post Reply