Shop OBEX P1 Docs P2 Docs Learn Events
Serout freezes everything — Parallax Forums

Serout freezes everything

linocklinock Posts: 31
edited 2006-02-05 11:22 in BASIC Stamp
Me again..i know shakehead.gif

Here's the thing that happens.
I have a little bit of code which displays a value taken from rctime.
It works fine displaying the values towards the parallel lcd but i wished also to send the values displayed on the lcd to the serial port of my computer and btw display those values to a simple terminal.

Why this example won't work ?

serial:

SEROUT 16,16484,[noparse][[/noparse]"Test"]

RETURN

whatever i try when i launch the terminal program (hyperterminal configured with 9600, N, 8, 1) everything freezes, even the LCD display. When closing the terminal program then everything restarts working as usual.

Post Edited (linock) : 2/4/2006 2:10:32 PM GMT

Comments

  • SamMishalSamMishal Posts: 468
    edited 2006-02-04 16:43
    Hi Linock

    Make surte that the SX-Key is not connected to your serial port
    while you are trying to SEROUT from the SX to the HyperTerminal
    unless you are using a different s-232 alltogether.

    Of course if you do not have the SX-Key then you need
    to install the resonator crystal.

    Samuel
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-04 17:14
    Thread moved to BASIC Stamp forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-04 17:25
    It's likely you have an incompatibility with your baudmode settings.· This is another case where conditional compilation can be really helpful.· First, in setting serial baudmode parameters.· This is from the standard template (attached) that I use:

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


    SevenBit······· CON···· $2000
    Inverted······· CON···· $4000
    Open··········· CON···· $8000


    Baud··········· CON···· T9600

    What I would do in your case is define two baud parameters:

    LcdBaud········ CON···· Inverted | T9600
    PcBaud········· CON···· T9600


    Now you can create a conditional switch to direct your program:

    #DEFINE __LcdMode = 1

    With this definition, your intent is to direct the output to the LCD.· By changing the value to 0 your intent is to direct the output to the PC.· And here's how you make that happen:

    #IF __LcdMode #THEN
    ··SEROUT LcdPin, LcdBaud, [noparse][[/noparse]"Test"]
    #ELSE
    · SEROUT PcPin, PcBaud, [noparse][[/noparse]"Test"]
    #ENDIF


    The danger of embedding "magic numbers" (i.e., numeric values for pin numbers, baudmode values, etc.) is that errors are very easily introduced when attempting to change the behavior of a program.· By adopting the guidelines of The Elements of PBASIC Style you will save yourself a lot of trouble, and with Conditional Compilation techniques you can make your program flexible for a wide variety of modules/applications.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • linocklinock Posts: 31
    edited 2006-02-04 21:40
    Thank you for all this documentation.
    I've found some code portions in the manual and while browsing it i found that my sx2 was not correctly detected.
    So i fixed the sentence directly with serout 16,245,[noparse][[/noparse]DEC result] using the code example and finally i got the result in the debug window but it doesn't seems to whish to work with hyperterm. Then i started playing with Stamp Plot and no more success with it.

    Now i found what is responsible of all this. In the Stamp plot, there's a note about the effects of DTR which may affect transmissions.
    When DTR is enabled, everything freezes, lcd display, serial connction, when disabling DTR, everything restarts working just as nothing happened.
    So all this is due to a misconfiguration in the RS 232 plug but i don't know where i made a mistake.

    PIN_________PIN
    DB9_________BS2
    2 __________ 1
    3 __________ 2
    4 __________ 3
    5 __________ NC
    6-7 ************ NC

    so i will have a look again at the documentation about this step smile.gif

    Post Edited (linock) : 2/4/2006 9:46:20 PM GMT
  • linocklinock Posts: 31
    edited 2006-02-05 11:22
    ok i'm naughty i didn't looked at the documentation as i said, i simply added a dip switch which toggles the Sub D9 pin 4 on or off. This way i can send program to the Basic Stamp, pin 4 switched on or switched off to use the same Sub D9 to transmit to a terminal without having to mount another Sub D9 on the board as suggested somewhere on the forum...ok it's quick and dirty but it works smile.gif
Sign In or Register to comment.