Shop OBEX P1 Docs P2 Docs Learn Events
Questions/problems with serial communications — Parallax Forums

Questions/problems with serial communications

MeepoMeepo Posts: 24
edited 2009-05-03 03:47 in BASIC Stamp
I'm trying to send strings of varying lengths from a Picaxe-08M to a BS2. I'm using bytes, but I could get away with nibbles if it makes the code tighter - I only need to send 16 codes maximum - however, the string of codes could be any length up to 16 bytes (or nibbles). I'm having problem making sense of the incoming serial stream on my BS2...I have no problem sending a known length of bytes, but I need to grab whatever comes down the line regardless of how many bytes there are, and I don't want to waste time sending 16 bytes every time (filling the unused bytes with nulls) if I'm only using a couple of them. Can someone point me to code, algorithms, or advice on how to do this?

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-03 02:49
    Hi, there are so many possibilities that it's hard to answer your question without more information.

    The first thing that came to my mind was the use of the STR formatter . The SERIN instruction uses STR to sequentially place incoming bytes of data into an array , STR has a "switch" that will cause the SERIN instruction to finish and move on if an incoming byte matches the "switch" value.

    For example the following will read 16 bytes or fewer if it sees the byte value of 13 (carriage return)

    myarray VAR Byte(16)

    SERIN rx,baud,[noparse]/noparse]STR myarray \16 \[color=red]13[/color

    Jeff T.
  • MeepoMeepo Posts: 24
    edited 2009-05-03 03:47
    Actually, that may be exactly what I was looking for, thanks a bunch! I'll try it first thing tomorrow, as I'm about to go to bed...would there be an equivalent parameter for the Picaxe?
Sign In or Register to comment.