How to receive/send RS232 Byte not Char

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
Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

How to receive/send RS232 Byte not Char

Post by Niro »

Hi all,

I'm trying to figure out how to receive/send bytes (0x00 to 0xFF) via RS232 with Flowcode 4 for AVR. The problem is, that my PC-software is sending/receiving data packages with adress bytes (HB,LB) and data bytes only in byte-format and not in char-format what the Flowcode RS232-macro work with. If you are using 'receive char' in the macro, it works with numbers up to 0xFE (254 decimal), but not recognizing 0xFF (decimal 255). This is quite a big problem, if you're receiving/sending data-bytes...
Maybe someone has an idea or could help me with some C-code (maybe using the RS232 interrupt), because I'm a beginner at AVR programming and I'd really appreciate some help.

Many thanks,
Niro

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: How to receive/send RS232 Byte not Char

Post by medelec35 »

What I do is byte = char - 48 (for receiving)
and
Char = byte + 48 (for transmitting)
So if char you receive is 52 then byte = 52- 48 = 4
So if you want to send a byte with value 4 via RS232, just send Char with a value of 52
Etc.
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: How to receive/send RS232 Byte not Char

Post by Dan81 »

Hello Niro

If you want to read 0xFF, in the properties of the RS232 component, you must choose int in the "char receive type".
If there is no reception the return value will be 512.

All is explained in the help file.
rs_prop2.jpg
rs_prop2.jpg (57.23 KiB) Viewed 8215 times
Your variable must be an integer.
I use Flowcode4 for Pic.

Daniel

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: How to receive/send RS232 Byte not Char

Post by medelec35 »

:oops: I forgot about that. I was so use to converting chars from keypad and sending via RS232. I gets into a habit.
Thanks Dan.
Martin

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Niro »

Hello Daniel,

many thanks for your answer! I'll try this now.
Unfortunately Flowcode for AVR seems not as much developed as Flowcode for PIC..:-( Especially when you look at the avialable interrups the chip configuration or the help file/documentation (In my help file I found nothing about this RS232 configuration option).
I really like Flowcode (AVR) very much, but sometimes I feel a bit like a beta-tester. I hope this gets better with the next version...

Once again, many thanks!
Niro

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: How to receive/send RS232 Byte not Char

Post by medelec35 »

Thinking about it two options are better then none :P
Niro wrote:Hello Daniel,
Unfortunately Flowcode for AVR seems not as much developed as Flowcode for PIC..:-( Especially when you look at the avialable interrups the chip configuration or the help file/documentation (In my help file I found nothing about this RS232 configuration option).
I have downloaded the demo Flowcode AVR and here are two ways of showing the help option for RS232 component.
one way is shown by Daniel ,the other way is:
1) Right click on component on the panel and select Properties.
2) Click on three dots beside 'Help' within the new opened properties window
3) Scroll down to link for Component Properties within the help file
232 Help file.jpg
232 Help file.jpg (63.53 KiB) Viewed 8180 times
Below the image you should See:

Code: Select all

Properties
The RS232 component has the following properties:

Baud Rate
Defines the speed of the bus relative to the device clock speed to allow for a specific rate of data to be acheived. For a custom raud rate any value of bits per second (bps) can be entered. The error textbox shows the percentage of error from your desired baud rate to the actual baud rate that will be produced based on clock speed.

TX / RX
Chooses between a hardware UART if available and a software bit-banged option.

It is always reccommended to use the hardware UARTs for serial communication if available as they have dedicated buffers that allow for data to be sent and received while you are processing other portions of your program.

If a software UART is selected then the connection pins for the RX and TX lines are available in the components component connections window.

Data Bits
Specifies the number of data bits included in a single transaction. 
Default value is 8 bytes.

Note 7-bit operation is not supported when using the hardware UARTs.

Receive Type
Defines the value for the timeout return value. 
Byte (Legacy) sets the INVALID_RETURN timeout value as 255 allowing acceptable data values 0-254 (8 bit mode).
Errors such as framing and overflow errors also return 255.

Int (Extended) sets the INVALID_RETURN timout value as 512 allowing acceptable data values 0-255 (8 bit mode) or 0-511 (9 bit mode)
When using the extended mode framing errors return a value of 1024 and overflow errors return a value of 2048.

RX Timeout
Configures the receive macro timeout structure as a number of iterations (Legacy) or as an actual time to wait for data (Milliseconds).

Flow Control
If flow control is enabled then the RTS and CTS pins become active in the send and receive functions.
The pins used for the RTS and CTS can be defined using the property settings. 

Echo Mode
Echo mode allows any incoming data to be echoed straight back out simply by calling one of the receive functions.

This is useful for certain devices that require their data to be echoed back in to work correctly. Eg certain GPS modules.

Display Characters or Bytes
Defines whether sent or received values are shown as numbers or ASCII characters in the Flowcode simulation.

Note the numeric and ASCII representations are simply different methods of displaying the same set of data.

Show Simulation
Enables the RS232 component to be present in the Flowcode panel window during simulation.
To change from char to byte as Daniel suggested you can select the three dots next to 'External properties'
Martin

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Niro »

....now It's clear. I got to the right help site and found the detailed description!

Many thanks medelec35,
Niro

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Niro »

Hi all,

now receiving single bytes work quite fine!
But when I try to send a single byte using the SendRS232Char command the teminal program always receives the sent byte two times (e.g. sent: 0x18 -> terminal receive: 0x18 0x18).
I've checked everything but don't really have any idea how this happens.
Can anybody please help?

Thanks in advance,
Niro

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Niro »

Hi all,

I figured out a solution for the problem of having send unexpected double bytes: you need to add a delay of 10ms after the 'SendRS232Char'-command (see the attached picture).
If the delay is taken out the AVR will send '0x18 0x18' and if the delay is insert the AVR will send '0x18' (this is as normally expected).

Does anybody have an explanation for this behaviour?
Or is there a way to get it working without an added delay, because I'd prefer not patching the program with any delays...

Looking forward to your answers!

Niro
Attachments
Sending single Byte only works with added delay!..???
Sending single Byte only works with added delay!..???
RX232_ByteSend.jpg (233.65 KiB) Viewed 8144 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Sean »

We have checked for this problem, but can not reproduce the fault.

The 10ms delay should not be required.

If you can send us a copy of the program, we will try to locate the cause of the second character.

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to receive/send RS232 Byte not Char

Post by Niro »

Dear Sean,

many thanks for your response!
I don't know why, but checking this again today, I wasn't able to reproduce the problem.
Maybe this happens because I'm using an FTDI TTL-RS232 converter on my evaluation board and there might be some timing problems.

But there's a different thing I've recognized: if you are using the RS232 simulator on Flowcode AVR and set the CharReceiveType to integer,
it works fine on the programmed AVR, but the simulator always writes 255 into the receiving variable (=integer) instead of 512.
The simulation in the BytesReceived window also show 255 instead of 512 if nothing received.

I hope you can reproduce this behaviour and it's not again my equipment...;-)

Many Thanks,
Niro

Post Reply