Trying to understand serial tx commands
charleyshf
Posts: 165
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
·
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
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.'
·
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
··
I can see a few·problems with your code. Try this new code and see if it works for you.
Sam
·
(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.'
·
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
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.'
·
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
·
Thank you again!!
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
Duly noted ..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'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.'
·