Serial data Hex
Stuarttttt
Posts: 45
in BASIC Stamp
Hi, I would like to send the following Hex data 01 04 01 05 00 01 5F 90 FB
I have tried SEROUT 16, 16468, [HEX "01 04 01 05 00 01 5F 90 FB",CR] but it is displayed on the debug screen as 301 04 01 05 00 01 5F 90 FB
Where has the extra 3 come from at the beginning?
And basically what am I doing wrong here?
Also whats the best way of receiving the reply which will be in the same format as the data sent?
Any help / pointers are welcome.
Thanks
Stuart
I have tried SEROUT 16, 16468, [HEX "01 04 01 05 00 01 5F 90 FB",CR] but it is displayed on the debug screen as 301 04 01 05 00 01 5F 90 FB
Where has the extra 3 come from at the beginning?
And basically what am I doing wrong here?
Also whats the best way of receiving the reply which will be in the same format as the data sent?
Any help / pointers are welcome.
Thanks
Stuart
Comments
The double quotes in your SEROUT cause the text within the quotes to be sent literally as given so "01" gets sent as an ASCII 0 character followed by an ASCII 1 character, not a byte with the value 1.
The HEX converts the following byte values to hex (two ASCII characters per byte ... human readable).
I'm not sure where the extra 3 came from. Maybe the HEX followed by a string confused the compiler.
Are you sure this is what you want? The bytes you're sending will go out to the debug screen where they may be interpreted as control sequences. Are you attaching some non-display device to the debug serial port?
You should read the "BASIC Stamp Architecture – Number Representations" chapter in the manual to understand the difference between decimal, binary, hex, and characters.
Posting your code and an explanation of what you are trying to do will get you more help.
How many bytes of data should this be? 9 or 27(including the carriage return)?
If you want to send raw data, you won't be able to view it well on the normal debug terminal. The ASCII character $5F (the underscore character) is the only printable character in the list.
What sort of device is sending the data
I second kwinn's suggestion here:
I also suggest reading about ASCII characters on Wikipedia. (Mike Green's post also mentions ASCII.)
Edit: If the protocol you want to use, doesn't use ASCII characters, then it is likely either always the same length or it includes a field to indicate the length of the message. Non-ASCII protocols also generally include some sort of check sum.
Edit again: I just looked back as some of your earlier posts. Sorry for explaining basic stuff you likely already know.
I have a 6 axis stepper controller, have a look here at a robotic arm I designed and programmed using the boards software
However due to the stepper boards limited input functions I would like to interface a BS2 via RS-485 and therefore be able
to use accelerometers, GP2D02 detectors, MakerPlot and other devices in my future robotic creations.
This stepper board expects control data such as 01 04 01 05 00 01 5F 90 FB (each byte is an instruction) and replies with similar.
When I set up the 485 data line properly and get it working and time allows I hope to be able to control the board from the BS2 using
Hex but probably more meaningful ASCII mnemonics.
That is what I am trying to achieve. I haven't used the BS2 for a while (a bit rusty and have forgotten more than I knew.
Hence just asking for some advice.
What's the make and model of the controller?
So the above instruction is sent as nine bytes?
If so then you want to send the raw data and not ASCII characters.
I don't recall how to do this with a Basic Stamp but I'm sure someone around here could help you with the appropriate commands.
What you can do is:
looks like you are deep into that meccano thing.
wonderful. Arm and car are nicely made.
Enjoy!
Mike
Duane, the stepper board is made by Trinamic and is model TMCM-6110
Stuart
In case anyone else is interested, here's the download page for this particular driver.
Page 11 of this pdf file indicate the binary protocol uses a 9 byte packet. The last byte of the packet is a check sum.
You might run into some trouble using a Basic Stamp to control the device since (IIRC) the Basic Stamp doesn't have an UART buffer. I haven't used Basic Stamps enough to now if a BS is a good match for your project.
Apparently the driver can be placed in ASCII mode which would allow you to control the device from a terminal program.
The problem is, when a SEROUT is followed by SERIN, it may not turn around quickly enough to capture the first character.
The obvious solution to all such BS-2 problems is, of course, FLiP!
I now know the stepper module RS-485 interface actually works as wasn't sure if it was or not.
I can send and receive Hex and ASCII commands to the module from HTerm (Hyperterminal type interface). Hopefully I will be able to get more meaningful ASCII commands sent from the BS2 working soon. Thanks again for your input. (I'll probably be back
' HEX control data to TMCM-6110 Stepper module (via TTL to RS-485)
serstr VAR Byte(9)
serstr(0) = $01
serstr(1) = $04
serstr(2) = $01
serstr(3) = $05
serstr(4) = $00
serstr(5) = $01
serstr(6) = $82
serstr(7) = $B8
serstr(8) = $46 'serSTR moves motor +99000 steps relatively
MAIN:
HIGH 0 'Tx enable DE/RE
SEROUT 1, 84,[STR serstr\9]
PAUSE 4000 'allow motor to reach posn
SEROUT 1, 84, [$01, $04, $01, $05, $FF, $fe, $7d, $48, $cd] 'moves motor -99000 steps relatively
PAUSE 4000 'allow motor to reach posn
GOTO MAIN
Can you describe a bit what you want to do with the BS2 and the stepper controller?
As Tom suggested, a Propeller might be a better fit for this project.
I don't think the BS2 can monitor two serial lines at the same time so if you wanted the microcontroller to both listen to commands coming from the debug terminal and also want the microcontroller to listen to replies coming from the stepper controller, you might want to switch to a more powerful microcontroller.
No question about it. The BS2 can't do two things at once without external hardware. In particular, there's no serial buffer so the BS2 can't listen to replies from the stepper controller and the debug port at the same time. It can't tranmit simultaneously either.
ProteanLogic shows a serial buffer on their website (the RSB509C). I don't know if they still carry it, but with two of them you could monitor both serial ports with the Stamp polling the serial buffers for any input.
Yes Mike, perhaps I'll just send ASCII Serout motor position commands using the BS2 and not listen to replies. I'll be getting feedback from other input devices to the BS2.
Just gives a bit more flexibility as the stepper controller only has a few DI and DO and two AI (Or I could multiplex several AI's to the stepper board perhaps)
"A Propeller might be a better fit for this project"
Probably is but I have several BS2's and don't (at the moment) intend buying / learning yet another micro.
Duane Degn wrote "Can you describe a bit what you want to do with the BS2 and the stepper controller?"
Well....just hobby robotics, three are on Utube,