How do I read rs232 and get correct byte into variable?
Moderator: Benj
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
How do I read rs232 and get correct byte into variable?
Question 1
Let's say I want to send 5 bytes of data to control my cable reel. How do i ensure that i put correct byte into each variable?
Maybe first byte is always value 120?
Question 2
Also want to use a bit to tell on or off,and a bit to tell direction,and a bit to tell high gear,and a bit to tell if its low gear,
Can I write a decision to look at single bit?
Let's say I want to send 5 bytes of data to control my cable reel. How do i ensure that i put correct byte into each variable?
Maybe first byte is always value 120?
Question 2
Also want to use a bit to tell on or off,and a bit to tell direction,and a bit to tell high gear,and a bit to tell if its low gear,
Can I write a decision to look at single bit?
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: How do I read rs232 and get correct byte into variable?
As you suggest sending a special first byte to signal the start of a sequence is a good way. Preferably a value that does not occur in the other bytes. Sending a checksum byte after the other bytes to ensure correct reception might be useful as well. (Simply add all bytes in a byte variable, ignoring overflow should work)markus747 wrote:Question 1
Let's say I want to send 5 bytes of data to control my cable reel. How do i ensure that i put correct byte into each variable?
Maybe first byte is always value 120?
In the decision logic use something likemarkus747 wrote: Question 2
Also want to use a bit to tell on or off,and a bit to tell direction,and a bit to tell high gear,and a bit to tell if its low gear,
Can I write a decision to look at single bit?
Code: Select all
( VAR & 0x10 ) = 0x10
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: How do I read rs232 and get correct byte into variable?
Here is two versionsz of Tx for sending data to Rx and one of Rx...Question 1
Let's say I want to send 5 bytes of data to control my cable reel. How do i ensure that i put correct byte into each variable?
Maybe first byte is always value 120?
Second question is answered by Kersing...Question 2
Also want to use a bit to tell on or off,and a bit to tell direction,and a bit to tell high gear,and a bit to tell if its low gear,
Can I write a decision to look at single bit?
Enamul
- Attachments
-
- RX_STR_RS232.fcf
- (12 KiB) Downloaded 387 times
-
- TX_STR_RSZ232.fcf
- (10 KiB) Downloaded 342 times
-
- TX_RSZ232.fcf
- (11 KiB) Downloaded 353 times
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: How do I read rs232 and get correct byte into variable?
I am using RealTerm to send data to my pic and it seems a start bit is always used can I enable start Bit in the RS232 component macro?
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: How do I read rs232 and get correct byte into variable?
it's automatically done by pic usart. What do you mean by real term? did you mean real time?markus747 wrote:I am using RealTerm to send data to my pic and it seems a start bit is always used can I enable start Bit in the RS232 component macro?
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: How do I read rs232 and get correct byte into variable?
RealRerm is a terminal software I am using to send a single byte out serial port, on my windows machineEnamul wrote:it's automatically done by pic usart. What do you mean by real term? did you mean real time?markus747 wrote:I am using RealTerm to send data to my pic and it seems a start bit is always used can I enable start Bit in the RS232 component macro?
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: How do I read rs232 and get correct byte into variable?
even if you use 2 stop bits?Enamul wrote:it's automatically done by pic usart. What do you mean by real term? did you mean real time?markus747 wrote:I am using RealTerm to send data to my pic and it seems a start bit is always used can I enable start Bit in the RS232 component macro?
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: How do I read rs232 and get correct byte into variable?
Ok.,.,I got it., I have used terminal software which is good other than windows hyperterminal...so have you managed to transfer data from pc to your PIC board? By the way have you used matrix RS232 board or you have made any custom board to interface between PC and PIC as you have to use for voltage level conversion. PC uses +12.,-12CV swing in RS232 whereas PIC uses only 5V to 0V.RealRerm is a terminal software I am using to send a single byte out serial port, on my windows machine
Regarding your post of stop bit..in pc you can send 1 or 2 stop bit but in flowcode default is (9600,N,1,8), so to change this I believe we have to change in c code., But first of all what you are trying to do...there might be an alternative to that., so please let us know what is your plan...
Enamul
-
- Posts: 33
- Joined: Mon Jul 23, 2012 7:17 pm
- Location: Petaluma california USA
- Has thanked: 26 times
- Been thanked: 2 times
- Contact:
Re: How do I read rs232 and get correct byte into variable?
I am using a ADM232LJN (max232 also makes similar chip)16 Pin dip chip to convert levels for pin 25 and 26 for either pic16f877 or pic16f887 and it seems to receive data good with 1 stop bit even seems to work with 2 stop bits but maybe some data is being tossed.
Another note my programming partner in other room got a pic to use standard pic levels 0 and +5 and had good data transfer without level converter!!! and have a small menu appear! only using a fet to invert incoming data and it worked fine.
I am still working on same reel project shown in active low thread and have made a lot of progress with this awesome program in just a week.
I don't see how the DATA[5] array is created I attempted to copy DATA = DATA0 into a calculation. from file RX_STR_RS232-1.FCF
I am still working on same reel project shown in active low thread and have made a lot of progress with this awesome program in just a week!!!
But it gives error "attempt to index non array object" when creating calculation
I = 0
VAR1 = 0
VAR2 = 0
VAR3 = 0
VAR4 = 0
VAR5 = 0
This above is another calculation but I don't see how this creates data[5] array
TIA
Another note my programming partner in other room got a pic to use standard pic levels 0 and +5 and had good data transfer without level converter!!! and have a small menu appear! only using a fet to invert incoming data and it worked fine.
I am still working on same reel project shown in active low thread and have made a lot of progress with this awesome program in just a week.
I don't see how the DATA[5] array is created I attempted to copy DATA = DATA0 into a calculation. from file RX_STR_RS232-1.FCF
I am still working on same reel project shown in active low thread and have made a lot of progress with this awesome program in just a week!!!
But it gives error "attempt to index non array object" when creating calculation
I = 0
VAR1 = 0
VAR2 = 0
VAR3 = 0
VAR4 = 0
VAR5 = 0
This above is another calculation but I don't see how this creates data[5] array
TIA
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: How do I read rs232 and get correct byte into variable?
I don't see how the DATA[5] array is created I attempted to copy DATA = DATA0 into a calculation. from file RX_STR_RS232-1.FCF
But it gives error "attempt to index non array object" when creating calculation
I = 0
VAR1 = 0
VAR2 = 0
VAR3 = 0
VAR4 = 0
VAR5 = 0
This above is another calculation but I don't see how this creates data[5] array
I have created array as normal variable declaration..I am posting here a screen shoot showing how to declare array variable with different array size...In the create a new variable window, write your array name in Name of new variable box while string is selected in bottom..put array size in third bracket..
Also for the newbie..it's good to go through the following MM course as it's freeee....but nice for knowing some basic tips and tricks
http://www.matrixmultimedia.com/courses/itm/index.php
I am using a ADM232LJN (max232 also makes similar chip)16 Pin dip chip to convert levels for pin 25 and 26 for either pic16f877 or pic16f887 and it seems to receive data good with 1 stop bit even seems to work with 2 stop bits but maybe some data is being tossed.
Yes. ADM232LJN is similar to MAX232 and that's fine. It's better to use 1 stop bit as PIC is following 1 stop bit protocol..
Another note my programming partner in other room got a pic to use standard pic levels 0 and +5 and had good data transfer without level converter!!! and have a small menu appear! only using a fet to invert incoming data and it worked fine.
Actually you can do the level conversion using FET or transistor...I guess your friend is doing the that or he's using a board which doing that. It's pretty simple when dealing with TX from PC, send that to transistor base and collector supply will be 5V...then PIC will see 5V..on the contrary, for PIC Tx, send that to another transistor base whose power supply is 12V...so PC will see that 12V..
Enamul
- Attachments
-
- Array.PNG
- (23.39 KiB) Downloaded 4533 times