Help with serial appretiated...
OlovA
Posts: 23
Hi. I would like to receive 8 byte's of binary data, i dont have a special start or stop character.
I just must wait for the data to come and then i want to store my data and clear the receive buffer and wait again...
I have tried a lot, but i just cant get it work perfectly...
Would appretiate some help / Olov, Sweden.
I just must wait for the data to come and then i want to store my data and clear the receive buffer and wait again...
I have tried a lot, but i just cant get it work perfectly...
Would appretiate some help / Olov, Sweden.
Comments
Have you looked at the FullDuplexSerial Object? This is a great object for sending and receiving bytes. This object does the send/receive and you can read the buffer to get your data.
Tell us more about what you tried. What device is on the other end of the serial line?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
It works sometime, but sometime i only get back 5 characters to the PC, wouldn't that be impossible
because of my tx-loop ???
I tell the prop. to send 0 to 7 in my tx-loop ???
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
byte DataStr1[noparse][[/noparse]8],Ptr,x
obj
Serial : "FullDuplexSerial"
PUB main
Serial.start(31,30,0,9600)
repeat
Ptr := 0
Repeat
repeat
DataStr1[noparse][[/noparse]ptr] := Serial.Rx
while DataStr1[noparse][[/noparse]ptr] == -1 'Here i want the prop to wait for character in receive buffer
ptr++ ' Then increase my pointer
while Ptr < 8 ' Until 8 characters received ( 0 to 7 )
repeat x from 0 to 7
Serial.tx(dataStr1[noparse][[/noparse]x]) ' Then send it back to the PC
Like this....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
byte DataStr1[noparse][[/noparse]8],Ptr,x
obj
Serial : "FullDuplexSerial"
PUB main
Serial.start(31,30,0,9600)
repeat
Ptr := 0
Repeat
repeat
DataStr1[noparse][[/noparse]ptr] := Serial.Rx
while DataStr1[noparse][[/noparse]ptr] == -1
ptr++
while Ptr < 8
repeat x from 0 to 7
Serial.tx(dataStr1[noparse][[/noparse]x])
also take a look into the Extended_FDSerial-object. It uses FullDuplexSerial as some mind of a "base-object"
It has already a amtheod for receiving strings
this method uses delimiters but as in your case you have 8 bytes all the time you can change the condition
you don't have to wait extra for bytes beeing received rx himself waits until there comes something in
her's the code from Extended_FDSerial
best regards
Stefan
This code should just do that job, and then send it back to the pc. Okay it does, BUT...
As u can see i toggle P17 just to see that "i have been there", That works too, but the last transmit "Serial.tx("A")
That one comes at the next cycle !!! I dont get it...
As u might now, i just started with the prop. i have done some programming with Microchip before...
No, i cant understand why my "Big A" comes at the next cycle and not directly after my toggle of P17
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
#1 HHD Free serial port monitor
#2 Device monitoring studio
I use this program's to monitor my serial activity, then i'll use "Artsoft Mach 3, Modbus Serial control monitor" to send the message. I'm trying to create a modbus client.
I have done this with microchip's 16F876,77 and that worked just fine, but now i want more "power" ( cog's ) so that's why i want to use the propeller...
When i use the second program, "Device monitoring studio", then i'll get the timestamps too from the serial activity so i can see that it is like this...
Can my prop be broken ??? I really dont think so, but ???
If u guys just try this small program and some terminalprogram, do u get the same result ???
Thank's / Olov...
Same result!!!
The simple solution is to put a delay of a few milliseconds after the last 'serial.tx' call like 'waitcnt(clkfreq/500 + cnt)'
The more complex solution is to use a modified version of FullDuplexSerial with a routine (method) that waits for the output buffer to become empty, then waits for the last character to be transmitted completely.
Post Edited (Mike Green) : 11/24/2008 2:36:30 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."
- Bjarne Stroustrup
Serial.tx($01)
Serial.tx($04)
Serial.tx($00)
Serial.tx($00)
Serial.tx($00)
Serial.tx($01)
Serial.tx($31)
Serial.tx($CA)
But that really makes "FullDuplexSerial.spin" confused
This sequence is ok, but not that one above... I dont know how to make it work, i cannot use "Serial.hex" because it converts to
for example "01" to ascii 31
Serial.tx($01)
Serial.tx($06)
Serial.tx($00)
Serial.tx($00)
Serial.tx($00)
Serial.tx($00)
Serial.tx($89)
Serial.tx($CA)
So, does anyone know how to transmit like this ?
I think you are getting a couple things confussed. I believe the code you have above is truely sending the hexadecimal you want to send. I mean, if you have an oscilloscope or a logic analyzer or even the View Port (free 30-day trial - find it in the other threads - it is way cool) you will see that the serial pin is indeed transmitting your hex out.
The problem is reading the hex on the terminal program. The terminal program sees $01 and interprets it as "Start of heading" and doesn't dispaly anything. However, if you are using the "serial.hex" I believe it is taking your hex value and converting it to ASCII readable characters to show in the terminal program. This explains why $01 is translated to "1" in ASCII which is $31.
Does this make sense? Search out ViewPort, it looks like a great tool. I am about to start using it too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
I can take a screenshot later and show it here...
I'm going to use this application along with Mach3, That is a CNC-software for PC.
It work's really nice with my Microchip Pic16F876 and 877, so it should work...
I found it! It was "rubbish behind the keyboard", my own fault, i sent two bytes to much back to the serverprogram, then the checksum was ofcourse illegal...
That's life, anyway, many thank's for the lessons in propeller programming, i'm sure i'll be back with more questions, maybe i can assist someone someday.
Now i can continue my project, that is a small Modbus-client, some digital in/out's and servocontrol, communication via RS485, multidrop...
I really start to like the prop.
Thank's / Olov
This is great to hear that the problem was solved! Excellent! You are going to control a CNC machine with it? I have heard of Mach3 but I have not used it. I bet there are others interested on the forum in CNC and using the Propeller as a controller.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com