RS232 and integers

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
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

RS232 and integers

Post by Jan Lichtenbelt »

I use RS232 (software, only TX and RX) between 2 PIC's. I like to send/receive integers. Is that possible? Up to now it seems to me that only the first 8 bits of the integer are send.

Kind regards

Jan Lichtenbelt

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: RS232 and integers

Post by dbasnett »

I think you can send two bytes, the order being up to you.

byte = integer
send byte
byte = integer right shift 8
send byte

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 and integers

Post by Benj »

Hi Jan,

RS232 in hardware mode can only transfer 8 or 9 data bits in one transaction. The 9th data bit is normally used for addressing using say the RS485 protocol.

This article may help on splitting and recombining large variables into multiple bytes.
http://www.matrixmultimedia.com/article.php?a=366

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: RS232 and integers

Post by dbasnett »

The link Ben posted is exactly what I meant, but explained far better.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

Is there a flowcode (send and receive part) for RS232 (software based) between 2 PIC's for INTEGERS? I tried it but without succes up to now.

Kind regards

Jan

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: RS232 and integers

Post by Dan81 »

hello Jan

This flowchart seems to be OK (within Proteus).
It is only for sending, for now.
Can test it in real live ?

Daniel
Attachments
RS_send16bits.fcf
not hard tested
(21.46 KiB) Downloaded 296 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

Dear Daniel,

I'm afraid that does not work. What you do is to change a byte into an integer (in some way) and than sending this integer by RS232 in one step. But RS232 will send only lower_byte and not the integer (if I'm correct). If you make a receiver, you will find only the low-byte part of the integer at the receiver site.
But thanks for helping finding a solution.

Kind regards

Jan

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: RS232 and integers

Post by Mikat »

Hi.

Why you just can't split the int in 2 bytes, send them and combine them back to int? At least that is what I do, I have an Eberspacher ecu, done by flowcode, and it uses rs232 (at the moment, the pcb to join that eber to CAN network, is under way) to communicate with fan controller unit, there is at least 5 int to sent, an it works fine..
I mean like this

byte = int >> 8
sent byte
byte = int
sent byte
and other device

rec byte
int = byte << 8
rec byte
int = int + byte
Like Ben says, the rs232 specs support only up to 9bit transfer...
Even in CAN I need to break int to bytes, to sent int, it's probably possible, by the modification of the software rs232 c code, but it's not rs232 anymore after that...

Mika

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 and integers

Post by medelec35 »

Hi Jan,

I only send 10bit integers that are displayed in hyperterminal, but I send them as ACSII string.
RS232 component has to be set to Characters and not bytes.
To send several different integers I use the format as in the screen shot below:
send int rs232.png
(11 KiB) Downloaded 5761 times
Using a temp string Variable saves on ROM being used.

Is is possible for you to send as a string, then the receiver can convert the string to integer using StringToInt$() function
You can use a decision to separate integers by waiting for a ASCII space.

You may not want to do it this way, but I thought I would show an alternative to splitting integers into bytes.
In theory this sending and receiving would work, but not tried it out on real hardware.
I have only ever use sending.
Martin
Martin

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: RS232 and integers

Post by Dan81 »

Hello Jan

In my previous flowchart , the calculation create a variable value with 16 bits.
In this version , I send the (integer) value of the ADC, 16 bits are sent but the last 6 are always "0".

I can only test with Proteus, I don't have an oscilloscope at home.

Daniel
Attachments
RS_send16bits_v2.fcf
(21.38 KiB) Downloaded 215 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

Dear Martin,

Thanks for the simple solution. It works. Please find the two Flowcodes used.

Kind regards,

Jan
Attachments
RS232 Send Integer.fcf
(6 KiB) Downloaded 214 times
RS232 Receive Integer.fcf
(7.5 KiB) Downloaded 219 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 and integers

Post by medelec35 »

Hi Jan,
Glad you have got what you want to work.
I have made a slight alteration to your flowchart so you can receive all the integer range including 0
Since on your flowchart you can’t receive a 0
Thanks for sharing your soultions and for letting us know.

Martin
Attachments
RS232 Receive Integer Modified.fcf
(8 KiB) Downloaded 207 times
Martin

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

string length should be >0 or >=1, instead of >1.

Jan
Attachments
RS232 Receive Integer.fcf
(8 KiB) Downloaded 182 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 and integers

Post by medelec35 »

Jan Lichtenbelt wrote:string length should be >0 or >=1, instead of >1.

Jan
The reason I used >1 is when stepping within flowcode simulator and there is nothing in rs232 buffer, then string always has 1 char that looks like a square which when converts to int produces a 0....hence >1 to get around that. If on real hardware this does not happen then fair enough use >0. I am relying on Flowcode simulator since not tried it on real hardware.
Thanks for letting me know.

Martin
Martin

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

With Length>1 you miss all numbers 1-9.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

Can someone tell me, when sending data in this way, there is a need for a delay between two RS232 calls. 10 msec fails and 100 msec is enough. Why is there a delay necessary? And what is the shortest time needed?

Kind regards

Jan Lichtenbelt
Last edited by Jan Lichtenbelt on Mon Nov 14, 2011 11:23 am, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 and integers

Post by medelec35 »

Jan Lichtenbelt wrote:With Length>1 you miss all numbers 1-9.
That’s Fair enough.
It’s just a case of Flowcode simulator differs from results of real hardware.

Martin
Martin

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 and integers

Post by Benj »

Hello
Can someone tell me, when sending data in this way, there is a need for a delay between two RS232 calls. 10 msec fails and 100 msec is enough. Why is there a delay necessary? And what is the shortest time needed?
I have had a look at your program and you don't seem to be sending any data. You should not need any delays in between RS232 component macro calls in Flowcode.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: RS232 and integers

Post by Mikat »

Jan Lichtenbelt wrote:Can someone tell me, when sending data in this way, there is a need for a delay between two RS232 calls. 10 msec fails and 100 msec is enough. Why is there a delay necessary? And what is the shortest time needed?

Kind regards

Jan Lichtenbelt
No delays should be needed, at least the eber ecu where I use rs-232 sends about 15 bytes with no delays, and it works like charm..
The other end has UART incoming int, and it reads also without delays...
If I don't remember wrong, the bus it tested at least 9600-38600 baud rates, I am not sure about 115200, but I might test it too.


Mika

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: RS232 and integers

Post by Jan Lichtenbelt »

I tried some different conditions and found that:
1) Timeout must be 1 (I do not know why) for the best results. 0 and higher values give bad results.
2) Increasing the baut rate improves the results
3) Sending with time delays < 1 msec gives bad results

Kind regards

Jan Lichtenbelt

Post Reply