Shop OBEX P1 Docs P2 Docs Learn Events
com1 — Parallax Forums

com1

leshea2leshea2 Posts: 83
edited 2006-02-09 16:06 in BASIC Stamp
Can I get the basic stamp to send and receive data to and from my computer's com port, and if so, would I use the serin, serout commands or some other commands ?

Thanks !

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-30 23:55
    SERIN and SEROUT will do the trick.· How do you want to connect to your BASIC Stamp?· Programming port?· If yes, then you would use pin 16 in SEROUT and SEROUT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • leshea2leshea2 Posts: 83
    edited 2006-02-06 20:35
    How do I get the stamp to send out text to com prot 16 ? So far, all that comes out on the screen is something like this,
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 21:18
    You simply specify [noparse][[/noparse]virtual] pin 16 in your SERIN and SEROUT statements.· I think "magic numbers" are bad form in the middle of a program, so I would do something like this:

    Sio·····CON·····16

    ... then in your program:

    · SEROUT Sio, Baud, [noparse][[/noparse]"Here is a string!"]

    Baud is also a constant that is appopriate for your Stamp module and baud rate, and must be set to Inverted mode.· I have posted on setting baudmode dozens of times through our forums.· And yes, you can use the programming port (pin 16) to "talk" with other programs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • leshea2leshea2 Posts: 83
    edited 2006-02-06 22:48
    Ok, but this is the code that I have right now,

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}



    YMTU VAR Word
    GJH VAR Word

    TGM DATA "God Bless The World !", 0



    Main:
    YMTU = TGM
    GOSUB Main2
    END


    Main2:
    PAUSE 20
    READ YMTU, GJH
    YMTU = YMTU + 1
    IF (GJH = 0) THEN GOTO Main ELSE SEROUT 16, 9600, [noparse][[/noparse]GJH]
    GOTO Main2


    Is there anything wrong with it ?

    Thanks !
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 23:23
    Leshea,

    Your program does exactly what I suggest it shouldn't -- it embeds "magic numbers" (numeric constants) in the operational code.· You might want to have a look at our document The Elements of PBASIC Style, and then study the online help file for any of the instructions you think you'll want to use (there's a lot of stuff in our manual, the answers are there).

    In the·meantime I've·rewritten your program following our suggested style guidelines and conforming to PBASIC 2.5.·I will ask just one thing: you actually study the code, and don't post anything else that you haven't tested in your editor.· ·You ask if anything is wrong with your program and the editor would have complained and directed you right to the offending code.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-07 20:44
    Oh, yes, and the SEROUT 'baud constant' should NOT be "9600". Instead, you should look in the manual, under the SEROUT command, to find the 'baud constant' value that corresponds to 9600 baud.

    (Or, you could just use the attachment Jon gave you above.)
  • leshea2leshea2 Posts: 83
    edited 2006-02-08 20:19
    I revised my code and it works, but I can't seem to get it to be in sync with my PC program. What I mean is, if I run my program first, then run my basic stamp, everything works fine, but if I run my stamp first and then my program, the input command in my program receives the basic stamps input too late, and prints (d Bless The World !) instead of the full message (God Bless The World !). So my question is would that be on the BS2sx side or on my programs side, and is there a command that would fix this on the side of my BS2sx ?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-08 20:56
    This sounds like a job for handshaking: RTS sent from STAMP gets a CTS back from the "program" and then the STAMP sends its message.· Or the STAMP could wait for a DTR (an input to Fpin)·from the "program", no message sent till DTR is asserted.

    Post Edited (PJ Allen) : 2/8/2006 9:01:26 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-08 21:05
    PJ,

    ·· RTS and CTS would be the lines used for flow control.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-08 21:28
    1. DTE sends DTR to DCE (Data Terminal Ready)
    2. DCE responds by sending DSR to DTE (Data Set Ready)
    3. DTE sends RTS to DCE (Ready to Send)
    4. DCE responds to RTS by sending DTE a CTS (Clear to Send)

    · With SEROUT, Fpin is made an input.· Someone will have to determine whether "the program" has an output that the STAMP can use as a cue for its transmission to begin.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-08 22:18
    Um, guys, RTS is looped to CTS on the '16' port. And DTR actually RESETS the BS2 on the 16 port.

    The advice you gave is valid if you're using a modem, but not on the '16' port of the BS2.

    So, Leshea2, the simple answer to your problem is to have the BS2 wait on a SERIN when it comes up.

    The PC then sends something to the BS2, to tell it it's ready for data.

    The BS2 then sends the desired string to the PC.

    That's how you get the synchronization you're looking for, without requiring extra wires or hardware.
  • leshea2leshea2 Posts: 83
    edited 2006-02-08 22:32
    Thanks, that's vary helpful !
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-08 22:33
    Well, y'know something, guy?......
    I'm aware the person is using the STAMP programming connector and..... (slow burn)..... far be it for the likes of me, but.....

    I have nothing further.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-02-09 02:59
    Leshea2,

    The reason it works when you run the PC program first is because the PC program is waiting before the BS2 starts sending, so it catches the whole string. When you start the BS2 first, it has already sent some characters when the PC program begins looking for input, and it misses the first characters.

    You can use hardware control to sync it up, but you can also mess around with the transmit and receive timings on both sides of the serial cable (meaning on the PC & BS2). BTW, what language / IDE are you creating your PC program with?
  • Paul Sr.Paul Sr. Posts: 435
    edited 2006-02-09 12:39
    PJ Allen said...
    Well, y'know something, guy?......
    I'm aware the person is using the STAMP programming connector and..... (slow burn)..... far be it for the likes of me, but.....

    I have nothing further.

    Please, don't stop now, I'm still laughing about the Darth Vader thread........
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-09 15:07
    Okay,

    ·· Let me clarify the whole flow control thing.· There will be none on the programming port.· Asserting DTR there will serve to simply reset the BASIC Stamp.· RTS and CTS and not implemented in a flow-control fashion on this port.· RTS is looped to DSR, not CTS.

    ·· When using standard I/O pins for serial interface there are options for implementing flow control using RTS/CTS but no provision for implementing DTR/DSR, which basically says, "Hey I'm here and ready to do business."· The basic RTS/CTS flow control system is all that's needed to dramatically increase the reliability of serial communication on the BASIC Stamp side when talking to devices that support it since the BASIC Stamp is no longer required to be right there waiting when the other device wants to send data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cindalusiacindalusia Posts: 2
    edited 2006-02-09 15:42
    Hello!

    I'm sorry, I don't quite follow your last post. Is this correct?

    The programming port does not support flow control. I can use neither RTS/CTS nor DTR/DSR.·Asserting DTR will reset the stamp.

    If I were to use another serial port (ie not the programming port), I would be able to use RTS/CTS, but I still not be able to use DTR/DSR.

    Thanks!

    Cindy
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-09 16:06
    Cindy -

    Everything you say IS CORRECT. You will need to assign an additional pin for use as the flow control pin. See the PBASIC Manual or the PBASIC Help File for additional information.

    RTS/CTS should be all you need to establish flow control. In other words, there should be no need for DTR/DSR.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
Sign In or Register to comment.