Trying to send serial to speed controller
stuartX
Posts: 88
I'm new to propeller so I'm not too sure about my code.
I have a speed controller that is RS-232. I'm trying to send ASCII code "!G,2,71" to the speed controller to test.
I have a simple program loop that I thought would work. But I'm not sure of is how to do so with my code.
I'm output at pin 0. with a speed of 115200.
I tried to use pst.Start (TxPin, 115200) but it return an error. I tried to look up proper syntax but, could not find what I was looking for.
Any help would be appreciated.
My test code is below.
I have a speed controller that is RS-232. I'm trying to send ASCII code "!G,2,71" to the speed controller to test.
I have a simple program loop that I thought would work. But I'm not sure of is how to do so with my code.
I'm output at pin 0. with a speed of 115200.
I tried to use pst.Start (TxPin, 115200) but it return an error. I tried to look up proper syntax but, could not find what I was looking for.
Any help would be appreciated.
My test code is below.
OBJ pst : "FullDuplexSerial.spin" CON ' _clkmode = xta11 + p1116x ' _xinfreq = 5_000_000 TxPin = 0 PUB Main pst.Start(TxPin, TxPin, %1000, 115_200) waitcnt(clkfreq + cnt) repeat pst.Str(String("!G,2,71")) waitcnt(clkfreq * 3 + cnt) pst.Str(String("!G,1,1000")) waitcnt(clkfreq * 3 + cnt) pst.Str(String("!G 1 1000"))
Comments
I wasn't quite sure what the %1000 was for but, I wanted to make sure that the ASCII was getting output @ 115200.
Thanks for your input, if you have anything else to add...please feel free.
Thanks again.
http://www.roboteq.com/index.php/docman/motor-controllers-documents-and-files/documentation/user-manual/7-nextgen-controllers-user-manual/file
It should be page 111 "Serial (RS232/USB Operation)
Thank you (in advance)
I tried that: pst.Str(String("!G,2,71", 13))
Then I tried
pst.Str(String("!G,2,71,13))
Then I tried:
pst.Str(String("!G,2,71, 0x0D", ))
Then I tried
pst.Str(String("!G,2,71", 0x0D)) 'I got a syntax error.
$0D is what you'd use. It's identical to 13. The exact same bits are sent down the serial line when using either of the below code.
I tried the :
pst.Str(String("!G,2,71", $0D))
and
pst.Str(String("!G,2,71,$0D"))
Is there an example of the message you're trying to send in the documentation?
Where is the "!G" command listed?
Edit: Give "pst.Str(string("!G", 2, 71, 13))" a try.
I got the following information from the Roboteq folks:
P. 168 and 169
Syntax: !G [nn] mm
Where: nn = motor channel
mm = command value
If you are trying to do this via a closed loop speed, then you need to set up your max speed value of your motor in the speed and acceleration parameter.
Refer to the user manual for additional information.
and
To test, send the sring "?FID" terminated by a carriage return character. That is ASCII 0x0d.
The nextgen controller works on 115200 kbps. Change the settings to 8N1 115200.
The syntax should be !G 1 10000 0x0D.
So is it delimited by a space character?
If so you'd send.
Or if the motor ID were stored in the variable "motor" and the speed stored in the variable "speed", you could use:
pst.Char(" ")
I made motor and speed a constant.
FDS uses "tx" instead of "char". Replace all the "Char" calls with "tx".
You have to have the clock settings commented out in order for the serial connection to work as mentioned earlier in the thread.
Make sure and do what kuroneko suggested. It won't work otherwise!
'thanks/
I promise they use the wrong syntax.
' _clkmode = xta11 + p1116x
' _xinfreq = 5_000_000
Then, shouldn't it be "pst.Str(string("!G 2 71, 13))" for the motor command?
! indicates it is a command,
G is the set motor command,
2 is the motor channel,
71 is the value to set it to, and a space is the separator.
The characters between the quotes will be compiled as the ascii characters !G 2 71, and the decimal number 13 will be the ascii character 0D aka CR since it is outside the quotes.
and I commented out the earlier strings:
But nothing happened.
Try this, then check my previous post.
I tried that again:
I received an error with the 0x0d 'it said must use characters from 1 to 255
I placed it in the " ......still nothing happen when I ran the program.
You must have the clock mode and crystal settings set in order to use the high speed serial.
As it's been mentioned multiple times, you must have:
or something similar in your CON section.
Do you have a 5MHz crystal on your Prop board? If not, what crystal are you using. You'll need a crystal to use a baud of 115,200 bps.
Both of these should do the same thing. The 13 outside the quotes is treated as a decimal number and converted to a carriage return character. The 0x0d is treated as a hexadecimal number and converted to a carriage return.
pst.Str(String("!G 1 1000",13))
pst.Str(String("!G 1 1000" 0x0d))
the clock mode code is still there. I have the propeller board, the crystal is a T5.00