Shop OBEX P1 Docs P2 Docs Learn Events
asyncronous serial comms — Parallax Forums

asyncronous serial comms

cplattcplatt Posts: 55
edited 2009-04-05 18:36 in BASIC Stamp
I have been communicating with my BS2p from my PC via the ComPort.
Even after reading the manual about the serin command I don't fully get it.
Could someone tell me if I am on the right track? I am not sure about how
to loop and if the pause is necessary. Thank you so much!

'{$STAMP BS2p}
' {$PBASIC 2.5}

sData   VAR     Byte

Main:
  SERIN 1, 16780, [noparse][[/noparse]DEC sData]
if sData=20 then High 5
if sData=21 then Low 5
pause 50
goto Main

END

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-05 05:41
    Right track to do what? Explain what you want to accomplish.
  • Craig EidCraig Eid Posts: 106
    edited 2009-04-05 07:31
    Cplatt,

    What type of problems are you encountering? How did you calculate the baudmode value of 16780 for a BS2p? You will find that the members of the forum are very supportive but you need to·provide·more information·to get a specific answer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ························ Craig Eid


    ··········· Triad Research and Development
    Electical Engineering Design and Consulting Services

    ··················· www.TriadRD.com

    Post Edited (Craig Eid) : 4/5/2009 7:39:15 AM GMT
  • cplattcplatt Posts: 55
    edited 2009-04-05 13:48
    Thank you guys, the correct baud rate should be 18447 from table 5.98 in the stamp manual for 8 bit no parity inverted 1200 baud. (sorry was sleepy last night) I am trying to listen for Sdata and if it's 20 turn on a led, if 21 turn off. Everything works well, the stamp just occasionally misses a on or off transmission. I believe the correct way to set up the program is to delete the pause command and just have it "sit" and listen for incoming data correct?
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-04-05 16:14
    Code snippet is nice, but you could avoid forum requests for additional information if you code included some comments.
    ....
    if·sData=20·then·High·5····· ' turn LED ON
    if·sData=21·then·Low·5····· ' turn LED OFF
    ....

    If your only task is to (test) manipulate LED's than "sitting in the loop" without the PAUSE is just fine.
    But the real reason to eliminate the PAUSE is·you are dealing with slow data stream and 50 ms pause will make a difference if you data rate is fast.
    Hence you can miss some changes as you found out..



    ·
  • cplattcplatt Posts: 55
    edited 2009-04-05 17:35
    I guess my real question is once the stamp hits Serin does it do: A. Just stop and listen or B. Stop, listen find nothing, loop and then stop listen find nothing, repeat loop until it finally finds something (wouldn't this constant looping be inefficient and hard on the stamp?)

    Thank you everyone for your patients with my vague postings- as a real novice I will try to do better; explain more, remark all code and describe my problems better.
  • FranklinFranklin Posts: 4,747
    edited 2009-04-05 17:52
    What the stamp does when it gets to the serin depends on wether yo included a timeout in your command. Check out the syntax help in the editor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-05 17:56
    When the Stamp reaches a SERIN (without an explicit timeout ... see the manual), it waits for data. The amount of data and its format depend on what you've written in the SERIN statement. Looping is not "hard on the Stamp". This is what a computer does.
  • cplattcplatt Posts: 55
    edited 2009-04-05 18:36
    Thank you guys (Hello Mr. Green- you have help me many times!!!!! )
Sign In or Register to comment.