Shop OBEX P1 Docs P2 Docs Learn Events
Basic Serin Serout question — Parallax Forums

Basic Serin Serout question

Jason ShortJason Short Posts: 21
edited 2005-08-26 11:58 in BASIC Stamp
I am playing around with Serin and Serout and everything seems to be working except the characters I see in my terminal program are not correct. For example an 'f' appears as a '4' every time.
My setup:
Mac OS X Tiger,
BS2 on a INEX-1000 training board
Keyspan serial adapter - 19HS
I've used Xterm, GoSerial, and MacBS2 with the same results.

Debug calls work fine. I can see my Debug "Hello World!" , but when I do a serout from a pin, I get ...H#EbDo...

Here is the code:
SEROUT 6, 16468,[noparse][[/noparse]"Hello World!"]

I tried to echo back the characters with this
SERIN 7, 16468, [noparse][[/noparse]inFromSerial]
SEROUT 6, 16468, [noparse][[/noparse]inFromSerial]

and I just got back oddly mapped characters.

I poked around Zterm's options but I'm overwhelmed by them all. like what is the difference between VT100 and PC-ANSI BBS? Who knows.

This should be a simple fix,
thanks anyone for the help.
Jason

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-25 12:32
    DEBUG works because the serial data is going through a set of inverters that are part of the programming port -- those inverters do not exist on the standard I/O pins. You might try changing the baud parameter to 84.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • stamptrolstamptrol Posts: 1,731
    edited 2005-08-25 12:40
    Jason,

    You're transmitting at 9600, 8, no parity. Double check that your terminal program is set the same. A common problem is to have it set for 9600, 7, even.

    Your echo back test won't work because you're listening with the SERIN before you're sending with the SEROUT.
    Even if you change the order, you probably won't see anything intelligent. The Stamp can only do one thing at a time.

    Also, 9600 is pretty fast for the BS2. Drop down to 2400 until you get things working.

    To see the Stamp receive things, set up a SERIN with the WAIT parameter. ( see the Help files)Then, from the terminal program type a few characters including the one the Stamp is watching for and the Stamp will grab it.

    This stuff will work reliably......keep at it!

    Tom Sisk
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-25 12:55
    The BS2 has no problems with 9600 baud -- in fact, we routinely use 38.4 kBaud (and higher) with the BS2 to move things along (this is why it's the fast setting for our PSC).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jason ShortJason Short Posts: 21
    edited 2005-08-25 16:33
    So when you mean inverters are you saying the bits may be coming in backwards or the voltage is inverted?

    I've double checked the Zterm program and it's set to 8N1 with no flow control.

    I got out the binary calc to investigate and noticed my 'f' was coming in as a 6.
    f = 102= 0110 0110
    6 = 54 = 0011 0110

    here is what delete does:
    del = 127 = 0111 1111
    x = 120 = 0111 1000

    ! = 33 = 1000 0100
    H = 72 = 0100 1000

    ok, well I thought I was on to something there but there's no pattern.

    Im not clear on why the order mattered on my Serin vs Serout
    I want to listen for a character from the term program and when I get it fire it back. Why won't that work? I'm actually counting on the fact that the BS2 can only do one thing at a time. I assumed serin would just sit there waiting for some input and not continue further execution. In fact it appears to be behaving this way in my loop:


    inFromSerial VAR BYTE
    main:
    SEROUT 6, 16468,[noparse][[/noparse]"Hello"]
    SERIN 7, 16468, [noparse][[/noparse]inFromSerial]
    PAUSE 100
    SEROUT 6, 16468,[noparse][[/noparse]inFromSerial]
    GOTO main


    I just wish there was some other way to investigate my problem. I feel rather silly.
    Jason
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-08-25 16:46
    From the SEROUT command in the editor help file:

    All BASIC Stamps (including the BS1) can also transmit RS-232 data through any of their I/O pins (Tpin = 0 - 7 for BS1, Tpin = 0 - 15 on all other BASIC Stamps). The I/O pins only provide a 0 to +5 volt swing (outside of RS-232 specs) and may need to be connected through a line driver for proper operation with all serial ports. Most serial ports are able to recognize a 0 to +5 volt swing, however. See the figure below sample wiring.

    There are schematics there as well discussing your issue.

    Did you also try Jon's suggestion of trying a baudrate of 84 to get TRUE instead of the INVERTED that you are currently using?

    Can you verify that you have leveled the voltages from 0 to 5v (for proper communication with a Stamp) rather than the standard RS232 voltage levels of (possibly) -15v all the way to +15v?

    (Just for fun:

    Ever notice that every serial port on your PC is male and every modem serial port is female? RS-232-C standard states that DTE port connectors are all male and all DCE port connections will be female~

    Standard RS232 uses +3v to -3v as a 'noise' zone- above +3 is 'space', below -3 is 'mark'- )


    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com

    Post Edited (Ryan Clarke (Parallax)) : 8/25/2005 4:49:32 PM GMT
  • Jason ShortJason Short Posts: 21
    edited 2005-08-25 16:58
    Yes, I read that, but i dismissed it since I can successfully debug and write program files to the BS2 over the same serial adapter/port. Is this a bad assumption? I'm using the Keyspan 19HS as recommended by the Physical Computing book and they don't mention this limitation. I'll try on a PC tomorrow.

    I'm also getting persistent results and I assumed any voltage issues would show up as some random noise.

    Thanks,
    Jason
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-08-25 17:27
    You are aware that the 'dedicated' serial pins on the stamp are level shifted/conditioned for you, where as using other standard I/O pins do NOT have RS232 shifting done for you automatically (hence the need for something like a MAX232 IC)-

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com
  • Jason ShortJason Short Posts: 21
    edited 2005-08-26 04:27
    So I went home and tried the suggestion about the Baud rate set to 84 and within 30 seconds I had a working setup. I'm almost disappointed it wasn't something harder since I spent two hours last night trying to figure it out!

    The solution...

    main:
    SEROUT 6, 84, [noparse][[/noparse]"Hello World!",10,13]
    PAUSE 100
    GOTO main

    Thanks so much!
    Jason
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-26 11:58
    It's always the easy stuff we take for granted....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.