PDA

View Full Version : what to connect serial communication to to test it/



realolman
01-09-2009, 06:27 PM
I have downloaded chip gracey's full duplex serial for· the propeller from the object exchange...

I'm not sure what to do with it. there seems to be both spin and assy language.··

To what can you connect it· to try it out?· Is there some documentation somewhere?

thanks

Post Edited (realolman) : 1/9/2009 9:05:14 PM GMT

sylvie369
01-09-2009, 06:48 PM
It won't do anything, of course, if you don't have your Propeller connected to something that communicates using serial protocols.

Have you worked your way through chapter 3 of the Propeller manual yet? If not, you should go there, hook up some LEDs to your Prop, and use the exercises in that chapter to familiarize yourself with the Propeller programming concepts. It'll clear up just about everything.

Edit: ditto everyone else on the "how about a subject line?". All forum posts should have descriptive subjects.

Post Edited (sylvie369) : 1/9/2009 5:42:42 PM GMT

heater
01-09-2009, 06:48 PM
Best thing is to have a quick read of the code, especially the SPIN functions, which has plenty of comments. For example you will find a start() function, that you should call first, which takes Tx and Rx pin numbers as parameters.

You could try it out just by connecting your Rx pin to your Tx pin as a loop back. Then send out bytes and receive them back as a test using the rx() and tx() functions

Do you have an application in mind?

P.S. Best add a subject to your thread.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

Chris Savage
01-09-2009, 11:33 PM
Please use the pencil icon to the top right of your message to add a descriptive subject line to your post. Take care.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

realolman
01-10-2009, 04:14 AM
Of course you are all correct about the lack of a subject... sorry about that...I have corrected it...·I'm surprised any of you read it.... you probably just wanted to see what the dope who·had no·subject had to say.

There's no disgrace in being dumb, but it is often unhandy.http://forums.parallax.com/images/smilies/smile.gif


Anyhoo...··· What I would eventually probably like to communicate with is a Visual Basic application, but for now, just to try to learn and understand this code, could you communicate with Hyper terminal or something like that?


I know what to do with serial comms in general, but I don't know what to do with this particular code in the propeller in order to try it out.


I guess I don't understand the concept of the "loop back"

Mike Green
01-10-2009, 04:32 AM
Loop back is simply connecting the receive and transmit lines together. You can test everything from your receiver/transmitter to the socket/plug and any length of wire to the other end as the signal goes out from the transmitter and loops back to the receiver.

There are all sorts of examples people have posted (and made suggestions) for a Stamp to communicate with VB. Exactly the same thing applies to using a Propeller for the same purpose. You can even use the BS2 Compatibility Library from the Object Exchange to supply the same sort of functionality. FullDuplexSerial just provides buffered serial I/O which neither the Stamp itself nor the BS2 Compatibility Library provides.

Leon
01-10-2009, 04:43 AM
As you want to communicate with a VB application, using HyperTerminal initially as you suggest would be a good idea. When testing comms software on an MCU I always start by transmitting a single character continuously (I always use '*'). If you have problems with that you can check the baud rate with a scope by sending 'U' continuously, which consists of alternating 1s and 0s, making it easy to check the bit time.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle

sylvie369
01-10-2009, 06:39 AM
If you just want to try out the code, you might download the Parallax Serial Terminal and set that up.

