Shop OBEX P1 Docs P2 Docs Learn Events
beginners question on DEBUGIN — Parallax Forums

beginners question on DEBUGIN

lfreezelfreeze Posts: 174
edited 2007-09-27 00:00 in Propeller 1
I am a beginner, I have gotten through the basis instructions in the manual, and thought I would try and
expand my knowledge..

I am trying to create a simple object which will mimic "debugin" via a hyperterminal session. I am using a propstick
(serial connector) to my desktop. For purposes of simplicity, I want the object to pause and wait for an input via
keyboard. The input will be a variable, either 1 or 2. If the input is 1, the object goes to the lightledtone· object.
If the input is 2, the object goes to the lightledtwo object.· If any other number, or nothing is input, the object stays
in a loop and·keeps looking for a 1 or 2.

I have tried countless variations of Martin Hebels BS2 functions (debugin) and also many variations of the full duplex
serial object.· I have searched the posting for any examples and can't find any. Below is some of the code (not working)
which I am using. Can anyone offer an example or some guidance on how to accomplish this.
Thank you in advance

Larry

CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000····················
VAR
··· byte value
·················································
OBJ
'··· BS2· : "BS2_Functions"·
···· SER· : "FullDuplexSerial"
·········
PUB start

REPEAT
·· ser.start(31, 30, 0, 9600)
· if value ==1
··· lightledone
· if value ==2
···· lightledtwo···

······
PUB lightledone
··· dira[noparse][[/noparse]9] ~~············ 'makes pins 9 an· output
··· outa[noparse][[/noparse]9] :=%1·········· 'set the value of pin· 9· as high +5
··· waitcnt (5_000_000 + cnt)
··· outa[noparse][[/noparse]9] :=%0·········· 'sets the value of pin 9· as low· 0
···· waitcnt (10_000_000 + cnt)·

PUB lightledtwo
··· dira[noparse][[/noparse]8] ~~············· 'makes pin an 8 output
··· outa[noparse][[/noparse]8] :=%1··········· 'set the value of pin 8· as high +5
··· waitcnt (5_000_000 + cnt)
··· outa[noparse][[/noparse]8] :=%0··········· 'sets the value of pin 8· as low· 0
···· waitcnt (10_000_000 + cnt)·

