Shop OBEX P1 Docs P2 Docs Learn Events
Trying to understand serial tx commands — Parallax Forums

Trying to understand serial tx commands

charleyshfcharleyshf Posts: 165
edited 2009-10-10 02:19 in Propeller 1
Hello,

I am fairly new to the prop and I have been totally lost with something I have been working on lately.

I have a motor controller (Polu qik2s9v1) which is·asynchronous logic-level, non-inverted serial input at 38400, 8 data bits, one stop bit.

I've been trying to just send it a·command in decimal 141, 127 I am also using the·FullDuplexSerial.spin:

My code:

CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000

OBJ
··· MOTORS : "FullDuplexSerial.spin"

PUB HEREWE_GO

···· ·MOTORS.START(3, 2, 2, 38400)
····· waitcnt(clkfreq/1_000· + cnt)
····· MOTORS.tx(string("141, 127"))

repeat


I have tried all sort of different things with this and I must be entirely lost on this, can some please help me with this?

Thank You
·

Comments

  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-10-10 01:31
    .. I don't know the controller but to send decimal value
    should it not be

    Motors.dec(127)

    Just a thought !

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    'Those who can, do.Those who can’t, teach.'
    'Convince a man against his will, he's of the same opinion still.'

    ·
  • charleyshfcharleyshf Posts: 165
    edited 2009-10-10 01:37
    QuattroRS4 said...
    .. I don't know the controller but to send decimal value
    should it not be

    Motors.dec(127)

    Just a thought !

    Hi, thank you for responding,

    That's one of the commands I have tried with this setup, I know the controller has tested good, but this motor controller also has an error led that lights up if·there is issue with the data sent, and it lights up no matter what I try to send to it.

    This is the pdf on the motor controller
    http://www.pololu.com/docs/pdf/0J25/qik_2s9v1.pdf

    from the pdf it stats of youi send dec 141,127 to the controller it makes one of the 2 motors go full speed forward....

    Thanks again
    ··
  • SamMishalSamMishal Posts: 468
    edited 2009-10-10 01:54
    Charley,
    I can see a few·problems with your code. Try this new code and see if it works for you.
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
     
     Rx_Pin = 3  'Check this is correct receive pin into the propeller from the polou
     Tx_Pin = 2  'check this iscorrect  transmit pin from the propeller to the Pololu
     
    OBJ
        MOTORS : "FullDuplexSerial.spin" 
     
    PUB HEREWE_GO
     
       MOTORS.START(RX_Pin,TX_Pin, 0, 38400)  'notice the mode is 0 not 2 as you had it...but check this I might be wrong
       waitcnt(clkfreq/2  + cnt)              'wait 1/2 sec not 1ms which I think is two short to give the FDS time to start up
       MOTORS.tx(141)                         'notice you must transmit the bytes not the text and one at a time
       MOTORS.tx(127)
       repeat
    
    



    Sam
    ·
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-10-10 01:54
    PDF says -

    (the circular pin right next to the “A” silkscreen label). This fixes the qik’s baud rate at 38,400 bps, and the qik skips the automatic baud detection phase that normally occurs on start-up.
    Has this been done ? If not it says dec(170) has to be sent to take it out of autobaud mode.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    'Those who can, do.Those who can’t, teach.'
    'Convince a man against his will, he's of the same opinion still.'

    ·
  • charleyshfcharleyshf Posts: 165
    edited 2009-10-10 02:01
    QuattroRS4 said...
    PDF says -

    (the circular pin right next to the “A” silkscreen label). This fixes the qik’s baud rate at 38,400 bps, and the qik skips the automatic baud detection phase that normally occurs on start-up.
    Has this been done ? If not it says dec(170) has to be sent to take it out of autobaud mode.

    Yes, currently I have the jumper on for 38400 baud..

  • SamMishalSamMishal Posts: 468
    edited 2009-10-10 02:04
    Charley

    Even if you want to transmit text not bytes then

    ····· MOTORS.tx(string("141, 127"))

    does not work......it should be

    ···· MOTORS.Str(string("141, 127"))



    But the Pololu expects the command and value to be ONE BYTE binary ie 141 is sent as a byte
    of the value 141 = $8D· not as the charachters 1 then 4 then 1 which would be THREE bytes of the
    values $31 $34 $31



    Sam
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-10-10 02:06
    @SamMishal
    As Charley specified decimal should it not be -

    MOTORS.dec(141)
    MOTORS.dec(127)

    in your example ? I am not familiar with the controller - just reading the data sheet now!

    Rgds,
    John

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    'Those who can, do.Those who can’t, teach.'
    'Convince a man against his will, he's of the same opinion still.'

    ·
  • SamMishalSamMishal Posts: 468
    edited 2009-10-10 02:13
    QuattroRS4 said...
    @SamMishal
    As Charley specified decimal should it not be -

    MOTORS.dec(141)
    MOTORS.dec(127)

    in your example ? I am not familiar with the controller - just reading the data sheet now!

    Rgds,
    John

    Hi John,

    NO....the Motors.Dec(141) will take the byte 141 and convert it to a text of character 1 then 4 then 1
    which are the bytes $31 then $34 then $31 just as if you have done Motors.Str(string("141"))

    The Motors.Tx(141) transmists a BYTE whose value is 141 JUST ONE BYTE with value $8D.

    This is what is needed since this is what the Pololu expects 2 bytes the first being the command
    and the second being the value of the command
    ie $8D then $7F.......just two bytes.

    The method Motors.Dec or Motors.Str· will NOT work since the first will convert the byte to its TEXT
    equivalent which happens to be 3 characters (bytes) and the the second does the same but you did the
    conversion yourself to text.

    Sam
    ·
  • charleyshfcharleyshf Posts: 165
    edited 2009-10-10 02:13
    Thank you so much!!! That was it, I would have to guess that between needing more of a delay and the fact that I had the wrong mode set ?

    Thank you again!!
    SamMishal said...
    Charley,

    I can see a few·problems with your code. Try this new code and see if it works for you.
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
     
     Rx_Pin = 3  'Check this is correct receive pin into the propeller from the polou
     Tx_Pin = 2  'check this iscorrect  transmit pin from the propeller to the Pololu
     
    OBJ
        MOTORS : "FullDuplexSerial.spin" 
     
    PUB HEREWE_GO
     
       MOTORS.START(RX_Pin,TX_Pin, 0, 38400)  'notice the mode is 0 not 2 as you had it...but check this I might be wrong
       waitcnt(clkfreq/2  + cnt)              'wait 1/2 sec not 1ms which I think is two short to give the FDS time to start up
       MOTORS.tx(141)                         'notice you must transmit the bytes not the text and one at a time
       MOTORS.tx(127)
       repeat
    
    



    Sam
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-10-10 02:14
    You also had a comma in your string

    to send this
    motor.tx(",")

    You may also need to send a carriage return (CR) and possibly a Line Feed (LF) at the end of the string. To do this
    motor.tx(13) 'cr
    motor.tx(10) 'lf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade, RetroBlade,·TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-10-10 02:19
    SamMishal said...
    But the Pololu expects the command and value to be ONE BYTE binary ie 141 is sent as a byte
    of the value 141 = $8D not as the charachters 1 then 4 then 1 which would be THREE bytes of the
    values $31 $34 $31

    Duly noted ..

    yeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    'Those who can, do.Those who can’t, teach.'
    'Convince a man against his will, he's of the same opinion still.'

    ·
Sign In or Register to comment.