www.parallax.com/ProductInfo/Microcontrollers/PropellerGeneralInformation/PropellerDownloads/tabid/442/Default.aspx (http://www.parallax.com/ProductInfo/Microcontrollers/PropellerGeneralInformation/PropellerDownloads/tabid/442/Default.aspx)

It's useful to have what amounts to a (Stamp-style) Debug terminal for the Propeller, of course, and the PST uses the FullDuplexSerial object.

Michael O'Brien
01-10-2009, 06:44 AM
Realoman,
·· Hi, I was at the same point as you 2 days ago - i just started using this excellent serial communication object by Chip Gracey.
···Try the following (nothing special just 10 x's followed by a \r\n), my setup is using a javax.comm serial client on the host - but you should see serial output using any terminal program that matches the baud rate.

· 1. open a new propeller tool IDE
··2. type in a new spin program like the quickstart code below
· 3. put·Chip Gracey's FullDuplexSerial.spin into the same directory as your spin driver program
· 4. drag FullDuplexSerial.spin into your propeller tool IDE - just to view it
· 5. download your spin program by selecting its' tab and hitting F10 or F11
· 6. open a terminal or comm host program to see the x


{ quickstart spin driver for FullDuplexSerial.spin
}
VAR

OBJ
· SER··· : "FullDuplexSerial"·

DAT
···
CON
· ' spin stamp·
'· _CLKMODE = XTAL1 + PLL4X···· ' clock speed to low = 1X=10Mhz
'· _XINFREQ = 10_000_000
· ' non-spin stamp
· _CLKMODE = XTAL1 + PLL8X···· ' clock speed to high = 80Mhz
· _XINFREQ = 5_000_000
·
PUB Main
·ser.start(31,30,0,38400)
· dira[15] := 1 ' output port to also flash an LED for example
· repeat
·· repeat 10
··· outa[15] := 0
··· waitcnt(10_000 + cnt)
··· ser.tx("x")
··· outa[15] := 1
··· waitcnt(10_000 + cnt)
·· ser.tx(13)
·· ser.tx(10)···
··


· thank you
· /michael

Cluso99
01-10-2009, 10:32 AM
I suggest you use PST (Parallax Serial Terminal) and the PropTool first up. Hyperterminal sets DTR and this will reset your Prop. If you use PST and PropTool, they share the comm port (USB) and PST will release the port when it loses focus. This way you do not have to close PropTool and PST between uses - great for code changes http://forums.parallax.com/images/smilies/smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439

cruising (http://www.bluemagic.biz)]cruising[/url]

This is a bold test.

realolman
01-11-2009, 01:41 AM
Sorry to be so dense, but I must be missing something.

I have a·USB Propeller education board.· I have gone through·chapter three of the ·manual, and turned the LED s on and off and what not...·but I don't see anything about this or serial communication.

It appears to me that the Tx and Rx of the usb plug is hooked to P30 and 31 of the propeller.
I have downloaded the program to the propeller... now what?

Am I supposed to be using Full Duplex Serial as an·object that I call·from from something that I write or what?

How do I input what I want to transmit, transmit something, and how do I know I received it?


Should I be able to use Hyper terminal for Michael's program.. what com port?· ·what is the baud rate? start bits? stop bits? ·handshaking?

Like I said... sorry to be so dense, but I am just a noob with the propeller.· If there is some written literature explaining this I will be glad to read it, and not bug you folks.

Post Edited (realolman) : 1/10/2009 6:58:21 PM GMT

Michael O'Brien
01-11-2009, 03:14 AM
Real,
Even without a hyperterminal host connected you will see (red) led output for about 10 second from the propeller usb port when serial output is being sent.
See the following post for a photo of what you will see.
To get the port for hyperterminal hit F7 in the propeller too to get the comm port to your propeller.
Use all defaults for eberything else except the baud rate (this value must match spin and on the pc.
If you look at the driver spin above you will see a declaration to SER - this is the reference to chips's object.
Test in stages, comment out all ser.* line and make sure you see led output first.
The loopback test above is also a good test.

Thank you
/michael

Michael O'Brien
01-11-2009, 03:18 AM
See photo of serial ports in action below.
http://forums.parallax.com/forums/default.aspx?f=25&m=318912

realolman
01-11-2009, 03:41 AM
thanks I'm gettin some action now.

Shouldn't I be seeing "x" 's...····from the line:···· ser.tx("x")

I'm getting a bunch of this:

·ž€ž€ž€ž€ž€ž€ž€žę€˜€€ž€ž€ž€ž€ž€ž€ž€ž€ž€žę€˜€€ž€ž€ž €ž€
ž€ž€ž€ž€ž€žę€˜€€ž€ž€ž€ž€ž€...

Although it is definately Tx 'in http://forums.parallax.com/images/smilies/smile.gif


Again... thanks for helping.

EDIT: I had the wrong baud rate ...·· I'm getting rows of x's now.
I thought the line calling the ser.start(31,30,0,38400) set 38400 as the baudrate.... I'm not quite understanding the· CON block... seems to have 2 different clock speeds?

EDIT the EDIT.. I see now that one set makes the baud rate 38400 and the other makes it· 19200· also I used the PST... works nicer than hyperterminal ... all you have to do is pause it and com 5 is good to go with the propeller tool again.

Again, again ...· thanks for helping. I'll have to mess with this for a while.http://forums.parallax.com/images/smilies/smile.gif

Post Edited (realolman) : 1/10/2009 9:14:54 PM GMT

Cluso99
01-11-2009, 11:37 AM
PST - no need to pause it. When you click on PropTool, PST loses focus and drops the com port. When you return to PST after loading more code in PropTool, just click "connect' (or whatever it says). PropTool and PST work really well together. Easiest if you use the same baudrate (115,200) but not essential. http://forums.parallax.com/images/smilies/smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439

My cruising website http://www.bluemagic.biz

realolman
01-11-2009, 08:02 PM
better yet... thanks for the tiphttp://forums.parallax.com/images/smilies/smile.gif

Is this stuff correct?

·1. you can only send one byte at a time the way it is written
2. It has to be a string
3 What needs to be modified in order to send a larger transmission?·· Would you use something like·STRSIZE and a loop to send each character,· or can it be modified to send·something ·larger than a byte?

I have removed the loops from Michael's code and substituted· other byte size strings... which seems to work OK.···

·I also inserted more ser.tx( ) and that seems OK also

In full duplex serial,· why doesn't the lines after repeat until·need to be indented?



PUB tx(txbyte)

'' Send byte (may wait for room in buffer)

repeat until (tx_tail <> (tx_head + 1) & $F)
tx_buffer[tx_head] := txbyte
tx_head := (tx_head + 1) & $F
if rxtx_mode & %1000
rx

·I tried to indent it and it didn't work.

Post Edited (realolman) : 1/11/2009 2:04:29 PM GMT

Cluso99
01-11-2009, 09:41 PM
You need to look at the FDX code. Here are some samples..
(Postedit: use ser. instead of fdx.)

fdx.str(string("The quick brown fox", $0D))
fdx.tx("Y")
fdx.tx($41)
fdx.hex(data,8)

Repeat: If you indent the lines under the repeat until .... they will be executed which waiting for the repeat to be satisfied. Without indentation, the repeat will wait until the condition is valid before passing control to the next lines.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439

My cruising website http://www.bluemagic.biz

realolman
01-11-2009, 10:08 PM
Well, I'll be durned... thanks

How does one know that the syntax you showed with the "tx.str(string("The quick brown fox", $0D))"

exists... where is this stuff documented?

again.... thanks

sylvie369
01-11-2009, 10:16 PM
The string directive is documented on page 310 of the Propeller Manual. There you'll read that


Hard working but anonymous Parallax documentation guy said...
Explanation
The DAT block is used often to create strings or string buffers that are reusable for various
purposes, but there are occasions when a string is needed for temporary purposes like
debugging or one-time uses in an object. The STRING directive is meant for those one-time
uses; it compiles an in-line, zero-terminated string into memory and returns the address of
that string.


The syntax of the FullDuplexSerial object itself is documented in that object. The str method looks like this:



PUB str(stringptr)

'' Send string

repeat strsize(stringptr)
tx(byte[stringptr++])




That tells you that you need to supply a pointer to the string that you want to transmit. You could either send a pointer to a string variable (whose value has been established elsewhere), or you could use the string directive to supply a pointer to a constant string of characters right there in your str code.

In general, you're going to want to know about the directives like string that are built into Spin, and you're going to want to become familiar with the methods in the various objects (like PUB str in the FullDuplexSerial object) that expand on Spin. Look at the rest of the methods in FullDuplexSerial - those are all additional things that Spin can do as long as you put a reference to the FullDuplexSerial object into your OBJ block.

Note: Cluso99 wrote "(Postedit: use ser. instead of fdx.)"

Actually, he'll need to use whatever label he used to include the FullDuplexSerial object up in his OBJ block. It's not "ser" or "fdx" necessarily: it's whatever you choose to call it. For example, if I have this:



Obj
Debug : "FullDuplexSerial"



then my program might have this later:



Debug.str(string(13,"This is a test message!", 13))



In that case, "Debug" refers to the FullDuplexSerial object. On the other hand, if in my OBJ block I said this:



Obj
Serial : "FullDuplexSerial"



then my program would have to say this:



Serial.str(string(13,"This is a test message!", 13))

Post Edited (sylvie369) : 1/11/2009 3:45:50 PM GMT

realolman
01-12-2009, 04:34 AM
Thanks...
I have a lot to learn.

realolman
01-14-2009, 05:00 AM
How does one recieve serial transmissions?

I don't know how to declare a string variable.

Post Edited (realolman) : 1/13/2009 10:15:09 PM GMT

StefanL38
01-15-2009, 11:03 AM
hello,

in SPIN there are NO stringvariables.
You have to declare an array of bytes where each byte contains ONE character of the string.
This bytesequence needs a ZERO at the end. Zero-terminated strings




VAR
byte MyStrArray[16]





And then you have to use a POINTER to the ADRESS of the first element of this array.
You can get the ADRESS of any variable by using the Adress-Operator "@"

To make life a little bit easier you can use the Extended_FDSerial-object from the obex
This object uses FullDuplexSerial as a base and adds some useful methods.





OBJ
ExtSerial "Extended_FDSerial"

VAR
byte MyStrArray[16]

long PointerToMyStr


PUB TestReceive
PointerToMyStr := @MyStrArray

ExtSerial.RxStr(PointerToMyStr)





This codesnippet is NOT a working demo it just shows the basic principle
It's up to you to make sure that your bytearray is BIG enough (long enough)
to load in the complete string

It's up to you to make sure that the string ALWAYS ends with a zero
otherwise commands like str(PointerToMyStr) will make crash your program

another way is to define variables in the DAT-section of the sourcecode

again a code-SNIPPET (=uncompleted demo)




DAT
MyStr1 byte "Hello world",0 '<---- notice the terminating ZERO
MyStr2 byte " How are you doing ?",0 '<---- notice the terminating ZERO


PUB SendTestStr

ExtSerial.Str(@MyStr1)
ExtSerial.Tx(13)

ExtSerial.Str(@MyStr2)
ExtSerial.Tx(13)





best regards

Stefan

realolman
01-15-2009, 05:37 PM
Thank you very much sir... I will try this this evening.