Shop OBEX P1 Docs P2 Docs Learn Events
Sx-28 serout — Parallax Forums

Sx-28 serout

JumpkickJumpkick Posts: 19
edited 2006-02-20 17:18 in General Discussion
All of the examples for SEROUT have something like this

SEROUT RA.0, N9600,[noparse][[/noparse] LF,CR,"24C01A",LF,CR]

But that will not compile in SX-Key v3.10 that I am running. How am I supposed to send like that?
Right now in order to send 3 bytes I would end up doing

SEROUT RA.0, N9600,byte1
SEROUT RA.0, N9600,byte2
SEROUT RA.0, N9600,byte3

but that is a very poor design.

Any suggestions?
·

Comments

  • Mike CookMike Cook Posts: 829
    edited 2006-02-18 02:04

    Attached is an example of sending bytes and strings. It uses mostly subroutines written by Jon Williams (Forum Moderator). Written for the Parallax Professional Development Board but will work on the SX tech board with a few mods.

    Parallax Professional Development Board:

    Connect RA.0 to X13-2 (RS-232 driver)



    SX Tech board:

    In the program change:

    PcTxBaud CON "T9600" ' PC Baud Rate (MAX-232) 9600,8,N,1

    to:

    PcTxBaud CON "N9600" ' PC Baud Rate (INVERTED) 9600,8,N,1

    Then RA.0 will go directly to pin 2 on your PC's serial port. You'll need a terminal program to receive the data



    Compile the program & program the part, insure the FREQ directive matches whatever type of resonator that you are using. The internal clock is not accurate enough for serial communication so make sure your using a resonator or a crystal.

    By putting most SX/B commands in subroutines, will save code space, do a <CTRL>-L to look at the assembly, if your interested.

    Mike




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $17.49

    Product web site: http://www.allsurplus.net/Axiom/

    Post Edited (Mike Cook) : 2/18/2006 5:12:01 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-18 04:49
    This thread is being moved from the BASIC Stamp Forum to the SX Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-20 16:29
    I don't think there are·examples with the BS2-type syntax you use below in the SX/B help file, but if you happen to find one, please let me know and I will fix it.· SX/B sends just one byte at a time, and the transmission of strings is possible with a subroutine.· This one, for· example, works pretty well in my projects.:

    ' Use: TX_STR [noparse][[/noparse] string | label ]
    ' -- "string" is an embedded literal string
    ' -- "label" is DATA statement label for stored z-String

    TX_STR:
    · temp1 = __PARAM1····························· ' get string offset
    · temp2 = __PARAM2····························· ' get string base
    · DO
    ··· READ temp2 + temp1, temp3·················· ' read a character
    ··· IF temp3 = 0 THEN EXIT····················· ' if 0, string complete
    ··· SEROUT SOut, Baud, temp3··················· ' send the byte
    ··· INC temp1·································· ' point to next character
    ··· temp2 = temp2 + Z·························· ' update base on overflow
    · LOOP
    · RETURN


    I will update the SEROUT demos to include a string TX subroutine -- this one happens to be in READ because that's a key element of retrieving the string characters from a stored (either inline or in DATA statements) string.· Using this subroutine you can do this:

    · TX_STR MyStr

    ... where MyStr is defined as:

    · DATA·· LF, CR, "24C01A", LF, CR, 0

    Just make sure you have constant definitions for LF an CR as they are not predefined by the compiler.· You also need to declare the subroutine:

    TX_STR··· SUB··· 2

    Two parameters are required because the address of the string uses two bytes (base + offset).· You can also use the subroutine above to send inline strings, but they must be enclosed in quotes -- you can't separate elements with commas as in you BS2-style example:

    · TX_STR "24C01A"


    Jumpkick said...
    All of the examples for SEROUT have something like this

    SEROUT RA.0, N9600,[noparse][[/noparse] LF,CR,"24C01A",LF,CR]

    But that will not compile in SX-Key v3.10 that I am running. How am I supposed to send like that?
    Right now in order to send 3 bytes I would end up doing

    SEROUT RA.0, N9600,byte1
    SEROUT RA.0, N9600,byte2
    SEROUT RA.0, N9600,byte3

    but that is a very poor design.

    Any suggestions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 2/20/2006 5:31:52 PM GMT
  • JumpkickJumpkick Posts: 19
    edited 2006-02-20 17:18
    Thank you very much for your response.
Sign In or Register to comment.