PDA

View Full Version : simple serial interface (Solved)



Laurent R
03-31-2009, 10:29 PM
Hi

New day = > new problem http://forums.parallax.com/images/smilies/tongue.gif

I try to put a flow of byte in a buffer using the simple serial interface and the max3430 for rs-485

It works when i send $AAFF13 or $AA13
But if i send more than 3 bytes it doesn't works ...



VAR

LONG Chan
Byte Range
Byte Bip
Byte MyStr[1024]



the way i receive



ptr:=0
repeat while (MyStr[ptr]:=ser2.rx)<>$13
ptr++



the way i send

ptr2:=0
repeat ptr+1
ser2.tx(MyStr[ptr2])
ptr2++



Thanks for your help ...

Laurent

Post Edited (Laurent R) : 4/3/2009 7:55:21 AM GMT

StefanL38
04-01-2009, 12:40 AM
Hello Laurent,

the simple serial-object is much too simple to receive a lot of bytes

use the Serial Mirror-object from the obex (http://obex.parallax.com/objects/189/)

Inside this object it is easy to adjust the size of the receive and send-buffer

best regards

Stefan

Ariba
04-01-2009, 01:05 AM
Laurent

SimpleSerial has a bug in the receive methode, maybe this cause your problems.
Here is an improved version of the rx methode. Only the marked line must be added.




PUB rx: rxByte | t, b
{{ Receive a byte; blocks caller until byte received. }}

if rxOkay
dira[sin]~ ' make rx pin an input
b~ '<-- ADD THIS
waitpeq(inverted & |< sin, |< sin, 0) ' wait for start bit
t := cnt + bitTime >> 1 ' sync + 1/2 bit
repeat 8
waitcnt(t += bitTime) ' wait for middle of bit
b := ina[sin] << 7 | b >> 1 ' sample bit
waitcnt(t + bitTime) ' allow for stop bit

return (b ^ inverted) & $FF ' adjust for mode and strip off high bits




Andy

Laurent R
04-01-2009, 05:08 PM
Thanks Andy and Peter but it seems that your answers doesn't work for me...

I don't undersdand my problem because if i try to look after the CR caracter, it works for 3 Bytes transmission not more


ptr:=0
repeat while (MyStr[ptr]:=ser2.rx)<>$13
ptr++



But if I try this


MyStr[0]:=ser2.rx
MyStr:=ser2.rx
MyStr:=ser2.rx
MyStr:=ser2.rx
MyStr:=ser2.rx
MyStr:=ser2.rx



the prop wait that I send 5 caracter and send me back so I know that he has received a CR caracter ..

Post Edited (Laurent R) : 4/1/2009 9:16:11 AM GMT

Laurent R
04-01-2009, 06:32 PM
Hi all

trying the serial-mirror object i can now receive and send a lot of bytes ... but there is a but, new bytes are always put at the end of my buffer...

with this code i through that new bytes should begin at MyStr[0] ... but it isn't.



ptr:=0
repeat until (MyStr[ptr]:=ser2.rx)==$13
ptr++

MagIO2
04-01-2009, 06:46 PM
By the way, CR is not $13, it is 13 which is $0D in hex.

Laurent R
04-02-2009, 06:04 PM
Thanks MagIO2 it probably help me for the future but it don't solve my problem ... :)

As i initialize all my variable to 0 before doing a new reception i don't understand why old bytes aren't deleted when I receive a new reception ...

I'm confused so I still need help ...

Laurent

StefanL38
04-02-2009, 07:35 PM
Hello Laurent,

als long as your condition is (MyStr[ptr]:=ser2.rx)==$13
the condition stays FALSE when receiving a carriage return

only if you receive ASCII-Code 1*16+3 = 19 the condition will be TRUE

from your answer it is NOT clear if you made this change
your condition has to be

(MyStr[ptr]:=ser2.rx)==13 'WITHOUT the "$"

or (MyStr[ptr]:=ser2.rx)==$0D 'hexedcimal "0D" with the hexdecimal indicator "$"

If you use the serialmirrror-object and resize your receivebuffer to 1024 bytes or even 16384 bytes if you like
you just call ONCE rxstr and EVERYTHING IS DONE

why do you still want to walk on feet with programming a loop




ptr:=0
repeat until (MyStr[ptr]:=ser2.rx)==$13
ptr++





if you can drive by car

using serial-mirror and coding just




.rxstr(@MyStr)





best regards

Stefan

Laurent R
04-02-2009, 08:20 PM
Hi Stefan

Thanks for your support...

In the serial-mirror i don't find a rxstr method... so I add it from extended serial object ...

But I have still the same problem...

I want to receive a serial command , do a task , send a serial answer and then be able to receive a new command...

The new command should replace the old and be saved in MyStr but it always saved after the first...

I can't erase the first one ...

Regards

Laurent

Laurent R
04-02-2009, 08:41 PM
I hope my problem is solved...

Just try to stop and restart the serial communication each time I want to receive a new command and it seems to be good :)

thanks @ all

Laurent

Post Edited (Laurent R) : 4/2/2009 1:06:35 PM GMT

StefanL38
04-03-2009, 12:52 AM
Hello Laurent,

restart the serial communication that's shooting with canons on little birds

question: how many bytes are you receiving as ONE STRING as a maximum ?

I assumed from your original code MyStr[1024] that you receive up to 1024 bytes as ONE STRING

if your string-length is below 16 you can use the standard-objects

ANYWAY:
did you watch your incoming strings with a terminalsoftware ?
did you check with a terminalsoftware that your sending device is sending SINGLE commands ?

I have attached an archive with democode that works with PST.EXE as well as with brays terminal
using serial-mirror for receiving the string on Rx-Pin 26 and Tx-Pin 25
and send it to Rx-Pin 31, Tx-Pin 30


if you want to attach code use the archive-function of the propellertool

select your top-object-file (here main-test.spin) and then
cklick file - archive - project...

this creates a ZIP-file that contains ALL files needed to compile the whole project

best regards

Stefan

Laurent R
04-03-2009, 03:52 PM
Thanks to you Stehan,

I don't have to kill little bird with canons now :)

I think the bytefill command and the flush where the answer for me

Best regards

Laurent

propwell
04-06-2009, 12:47 AM
Hi together,

i'm pretty new in the business with Propeller and Programming in general, but i created a little program in Spin, which creates several lines and shows it on my screen, it works really good.
But now, i want to read die angles of the lines (which i previously saved in 3 Variables) from a serial connection.
For the first it would be enough if i could send a value like "180" from a serial terminal to the propeller, the porgram reads it and saves it in a variable!

Now my questions:
1. Can i make a serial connection with the USB-Connection which is on the Starter-Kit-Board?
2. I've downloaded the serialmirror.spin, can i use this one?
3. Is there something like a tutorial which i can read for not asking you these (surely) stupid questions?

Thank you,
propwell

Mike Green
04-06-2009, 12:54 AM
1) Yes, pin 31 is the receive line from the PC and pin 30 is the transmit line to the PC. Be careful since opening and closing the serial connection usually (by default) toggles the DTR line and this will cause the Prop to reset. You need to disable this behavior on the PC side, usually as an option on the serial port.
2) Yes, you should be able to use any of the serial I/O drivers to do this.
3) No. Do look at the FullDuplexSerial driver and the Extended FullDuplexSerial object. The latter includes routines for processing input numbers and strings.

In the future, please start your own thread. You'll get better and faster answers than hijacking someone else's thread.