Comments

  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-09-24 14:22
    Last week I posted a spin program called color-code.spin

    One of the features is it uses hyperterminal to control the program. The program looks for I,J,K,M and does something if one of those is hit. Your program is basically the same idea.

    How about something like this description

    
    Serial.start(31, 30, 0, 9600) ' HyperTerminal  9600, None, 1, no flow control 
    
    repeat
      keyHIT := Serial.rxcheck ' reads byte from serial port
      case keyHIT ' check the byte
        49: ' ascii of 1 was pressed
           do_the_first_one
      
        50: ' ascii of 2 was pressed
           do_the_second_one
    
    
    



    The above is not 'real' code, it is just thinking out loud with something that looks like code (but is really close).
    Check out the color-code.spin to see how I did it with both RS232 and IR-TV-remote
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-24 14:27
    Hi ifreeze

    Look in this thread


    http://forums.parallax.com/showthread.php?p=651296

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • lfreezelfreeze Posts: 174
    edited 2007-09-24 15:27
    Thank you Mark and Saphiea

    I will try both solutions, Saphiea is there an English version of the web site? ·I used the·link you suggested

    and then downloaded the files, I·need some directions in how to use them. The help button sends me to a German language site. Meinen Deutsch is nicht gut

    Larry
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-24 16:40
    Hi Ifreeze

    It is both on some sides
    But Spin codes is in English.
    Study it (I recommend Virtual_S_L.spin)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • lfreezelfreeze Posts: 174
    edited 2007-09-25 21:22
    Mark,

    Thanks again for·your example. I·used it to build on, ·then I extracted the case statements from color-code spin. The

    object I built loads, but I get no result when· keyboard 1 or 2 is pressed.· I suspected My hyperterminal setup is incorrect

    so I ran a known good object and I can receive via hyperterminal okay.···Any suggestions would be appreciated.

    Here is the code I have created so far...

    CON
    ··· _clkmode = xtal1 + pll16x
    ··· _xinfreq = 5_000_000····················
    VAR
    ··· byte value
    OBJ
    ··· SER· : "FullDuplexSerial"
    PUB start
    ser.start(31, 30, 0, 9600)
    REPEAT
    · value:=ser.rxcheck·
    · CASE value
    ···· 49: 'ascii· "1" was pressed
    ······· light_led_one
    ···· 50:· 'ascii· "2" was pressed
    ······· light_led_two
    ······
    PUB light_led_one
    ··· dira[noparse][[/noparse]9] ~~············ 'makes pins 9 an· output
    ··· outa[noparse][[/noparse]9] :=%1·········· 'set the value of pin· 9· as high +5
    ··· waitcnt (5_000_000 + cnt)
    ··· outa[noparse][[/noparse]9] :=%0·········· 'sets the value of pin 9· as low· 0
    ···· waitcnt (10_000_000 + cnt)·
    PUB light_led_two
    ··· dira[noparse][[/noparse]8] ~~············· 'makes pin an 8 output
    ··· outa[noparse][[/noparse]8] :=%1··········· 'set the value of pin 8· as high +5
    ··· waitcnt (5_000_000 + cnt)
    ··· outa[noparse][[/noparse]8] :=%0··········· 'sets the value of pin 8· as low· 0
    ···· waitcnt (10_000_000 + cnt)
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 21:28
    You should reflect the received values to the PC to find out what is going on.
    There will most likely be a parity bit, but EITHER 49 OR 50 should work smile.gif

    Take into account that a flash of 5/80 = 0.06 s is hardly noticeable

    Post Edited (deSilva) : 9/25/2007 9:33:03 PM GMT
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-25 21:47
    Hi Ifreeze

    Thus is HyperTerminal setup.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
    1180 x 611 - 73K
  • lfreezelfreeze Posts: 174
    edited 2007-09-25 22:02
    Thank you everyone for the help. My small· hyperterminal program is now working. My error was a stupid

    beginners mistake. I had set up hyperterminal incorrectly. Saphiehas message prompted me to create a new

    hyperterminal connection using the settings he provided And suddenly magic !!! it worked.··

    Larry
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 22:07
    Well: Parity? Flow Control? Baud rate? smile.gif
  • lfreezelfreeze Posts: 174
    edited 2007-09-25 23:52
    I set up hyperterminal this way:

    ··· bits per second··· = 9600

    ··· data bits············· = 8

    ··· parity················· =· none

    ··· stop bits············ =· 1

    ·· flow control········ =· none

    I checked the program (attached) several times and noticed one problem. If you key in "1" rapidly the program will stop reacting to

    it after about three times. If you rapidly alternate between keying "1" then ·"2", it works fine. I am not sure what is causing this. I will spend some time with it and see if I can solve it.

    Larry
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-26 00:01
    For convenience, you can use quoted characters as CASE labels. For example, you can put
    case value
       "1": led_light_one
       "2": led_light_two
    

    I suspect you're dropping characters because of the 3/16 second delay for each action.· If you type too many characters ahead, the FullDuplexSerial buffer will fill up before your program can get them and the extras will be dropped.· The buffer is normally 16 bytes.


    Post Edited (Mike Green) : 9/26/2007 12:06:11 AM GMT
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-26 00:06
    Hi Ifreeze

    You cant use this to check values.

    value:=ser.rxcheck

    Study "FullDuplex" it is only check for incomming char flag

    else check in you routin for "case -1" - not char in

    Ps. Sorry my bad English

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha

    Post Edited (Sapieha) : 9/26/2007 12:17:08 AM GMT
  • lfreezelfreeze Posts: 174
    edited 2007-09-26 00:22
    Mike,

    Thanks for the tip on the quote marks. I don't think it's the 3/16 second delay. If I key in a 1, wait approx one second then do it again, it will fail after the third· or fourth try. If I key in· 1, and then rapidly (as fast as I can) ·key in any other key the program reacts perfectly. I am really puzzled (not unusual) about this problem. I will pursue if further, but I· am not sure

    which direction to take. (hyperterminal, fullduplexserial or my program)

    Thanks

    Larry
  • lfreezelfreeze Posts: 174
    edited 2007-09-26 00:41
    Saphiea

    Thank you for your response. I am confused about not being able to use value:=ser.rxcheck. It seems to be working

    as it is reading whether a 1 or 2 is keyed in. i suspect a buffer problem in fullduplexserial.· I will work on this in

    the morning as see if I can fix it.··.

    guten nacht

    Larry
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-26 00:57
    Hi IFreeze.

    Yes it reading but.
    You mast test for incominh char first and if one, read it and test.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • lfreezelfreeze Posts: 174
    edited 2007-09-26 16:17
    I think the problem with not being able to repeat keys into the propeller··is caused by the type of hyperterminal

    emulation. My program works fine if hyperterminal emulation is changed from auto detect to minitel. Of course nothing

    is easy, if you disconnect the hyperterminal connection while using minitel emulation, you can not restart it.

    You must create a new connection. Does anyone have any ideas about how to solve this.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 23:25
    @Sapieha:
    "rxcheck" is the approved way to read characters.
    "rx " does nothing but
    repeat while (rxbyte := rxcheck) < 0
    


    it is not necessary to check for -1 when you check for other specific values
  • SapiehaSapieha Posts: 2,964
    edited 2007-09-27 00:00
    Hi deSilva.

    Sorry my miss. I still thing standard serial port.
    Rxcheck = Receive buffer full flag

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
Sign In or Register to comment.