Shop OBEX P1 Docs P2 Docs Learn Events
Help with Receiving serial data — Parallax Forums

Help with Receiving serial data

SiriSiri Posts: 220
edited 2008-07-28 18:11 in Propeller 1
I am working with a stepper motor/driver "Little Step-U" from parallax shop.
I am able to send commands to the stepper and they work well - using spin object - "Full Duplex Serial" and other serial objects.
I am unable to receive any serial data from the Stepper driver.
When the command "{V}" is sent - the state of the two "Stops" are sent back in this ·format.
··························· " [noparse][[/noparse]a,b]" - "a" ·and "b" are binary "0" or"1" - open or closed.

I have tried using BS2 Functions - which is the only way I seem to have found that has a serial command
to "WAIT for CHAR" - "[noparse][[/noparse]" - · function but I cannot get it to work.
Is there a way I can do this using the serial spin objects without cog lock-up.

Thank you.

Siri
P.S - Attached is the Stepper motor specs.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-22 22:33
    FullDuplexSerial has an "rxcheck" method that returns -1 (or 0, I don't remember ... look at the comments) when there are no characters in the buffer. You can just do an IF ser.rxcheck == "[noparse][[/noparse]" and process the rest of the response yourself or do something else otherwise.
  • SiriSiri Posts: 220
    edited 2008-07-23 01:20
    Mike,
    I tried using Rxcheck as you suggested but was not sucessful.

    When I run this code without the repeat in the "StepInit" method - the DebugGo method works and I receive "0 0 ".Even if I turn the motor to
    the "Stop markers" - I still receive only "0" 's·· and no "1" 's.
    If I run the the code with the "repeat" - the motor goes back and forth trggering the "stop markers" - but Debug part stops functioning and I do not receive any data - at least I can't see on the Debug screen.
    I am execcuting the Debug code on a sepatate COG.
    Thanks for the help
    Siri

    (unable to attach doc. - server failure) so here it is :
    Code : CON
    ········· VAR
    ··············· long DebugStack[noparse][[/noparse]20]
    ········· OBj
    ··············· stepper:"Extendd Serial"
    ··············· Debug: "FullDuplexSerial"
    ········· PUB Main
    ················ Stepper.start(5,6,1,2400)··
    stepper baud rate etc.
    ················ Debug.start(31,30,0,57600)
    ················ StepInit
    ················ cognew(DebugG0,@DebugStack)

    ········ PUB StepInit·························· 'stepper motor to go back and forth to stops A & B - "on and off"

    ·············· Repeat
    ······················ stepper.str(string("{K}"))·········· 'go clockwise to stop "A"
    ······················ waitcnt(clkfreq + cnt)
    ······················ stepper.str(string("{J}"))··········· 'go counter clockwise· to stop "B"
    ······················ waitcnt(clkfreq + cnt)

    ······ PUB DebugGo | a,b
    ·············
    ·········· Repeat
    ·············· waitcnt(clkfreq + cnt)
    ·············· stepper.str(string("{V}"))·············· 'request the positons of stops "A &B" - on/off --> 1 or 0
    ·············· If stepper.rxcheck == "[noparse][[/noparse]"··············· 'receiving format " [noparse][[/noparse]a,b]"
    ·················· a:= stepper.RxDec····················· 'receive "a" -->1 or 0
    ·················· b:= stepper.RxDec····················· 'receive " b" --> 1 or 0
    ·················· Debug.str(string(13)
    ···················Debug.Bin(a,1)
    ·················· Debug.str(string(13)
    ·················· Debug.Bin(b,1)




    Post Edited (Siri) : 7/23/2008 1:30:26 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-23 01:27
    You can't use the same instance of FullDuplexSerial (or Extendd Serial) from two cogs at a time without using locks to only allow one cog to access the same instance at a time.· I'm pretty sure the 20 level stack is also too small, particularly since Extendd Serial probably calls FullDuplexSerial.

    Post Edited (Mike Green) : 7/23/2008 1:32:47 AM GMT
  • SiriSiri Posts: 220
    edited 2008-07-23 01:41
    Mike,

    Thanks for the help.

    I thought since they are two different objects that I could use them at the same time.

    How do I use locks - I have never used them - giude me along.



    Thanks



    siri
  • SiriSiri Posts: 220
    edited 2008-07-25 17:58
    Mike,

    I tried using " If ser.Rxcheck == "]" and when I try to capture the data after the "[noparse][[/noparse]" - I am unable to do so.

    using· " a :=·ser.Rx " as shown in my prior post.

    Then I tried using· : If ser.Rxcheck == "[noparse][[/noparse]"

    ······························ a:= ser.Rx(time)· --- using tme as 100 msec.

    now I receive 4 bits of garbage but no "0" or "1".

    Then I thought the stepper driver may be not working well.- but after using a BS2px set up·with DEBUG i- recived

    "0" and "1". - so the stepper driver is working well.

    I also tried changing the baud rate,mode inverted/non-inverted with all possible combinations - but yet I am

    unable to receive the right out-put from the stepper drive.

    I am using only one "serial object" - no duplicates and· PINS (5,6) to communicate with the stepper driver and PINS 30,31 for the DEBUG.

    I appreciate any help I can get.

    Siri
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-25 18:10
    Here's one example that tests for "[noparse][[/noparse]" and discards anything else.
    If there's a "[noparse][[/noparse]", then it accepts a single digit "0" or "1", then
    a comma, then a single digit "0" or "1", then a "]".
    if ser.rxcheck == "[noparse][[/noparse]"
       a := ser.rx - "0"
       if ser.rx <> ","
          abort
       b := ser.rx - "0"
       if ser.rx <> "]"
          abort
    
  • SiriSiri Posts: 220
    edited 2008-07-25 19:37
    Thanks Mike I will try that as soon as I get back from work.

    Siri
  • SiriSiri Posts: 220
    edited 2008-07-25 21:52
    Mike,
    I tried the code you suggested but I am still unable to receive any data back from the stepper driver.
    I attached the code I used and BS2 code that works.
    Hopefully this will help you figure out - if I am doing something wrong.

    Thank you again.

    P.S - How do one post code snippets like you did in the previous post.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-25 22:27
    You need to look at what I wrote and figure out what it's doing, then decide whether it will do what you want or not and modify it as needed, not just take it uncritically and expect it to work as provided. You'll notice that I wrote an IF statement and mentioned that it would test for "[noparse][[/noparse]" and discard anything else. It will indeed do that ... once. If there is no "[noparse][[/noparse]" in the serial input buffer, it will throw away the first character there (if any) and that's all. You need to figure out what to surround this fragment with. You could change the "rxcheck" in the IF statement to an "rx" which will cause it to wait for a character to be received, then make sure it's a "[noparse][[/noparse]" (and ignore it if not). This will "lock up" the cog though until a character is received and you said you didn't want that.

    Start a code block with "[noparse][[/noparse] code ]" without the spaces and end the code block with "[noparse][[/noparse] /code ]" also without the spaces. Not everything is left unaltered, but spacing is preserved.
  • SiriSiri Posts: 220
    edited 2008-07-28 18:11
    Mike,/et al

    Thanks for all the help.

    I finally figured what the source of the problem.

    When all spin code did not work - I suspected there must be a hardware problem.I connected the Stepper motor driver to BS2 setup and it worked flawlessly.Then I hooked up the scope to the stepper driver serial out-put and I was receivng a good signal - this confirmed that all is working well.

    Then I placed the stepper motor driver in the Prop setup.I was able to run the motor in both directions using the commands with Full_Duplex_Serial.But for some reason there is no serial out-put was detected with the scope.I have double-trpple checked my wiring and all the connections,I am not using that particular PIN for any other task.

    The question now is why I can communicate only in one direction with the stepper motor driver.

    I tried changing the I/O pin direction form input/ouput - high and low still I am unable to record any out-put from the Stepper motor driver.

    The stepper motor Driver is driven by 5V DC and I have connected the 3 pins to the prop via 2K ohm resisitors

    and it reads 3.1V for all the 3 pins at the prop.- but still no out-put from the serial out from the Stepper driver.

    I can do directly back to the BS2 setup and the same serial out pin from the steppr driver and the GND will record a normal serial signal on the scope.

    Why is the Prop and the Stepper driver "NOT work together.

    Siri

    Post Edited (Siri) : 7/28/2008 7:57:39 PM GMT
Sign In or Register to comment.