sending numbers over Rs232

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

sending numbers over Rs232

Post by Xavier »

Hi guy's

I've been looking on the forum but don't seem to find what I'm looking for. I would like to send numbers from 0 to 220 from one pic 16f690 to another pic16f690 using the Rs232, I can send a string no problem but numbers either give me 0 or 255 now how difficult can it be to send the number 62 for example? This number is then printed on an LCD and like I said I had no problems sending a string and printing it to the LCD. Is there a tutorial or an example that I could have a look at?

Best regards
Xavier

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: sending numbers over Rs232

Post by medelec35 »

Can you post the flowchart that's not working then I can take a look at it for you.
Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Ok well here are the two files one for the tx and the other is the rx

Regards
Xavier
Attachments
RS232_TX.fcf
(11.5 KiB) Downloaded 309 times
RS232_RX.fcf
(13.29 KiB) Downloaded 287 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: sending numbers over Rs232

Post by medelec35 »

Hi Xavier, I have had a look at the RS232RX and can see some issues with will tie up with receiving 255 = no characters received.
When the RS232 component is used in received mode, if at the time of it being accessed there is no RS232 data at the RX pin then the default valuce will always be 255.

Also you're settings are for internal oscillator and you have got the clock set for 20MHz.
These do not match.
If you look at the datasheet you will see that that highest internal osc speed is 8MHz
You will also see that default is 4MHz.
What that means is on start up if osccon register is not set, then the internal osc will be running at 4MHz only.
The clock speed in project options is only for component macros that are dependent on delays e.g LCD, RS232, I2C and delays them self.
The delays are calculated using the clock speed within a formula.
So its important that the clock speed match the speed of internal or external osc.
Earlier I stated the internal osc default speed is 4MHz.
If you want the internal osc to run at the fasted speed (for 16F690 it's 8MHz) then you will need to add a c code block at the beginning of main with osccon=0x70; (not oscon=0x60;)
How that value is derived you can see from [urlhttp://www.matrixtsl.com/mmforums/viewtopic.ph ... 29&#p28829]this post[/url]
The 32MHz has to be ignored as the example is from a different target device.

If is was me then I would used the RX interrupt to instantly capture the RS232 transmission.
I will try & modify your flowchart to see if we can get it to work the way you would like it to.

First can you post examples of RS232 transmissions.
E.g if numbers then the range (0 to 9999) etc
Will there be more than one set of numbers. e.g 1234 7891 etc?

You will also need to bear in mind that RS232 are transmitted one character at a time, so if you want to receive 1234 then that's 4 lots of reading RS232 rx pin
Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

The oscillator speed is my fault, what I did instead of sending you a huge file I copied the part that's giving me the problem and I forgot to change the settings for the oscillator speed in project options. Yes I would like to be able to send a number from 0 to 220 so I could be sending 76 just like I could be sending 124. Should I then use a different method of communication between the two pic's? Because there are a total of four different numbers that will be sent but not simultaneously and only when they are being changed. Mind you I guess that, that makes no difference to the problem.

Best regards
Xavier

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: sending numbers over Rs232

Post by medelec35 »

Xavier wrote:Yes I would like to be able to send a number from 0 to 220
Oops, sorry you did state that at the beginning.
Here is one way without rx interrupt.
I have added a default timeout of 3 seconds after a character is received.
After three seconds has elapsed (will be longer than 3 seconds in simulator)
the the set of numbers from 0 to 250 will be assigned to Frequency (if 1st set), On time (if 2nd set), Delay (if 3rd set) or Sample (if 4th set).
Then process will start all over again waiting for witch to be pressed.

I'm guessing that's how you would like it to work?
If not then if you can explain step by step how you would like it to work then we can take it from there.

Martin
Attachments
RS232_RX V1.1.fcf
(21.2 KiB) Downloaded 289 times
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Thanks Martin

I will have a look at it in the morning he he almost morning here. Will be sure to let you know if it will do the job or not.

Regards Xavier

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: sending numbers over Rs232

Post by medelec35 »

After having a bit more of a think, I have came up with a more simplified version having the same function as I stated in my previous post, but without the time out and just reading bytes rather than ASCII.

Hopefully get there in the end?

Martin
Attachments
RS232_RX V1.2.fcf
(16.45 KiB) Downloaded 300 times
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

:D I was just going to send you the FC file with some questions in it. Actually I will send it to you, never know what can come out of it. I'm now going to have a look at the new one that you posted. Thanks for all the help Martin much appreciated.

Xavier
Attachments
RS232_RX V1.2.fcf
(22.73 KiB) Downloaded 268 times

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

I noticed that we both gave our new file the same name, could you rename it to RS232_RX V1.3 (the one that I sent you)

Xavier

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: sending numbers over Rs232

Post by medelec35 »

Hi Xavier,
Without testing Im not even sure if the second flowchart will work or not.
With the first flowchart it's really for if your sending string (using IntToString function) which is what I do all the time time.
If you send a string value of 0 then if you look at a ASCII chart you're really sending an ASCII value of 48.
So 48 will be received.
Hence the reason for

Code: Select all

RX_Receieve - 48

RX_Receieve = 48
so RX_Receieve - 48 = 0
If your sending values to a PC and not PIC then you will not be able to send char 0 for the number 0
This is because you will be sending ASCII 0 = null. So the PC using HyperTerminal, RealTerm, Putty, Terra Term etc to display characters then a 0 will not be displayed.

I personally find it better to send RS232 via strings because it can be then converted back into a number very easily (depending on the typecast).
E.g if using a UInt variable then numbers received can be converted in the range from 0 to 65535

So perhaps yo should be working on sending all numbers via string then you could extend the range from 254 to unlimited.
I can alter the transmitter to do that for you?

If the 1st flowchart will not work if not sending ASCII characters.
If sending char then i believe only 2nd flowchart will work,
To make sure I need to set up the same hardware as you.

If transmitting bytes, then to see the bytes in the simulation, you can right click on the RS232 component on the control panel, select Ext properties.
In the simulation part, change Characters to Bytes

Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

I'm going to have to study all that you have said very carefully (very interesting stuff) in the meantime I was having a bit of fun trying out some stuff on my own, but alas the results are poor. Here are the two files TX and RX so that you can see what I've been trying to do. I don't use the PC for simulation I burn to the PIC as in this kind of situation I feel thats it's a better bet.
Actually I had another look at what I'm doing and I think that I'm getting myself in a real knots LOL

Xavier
Attachments
RS232_TX V1.2.fcf
(14.55 KiB) Downloaded 224 times
RS232_RX V1.2.fcf
(16.88 KiB) Downloaded 200 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: sending numbers over Rs232

Post by medelec35 »

Xavier wrote:I was having a bit of fun trying out some stuff on my own, but alas the results are poor
What results did you get when you transmitted the 25?
For testing purposes can you also program your tx flowchart to keep transmitting 57 and then see what results you get.
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

I got no results with the 25, tried sending 57 and got no results either. My LED does not flash this should mean that I do not go out of the loop. That is if I got the FC correct.

Xavier

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: sending numbers over Rs232

Post by medelec35 »

If It was me I would first establish if the data is being transmitted, and check on the RX that data is being received.
Can you connect an LED to RX pin of receiver and check it stays on, until data is received then it should flash with data, the go back back to being on solid.
If its not doing what it should be, then their is an issue with the switch so transmitter is not transmitting at all, or if transmitter is transmitting, is there continuity from TX (pin 10) of transmitter to RX (pin 12) of receiver.
If data is present on this pin is there a problem with the switch of the receiver?
That can be checked by the attached flowchart.
All I have done for test purposes is moved Print "Sample ="
so it only appears when switch is pressed and released.
Other thing to try is place a bit of code where you have Data_Received = 1
to light an LED for a second then it can go back out.
Just to show data has been received.
Attachments
RS232_RX V1.3.fcf
(16.52 KiB) Downloaded 225 times
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

Well I'm at a complete loss now Martin. I decided to go back to the basics that worked before but now I get this when sending a string. Ho I just found out that I can't post a jpg OK then when I press the send button the displayed "RS232" comes out looking like this #$÷×/"^:€*!/ and more characters than what are sent in the string. I've never had that problem before. And it worked yesterday while I was testing the RS232 send, receive
Attachments
TX_1.fcf
(11 KiB) Downloaded 205 times
RX_1.fcf
(11 KiB) Downloaded 199 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: sending numbers over Rs232

Post by medelec35 »

You have not included the name of string within receive string macro so LCD is probably just printing random characters?
Also for more than one char within a string, you either need a very tight loop (which you have not got) , or better still an RX interrupt
I have got 16F690's in work,
I should be able to get comms working from TX to RX.
If you can just set up the tx part of all the data you want to transmit,
Then if you have not been successful with RX side then I can post a working version for you.
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Thanks Martin I will look into that tomorrow, I'm starting to make stupid mistakes now so will give it a rest.

All the best and thanks for the help
Xavier

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: sending numbers over Rs232

Post by medelec35 »

Hi Xavier,
It must be an hardware issue your end.
I just loaded your original Tx that is sending bytes, and RS232_RX V1.3.fcf
I can see whatever is being sent on the display.
first I pressed switch on RX to wait for incoming RS232.
Then enabled TX to send 25 and the LCD shown 25.
Change TX to transmit different numbers e.g 0, 220 189 ect. and all worked just fine.

let me know if you want to send strings instead (req if numbers greater than 254 or letters, spaces etc require sending).
Perhaps it would be a good idea if you can post a full circuit diagram (including the relevant microcontrollers pin numbers),also including RX & TX both 16F690's connected together.
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

Haven't been feeling great today so have done very little but I do have coms between the two pic's I sent a string and it came up on the LCD so that is one thing out of the way. Now I just need to be able to send a number. How can I post a schematic? I wanted to post a jpg yesterday but I found that it could not be done. Do you have an email address that I can send it to?

Regards Xavier

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: sending numbers over Rs232

Post by medelec35 »

Pm sent.
connections should be correct if you can receive strings. As I stated above, just send as bytes like you did with your original tx flowchart.
Use rx 1.3. Unless you wish to send strings for a reason?


Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

It's sending and receiving but I do have an issue, if I send only once I do not receive but if I do a continuous send then I receive the data. I think that I mesed up either the TX or thr RX flow chart. Got your PM and am going to send you all relative info.

Best regards
Xavier

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

Been having Internet problems on my end for the best part of the day so I'm not sure if you received the email that I sent you, could you please confirm. Also could you post the two FC files that you used for testing as I think that I mesed things up on my side.

All the best Xavier

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: sending numbers over Rs232

Post by Xavier »

Hi Martin

Well got it working, sending numbers like I want it to :D now will I be able to get it to work in the programme the same way is another matter. Will keep you posted.

Regards Xavier

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: sending numbers over Rs232

Post by medelec35 »

Hi Xavier,
I have just had and idea.

Currently you need to transmit after pressing a switch in the correct order.
How about we change both flowcharts, so 2 bytes are always sent instead of 1 byte at a time.
The 1st byte is the reference to what data is going to be sent.
So if we send 1 1st that is settings, so the next byte sent is the settings data.
we send 2 1st that is Count up, so the next byte sent is the Count up data etc.
This way is does not matter what button is pressed, the receiver will know what to display and on what line of LCD.

Edit:
I have just looked at your flowchart, and you have got sending string instead of bytes in some places.
String is much more versatile and if receive flowchart is done correctly the you can receive numbers from 0 to 65535 and place then in a variable.
We can also send a letter first then the data.
The letter representing what data is about to be sent.
Then we can finish data by sending a space or full stop etc.
That will be better if ever going to use numbers greater than 254.

So do you want to use strings, or bytes?

You need to bare in mind that transmitting a single byte it can contain numbers from 0 to 254.
If sending string, then only a single number/character at a time is sent,
So if 254 is required, you will be sending 2 then 5 then 4 = 3 bytes
The value placed in a variable will be achieved by the RX flowchart.
Martin

Post Reply