Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication Question — Parallax Forums

Serial Communication Question

ArchiverArchiver Posts: 46,084
edited 2004-03-09 18:57 in General Discussion
Hi All,
Is it possible to use a BASIC stamp to receive serial data in the
form of 4800, 8, N, 1 and convert and send it to another device in
the form of 4800, 8, N, 2?

I was reading the manual and I don't think it can be done with the
STAMP, but I have been wrong before. Anyone have any thoughts on
this or know of another way to do it?

Thanks,
Jeff

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-05-02 05:09
    Jeff-

    A BS2* can receive at 4800,8,n,1. Because a stop bit and an idle
    line share the same line level, all you need do to transmit at
    4800,n,8,2 is wait about 0.208 msec before sending the next byte.
    If you're using a BS2, the interpreter will probably use up at least
    that much time setting up the SEROUT, if you SEROUT a byte at a time.

    What you can't do is accept a continuous 4800 baud stream, reformat
    it and send it back out continuously, because your Stamp can't SERIN
    and SEROUT at the same time, plus it would fall behind anyway since
    transmitting 11 bits would take longer than 10. But you can SERIN
    several bytes into variable storage space and then SEROUT them one at
    a time with two stop bits.

    Regards,

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-02 06:04
    Hi Steve,
    Here is the scenario. My repeater controller can only send 8, N, 1
    and my FT-1000D radio which I want to give the remote control
    commands can only receive 8, N, 2.

    I am not very good with bits and bytes, but maybe you hit on
    something.

    The remote control command sent to the radio consists of a 5 byte
    command from the controller. From what I read in the radio manual,
    each byte consists of a start bit, 8 data bits (bit 0 - bit 7) and 1
    stop bit. Everything is good except the radio needs 2 stp bits.

    I think I understand your reply in that I could read in the serial
    data at 4800, 8, N, 1 and send it back out at 4800, N, 1 and add
    another bit to simulate 2 stop bits. Am I correct?

    If so, any help or suggestions you have for programming to do this
    would be appreciated as I have not used a STAMP before.

    Thanks,
    Jeff

    --- In basicstamps@yahoogroups.com, "S Parkis" <parkiss@e...> wrote:
    > Jeff-
    >
    > A BS2* can receive at 4800,8,n,1. Because a stop bit and an idle
    > line share the same line level, all you need do to transmit at
    > 4800,n,8,2 is wait about 0.208 msec before sending the next byte.
    > If you're using a BS2, the interpreter will probably use up at
    least
    > that much time setting up the SEROUT, if you SEROUT a byte at a
    time.
    >
    > What you can't do is accept a continuous 4800 baud stream, reformat
    > it and send it back out continuously, because your Stamp can't
    SERIN
    > and SEROUT at the same time, plus it would fall behind anyway
    since
    > transmitting 11 bits would take longer than 10. But you can SERIN
    > several bytes into variable storage space and then SEROUT them one
    at
    > a time with two stop bits.
    >
    > Regards,
    >
    > Steve
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-02 14:30
    Jeff-

    The Stamp program would be very simple. If I understand the concept
    correctly:

    repeat forever
    {
    wait for five input bytes (4800,n,8,1)
    send first byte (4800,n,8,2)
    send second byte (4800,n,8,2)
    send third byte (4800,n,8,2)
    send fourth byte (4800,n,8,2)
    send fifth byte (4800,n,8,2)
    }

    In PBASIC for your Stamp, that would be something like:

    i VAR NIB
    cmd_bytes VAR BYTE(5)

    again:
    SERIN 0,baud,[noparse][[/noparse] STR cmd_bytes\5 ]
    FOR i = 0 TO 4
    SEROUT 1,baud,[noparse][[/noparse] STR cmd_bytes( i )]
    NEXT
    GOTO again

    Seems like nothing is ever as simple as it looks at first, but I
    don't think there'd be a whole lot more to it than this. This
    assumes the repeater controller works through I/O pin 0, and your
    radio is connected via I/O pin 1. The processing overhead
    associated with the FOR-NEXT loop and the SEROUT within it should
    provide ample idle time for a perceived second stop bit.

    Assuming the controller doesn't spew one 5-byte string on the heels
    of another (probably need ~5 msec break minimum), this should take
    care of the timing. Signal polarity and logic levels must also be
    considered in the choice of the value for "baud" above and may also
    require some level-shifting hardware external to the Stamp (see the
    Stamp manual for the gory details).

    Regards,

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 06:40
    Magnus-

    Assuming your PC's program can insert a non-ASCII numeric value prior
    to the command sequence:

    SERIN pin,baud,[noparse][[/noparse]length, STR command\length]

    Or, if ASCII numeric would be much easier:

    SERIN pin,baud,[noparse][[/noparse]length, STR command\length]

    Your PC would figure out how many command bytes it's about to send,
    then send that value in a byte followed by the real stuff. If high
    baud rate being used, this may not fly.

    Regards,

    Steve

    On 9 Mar 04 at 17:10, skogsvargen wrote:

    > Can anyone give me any ideas on how to implement a protocol that
    > allows me to receive commands with a size (4-8 bytes) unknown by
    > the Stamp...
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 06:43
    Sometimes these senior moments just seem to go on and on and on...

    On 9 Mar 04 at 14:40, S Parkis wrote:

    > Or, if ASCII numeric would be much easier:
    >
    > SERIN pin,baud,[noparse][[/noparse]length, STR command\length]

    Better make that:

    SERIN pin,baud,[noparse][[/noparse]DEC1 length, STR command\length]
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 17:10
    Hi,
    I am currently trying to implement a protocol to transmit commands
    between my PC and my BS2e. The link is a small radio modem. I run
    into problems when i need to send commands of varying length to the
    Stamp. Can anyone give me any ideas on how to implement a protocol
    that allows me to receive commands with a size (4-8 bytes) unknown
    by the Stamp. The alternative is to use a fixed length message from
    the PC, but this seems lik an innefficient way to solve things...

    Any ideas?

    /Magnus, Stockholm, Sweden
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 17:59
    MyData VAR BYTE(8)
    SERIN MyPin, MyBaud, [noparse][[/noparse]STR MyData\8\0]
    ' The above says, recieve 8 bytes, or to first 0,
    ' whichever comes first. Thus, you can use some
    ' specific value to end your messages at 4 bytes.


    --- In basicstamps@yahoogroups.com, "skogsvargen" <skogsvargen@h...>
    wrote:
    > Hi,
    > I am currently trying to implement a protocol to transmit commands
    > between my PC and my BS2e. The link is a small radio modem. I run
    > into problems when i need to send commands of varying length to the
    > Stamp. Can anyone give me any ideas on how to implement a protocol
    > that allows me to receive commands with a size (4-8 bytes) unknown
    > by the Stamp. The alternative is to use a fixed length message from
    > the PC, but this seems lik an innefficient way to solve things...
    >
    > Any ideas?
    >
    > /Magnus, Stockholm, Sweden
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 18:28
    You can use the STR modifier with SERIN and a specified ending
    character. You'll have to modify the PC end so that your termination
    character is appended to each packet. Your Stamp will need to have an
    array defined to capture your maximum data length.


    ETX CON 3

    buffer VAR Byte(8)

    ...

    SERIN Rx, Baud, [noparse][[/noparse]STR buffer\8\ETX]


    Read up on the details in the Help file or manual (see SERIN).

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: skogsvargen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=UXB05S9-r4kEaK0L-2L5tbk3tjcgU_9zRFalZXoLpRCA7KqtVQrGhEWwT9HGkizAynhkdh35NJGz4i1QNVf4F8M]skogsvargen@h...[/url
    Sent: Tuesday, March 09, 2004 11:10 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Serial communication question


    Hi,
    I am currently trying to implement a protocol to transmit commands
    between my PC and my BS2e. The link is a small radio modem. I run
    into problems when i need to send commands of varying length to the
    Stamp. Can anyone give me any ideas on how to implement a protocol
    that allows me to receive commands with a size (4-8 bytes) unknown
    by the Stamp. The alternative is to use a fixed length message from
    the PC, but this seems lik an innefficient way to solve things...

    Any ideas?

    /Magnus, Stockholm, Sweden
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-09 18:57
    Two things come to mind.

    First, if you are transmitting only 7-bit ASCII data, set the
    high-order bit of the last command byte. The Stamp can use this extra
    bit to detect end-of-command.

    Second, let the first byte indicate how many bytes follow, but as an
    ASCII letter. That is, if four bytes of command follow, send a "D".
    This first letter can be converted to a numeric value by anding it
    with 0x0F, which will give you up to 15 bytes.

    Russ


    --- In basicstamps@yahoogroups.com, "skogsvargen" <skogsvargen@h...>
    wrote:
    > Hi,
    > I am currently trying to implement a protocol to transmit commands
    > between my PC and my BS2e. The link is a small radio modem. I run
    > into problems when i need to send commands of varying length to the
    > Stamp. Can anyone give me any ideas on how to implement a protocol
    > that allows me to receive commands with a size (4-8 bytes) unknown
    > by the Stamp. The alternative is to use a fixed length message from
    > the PC, but this seems lik an innefficient way to solve things...
    >
    > Any ideas?
    >
    > /Magnus, Stockholm, Sweden
Sign In or Register to comment.