Shop OBEX P1 Docs P2 Docs Learn Events
Basicstamp connectet to comport (receiving data) — Parallax Forums

Basicstamp connectet to comport (receiving data)

IguanIguan Posts: 8
edited 2009-10-20 15:05 in BASIC Stamp
Hello

I've got a Basic Stamp 2e and a Board of Education.
Now, I would like to receiving data on Hyperterminal.

I connected Pin 5 (GND) of my comport to VSS on my Education Board and
Pin 2 (RxD of com) is directly connectet to my I/O Pin 0. (I tried with a 22k resistor as well)

My simple program looks like this:

Main:
DO
·· SEROUT 0, 9600, [noparse][[/noparse]"Hello!", CR]
·· PAUSE 500
LOOP

END

But I don't receive any characters
Hyperterminal is set to 9600,8,N,1· Flow Control: None (i tried different settings)

whats wrong? rolleyes.gif
please help me!!

Best wishes

Iguan

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 18:35
    Read the chapter in the Basic Stamp Syntax and Reference Manual on the SEROUT statement or consult the equivalent entry in the Stamp Editor's help files. The 2nd item in the SEROUT statement is not the actual Baud. It's a value that specifies the Baud and some other configuration information for the serial I/O. The documentation gives the values required for various Bauds (and other factors) for various Stamp models including the BS2e.

    You need the 22K resistor if your comport provides an RS232 signal. You can damage the Stamp if you directly connect an I/O pin to an RS232 signal.
  • IguanIguan Posts: 8
    edited 2009-10-13 20:02
    Hi Mike, thanks for the quick reply

    My new code is:

    ' SERIN_SEROUT1.bs2
    ' Using two BS2-IC's, connect the circuit shown in the SERIN command
    ' description and run this program on the BASIC Stamp designated as the
    ' Sender. This program demonstrates the use of Flow Control (FPin).
    ' Without flow control, the sender would transmit the whole word "Hello!"
    ' in about 1.5 ms. The receiver would catch the first byte at most; by the
    ' time it got back from the first 1-second PAUSE, the rest of the data
    ' would be long gone. With flow control, communication is flawless since
    ' the sender waits for the receiver to catch up.

    ' {$STAMP BS2e}
    ' {$PBASIC 2.5}

    SO PIN 0 ' serial output

    #SELECT $STAMP
    #CASE BS2, BS2E, BS2PE
    T1200 CON 813
    T2400 CON 396
    T9600 CON 84
    T19K2 CON 32
    T38K4 CON 6
    #CASE BS2SX, BS2P
    T1200 CON 2063
    T2400 CON 1021
    T9600 CON 240
    T19K2 CON 110
    T38K4 CON 45
    #CASE BS2PX
    T1200 CON 3313
    T2400 CON 1646
    T9600 CON 396
    T19K2 CON 188
    T38K4 CON 84
    #ENDSELECT

    Inverted CON $4000
    Open CON $8000
    Baud CON T9600 + Inverted


    Main:
    DO
    SEROUT SO, Baud, [noparse][[/noparse]"Hello!", CR] ' send the greeting
    PAUSE 500 ' wait 2.5 seconds
    LOOP ' repeat forever
    END


    I tried it and the Hyperterminal showed "Hello!". But only without the resistor. And as soon as i disconnect the USB from my
    Education board. The Hyperterminal says nothing ;-(

    Do you know the reason?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 20:09
    You need to supply more information for me to answer your question. What do you have connected to what? What's "the USB"?
  • IguanIguan Posts: 8
    edited 2009-10-13 20:16
    My PC is connected via USB to the Board of Education (to transferring the program).
    the Pin 5 of the pc-comport is connected to the GND of the Board of Education and Pin2 (pc-comport) is connected to I/O-Pin 0 (On the Board of Education as well).
    The word "Hello!" appears on the Hyperterminal with that setting (without the resistor). As soon as i disconnect the programming cable (USB). The Hyperterminal doesn't show anything.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 22:39
    Perhaps there's something wrong with the ground connection from the USB to serial adapter to the BoE. The USB would provide another ground connection when it's plugged in. When you disconnect it, there's no complete circuit.

    If the USB to serial adapter provides an RS232 signal, it can damage the Stamp without the 22K resistor. If it provides a +5V logic signal, then you should be ok.

    What kind of USB to serial adapter are you using?
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-14 00:02
    So, it sounds like you have the USB connection to the BS2 for programming.

    Then, you're trying to use "pin zero" to talk from the BS2 to the PC.

    You CAN talk to the PC through the USB connection with "SEROUT 16, BAUD, [noparse][[/noparse]"Hello!",CR]"

    Usually to talk from a 'generic' I/O pin (like Pin zero) you need a MAX232 driver. It sounds like your PC is able to recieve a 0 to 5 volt signal and properly recieve it. If you connect the PC's TX signal to the BS2, you'll definitely need the 22 Kohm resistor. Signals going in the OTHER direction (from the BS2 TO the PC) don't need the resistor.
  • IguanIguan Posts: 8
    edited 2009-10-14 16:24
    >>So, it sounds like you have the USB connection to the BS2 for programming.
    thats correct
    >>Then, you're trying to use "pin zero" to talk from the BS2 to the PC.
    Thats also correct, it doesn't matter for me which pin...
    >>You CAN talk to the PC through the USB connection with "SEROUT 16, BAUD, [noparse][[/noparse]"Hello!",CR]"
    I would like to talk to the PC without USB (because i wrote a PC-program which can read comport charakters...)
    >>Usually to talk from a 'generic' I/O pin (like Pin zero) you need a MAX232 driver. It sounds like your PC is able to recieve a 0
    what do you mean with "generic I/O pin"? is Pin 0 a special case? ( i also tried with other I/O's but it doesn't work )
    I don't understand.. you mean, its not possible to talk to the PC whitout additional electronics?

    >>to 5 volt signal and properly recieve it. If you connect the PC's TX signal to the BS2, you'll definitely need the 22 Kohm >>resistor. Signals going in the OTHER direction (from the BS2 TO the PC) don't need the resistor.
    OK, I gonna use a resistor, but first I'd like to fix that problem in the OTHER direction (without resister)(BS2 to PC)
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-14 20:15
    The USB connection looks to the PC like it IS a "comport", so I'm still not sure why you're not using "SEROUT 16, ... "

    And the phrase "generic I/O pin like pin zero" means that pin zero is 'generic' like all I/O pins on the BS2 from 0 to 15. That "16" in "SEROUT 16, ..." is a 'pseudo-pin' meaning to the BS2 "Use the programming I/O port pins".

    Signal direction is very important in RS-232 communications. Your BS2 can 'talk' out pin zero to the PC's serial port RxD pin without a resistor. But if you connected your PC's TxD pin directly to a BS2 pin it would burn out the BS2's pin -- so in that direction (the PC 'talking' to the BS2) you MUST have the 22 Kohm resistor in series.
  • IguanIguan Posts: 8
    edited 2009-10-15 17:07
    Hi allanlane5 and thanks for the reply!

    >>The USB connection looks to the PC like it IS a "comport", so I'm still not sure why you're not using "SEROUT 16, ... "
    Because, at the end, i dont wanna use the Board of Education for that project.. (i wanna use that board only for testing)
    On top of that, im not sure, if my own written PC-program would work with that "virtual comport" and anyway, i dont have enough USB-Ports on my Notebook. My aim is to build a Notebook controlled robot (the BS2 is only for reading sensor data and sending it to the notebook)


    >>Signal direction is very important in RS-232 communications. Your BS2 can 'talk' out pin zero to the PC's serial port RxD pin without a resistor. But if you connected your PC's TxD pin directly to a BS2 pin it would burn out the BS2's pin -- so in that direction (the PC 'talking' to >>the BS2) you MUST have the 22 Kohm resistor in series.
    OK, I promise you, I gonna do that wink.gif
  • IguanIguan Posts: 8
    edited 2009-10-18 08:59
    Hello? Anybody here?
    I just wanted to know, if it is possible without adittional electronics, that the BS2 speaks to my PC via Comport (not the USB programming cable! (not the "virtual comport")
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-10-18 14:53
    The answer is: Yes.

    Post Edit -- You must use Inverted Baudmodes.

    SEROUT 0, 16468, [noparse][[/noparse]"hello!", CR]
    sends "hello!" out on P0, 9600 8N1.

    attachment.php?attachmentid=64475



    Post Edited (PJ Allen) : 10/18/2009 3:08:36 PM GMT
    418 x 261 - 16K
    229 x 377 - 17K
  • IguanIguan Posts: 8
    edited 2009-10-19 20:46
    YESSSSSSSSS!! Thats it!!! Thanks mate!

    The baud was wrong... i used:

    #SELECT $STAMP
    #CASE BS2, BS2E, BS2PE
    T1200 CON 813
    T2400 CON 396
    T9600 CON 84
    T19K2 CON 32
    T38K4 CON 6
    #CASE BS2SX, BS2P
    T1200 CON 2063
    T2400 CON 1021
    T9600 CON 240
    T19K2 CON 110
    T38K4 CON 45
    #CASE BS2PX
    T1200 CON 3313
    T2400 CON 1646
    T9600 CON 396
    T19K2 CON 188
    T38K4 CON 84
    #ENDSELECT

    Inverted CON $4000
    Open CON $8000
    Baud CON T9600 + Inverted
  • YoshtiYoshti Posts: 108
    edited 2009-10-20 15:00
    Hi all,
    On the subject:
    Serout 16 or Debug ? any real difference? which one is more efficient?

    The case is that I'll have a VB code read the incoming info. But don't care really if I miss the incoming data. The code will catch it eventually.

    Cheers,
    Yosh
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-20 15:05
    SEROUT 16 lets you use different baud rates. "DEBUG" is fixed at 9600.

    The SEROUT Formatters (like STR) are slightly different.

    SEROUT lets you use different pins if you want to, DEBUG is 'fixed' to port 16.

    For all these reasons, I prefer SEROUT 16.
Sign In or Register to comment.