Shop OBEX P1 Docs P2 Docs Learn Events
timeout for Simple_Serial read? — Parallax Forums

timeout for Simple_Serial read?

janbjanb Posts: 74
edited 2007-01-07 02:24 in Propeller 1
Hi,
I'm using Simple_Serial OBJ to read characters from pin=26=Rx:
rs: "Simple_Serial"
...
·rs.start(26,-1,9600)
...
repeat 'endless loop
· · c:=rs.rx
··· tv.out(c)

It may happen the sender is not functioning and I'd like to abort this loop
after e.g. 10 seconds.

Since the coge runing rs.tx hangs on
··· waitpeq(inverted & |< sin, |< sin, 0)·············· ' wait for start bit

I was thinking to fire· cog#2 at the start and after some time out
execute on cog#2
·· dira[noparse][[/noparse]26]:=0
···outa[noparse][[/noparse]26]:=0 ' produce a·false input message

But it seems to not work, cog#1 still hangs.
Is there any other trick I could·try perhaps?
Thanks
Jan·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-03 05:38
    Try "dira[noparse][[/noparse]26] := 1". Your code sets the direction to input in cog#2.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-01-03 06:12
    Also be careful that, when driving your input pin, you don't force a bus conflict with the serial receiver driving the same pin. Some series resistance with the receiver is likely called for here.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-03 08:17
    As an alternate approach, a second pin (if available), could be used in conjuction with a cog counter to force the timeout.

    ' To wait for a low level on both pins 25 (as timeout helper) and 26 (as serial in):
    frqb := 1
    dira[noparse][[/noparse]25] := 1
    cntb := nco_mode | 25 ' NCO mode, pin pa25

    phsb := -10 * clkfreq ' starts with p25 high, low after 10 seconds
    waitpne( (|< 26) | (|< 25), (|< 26) | (|< 25), 0)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • janbjanb Posts: 74
    edited 2007-01-07 02:24
    Hi Guys,
    thanks for all advices.
    I took from them :
    - it is possible
    - protect RX·pin w/ resistor , done

    Attached files show a soultion:
    - second Simple_Serial OBJ initialized with reveresed Rx<-->TX pins
    - activated·on a··2nd cog after time out of 7 seconds
    ·· sends some emergency text to the RXpin·for the 1st cog,
    ·· next·restores·this pin·back as input

    Works good , the tcl script can be fired to test the RX pin reads from external soruce all the time.

    The advatage of this aproach (in my opinion) is I have avoided ·low level commands. (except one dira[noparse][[/noparse]pinRx]~·· )
    Thanks
    Jan
Sign In or Register to comment.