Shop OBEX P1 Docs P2 Docs Learn Events
Using two serial ports as a bi-directional pipe — Parallax Forums

Using two serial ports as a bi-directional pipe

Don FrenchDon French Posts: 126
edited 2007-05-10 19:50 in BASIC Stamp
I want to use a BS2 with two serial connections and pass all bytes coming in either port out the other port. I tried the using the timeout feature of SERIN, as in the following:

Baud CON 84
Timeout CON 2

DO
SERIN RX\RTS,Baud, Timeout, NoData1, [noparse][[/noparse]dataByte]
SEROUT 16, Baud, [noparse][[/noparse]dataByte]
NoData1:
SERIN 16, Baud, Timeout, NoData2 [noparse][[/noparse]dataByte]
SEROUT TX\RTS, Baud, [noparse][[/noparse]dataByte]
NoData2:
LOOP

With a timeout value of 1, no characters are ever transmitted. With a timeout value of 2, it does fairly well, only dropping every third or fourth character. With a timeout of 3 and higher it drops about 3 out of every 4 characters.

Is there a way to do this that drops no characters? FWIW, I am using a HomeWork board and using the programming port for one port and a XBee RF modem for the other port.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-10 13:46
    One problem you have is that the BS2 has no serial buffer. If the code is not sitting in a SERIN statement, any bytes coming in will be ignored.

    Another problem you have is that it looks like you're trying to recieve (and pass on) one byte at a time. Each byte takes 1 mSec (at 9600 baud) to be recieved, but the SERIN statement takes like 500 uSec to execute. So there's a LOT of time there the BS2 is not 'listenting'.
  • Don FrenchDon French Posts: 126
    edited 2007-05-10 13:57
    Any suggestions on how to solve these problems given an asynchronous bi-directional data stream?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-10 14:11
    The only way would be to use a 3rd party serial input buffer in each direction. These are usually PICs preprogrammed with a small program to receive a serial stream and buffer it, then retransmit it with flow control to a Stamp or equivalent. They're typically an 8-pin part that either works without any external components or may require an external resonator. I've not had any personal experience with them, but I've seen 2 different sources on websearches. One example is: www.proteanlogic.com/product_periph_rs232.shtml.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-10 14:13
    I would recommend using an SX for this task. There have been a few examples of redirecting multiple serial inputs (even of different baud rates) to a single serial output using the SX. It has more than enough horsepower to do the job. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Don FrenchDon French Posts: 126
    edited 2007-05-10 16:49
    Erk! I was hoping someone would know how to do it with what I have here. Oh, well! Thanks to all who replied!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-10 17:28
    Don,

    Since the BASIC Stamp cannot monitor and receive Serial streams from more than one port at a time I don’t see how it could be done with a BASIC Stamp unless you have a large external FIFO buffer, but again, this wouldn’t be using what you have.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-10 19:24
    You could also try one of these:

    http://www.rhombus-tek.com/co-processors.html

    The "Simple Multi-Tasking" processor has a recieve-only UART buffer built in.
    You get info from it using SHIFTIN/SHIFTOUT.
  • Don FrenchDon French Posts: 126
    edited 2007-05-10 19:50
    Allan,

    That's pretty cool and not very expensive either! Thanks!

    -- Don
Sign In or Register to comment.