PDA

View Full Version : One newbie to all others... serial debug terminal



WNed
01-25-2009, 08:39 AM
Hello All,
I just recently started playing seriously with my Propeller demo board. I've been messing around with a BS2 for some time, and was pretty intimidated at having to learn everything from scratch on the Prop. There are a lot of extremely helpful people in these forums, and I'm endlessly grateful to you all. What I have not seen in any of the Propeller postings, though, is one place where newbies can go and get an answer to one of the most basic questions, when you come over from the BS2 world: How do I get Debug terminal output from a Propeller. If there is such a posting and I missed it, I apologize, and the moderator can ditch this one. This is not a detailed "engineer's" explanation, this is a "technician's" Make it work example. Here's what I did to get a bare bones debug display that works, using the Propeller Demo board:
First, you need to download, unpack and configure the Propeller Serial Terminal. That will be your Debug screen. If you don't know what serial port your Propeller is on, in the Prop Editor, hit F7. If your Propeller is turned on and connected, that will tell you what port it's on. I use a baud rate of 19200. Then you need to be sure you have "Numbers.spin" and "Simple_Serial.spin" in your Propeller Library folder, usually C:\Program Files\Parallax Inc\Propeller Tool (with some version number).
Look through Chapter 3 in the manual and learn how Objects are used. Then be sure you add the "Numbers", and "Simple_Serial" objects to your program:
Notice how each object is given an Alias, Num for Numbers, and Comm for Simple_Serial. Those are what are used in your code.
OBJ
Num : "Numbers" 'Use Number To String method ( Num.ToStr()) for debugging
Comm : "Simple_Serial" 'For Debug Purposes

The Simple_Serial object will expect the following constants to be set:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
'Simple_Serial
RXPIN = 31 'The demo board uses Pin 31 as the serial receive pin
TXPIN = 30 'The demo board uses Pin 30 as the serial transmit pin
BAUD = 19_200 'Uhh, Baud Rate
In addition, Simple_Serial wants a one Byte variable, I use "Byte Okay", to hold the return from the Serial Init function.
The following code *must* be at, or near, the beginning of your PUB Main code:
PUB Main
Num.Init 'Initialize the Numbers Object
Okay := Comm.start(RXPIN, TXPIN, BAUD) 'Init Serial Comms.
Now you can use the following code, anywhere in your program, to get simple output to the Serial Terminal:
If Okay 'If Comm.start succeeded
Repeat
Comm.str(string("Pin: ")) 'Send text label to serial terminal
Comm.str(Num.ToStr(Pin, Num#DEC)) 'Convert numeric variable Pin to a String, then send that value to the serial terminal
Comm.tx(13) ' Send Carriage Return.
Waitcnt(4_000_000 + cnt)

This code is in an endless loop for a reason. Since you can't be looking at the Serial Terminal while you're telling the Prop tool to download your program, and the serial terminal must be disabled to allow the program to download, and your program starts immediately, if you just have the code send the value once and move on, you'll miss it. If your program is taking constant readings and is looping anyway, the loop I have is not necessary, and will halt your program loop. In the above example, "Pin: " is a text label I am sending out to the terminal. Pin is a Long variable.
This may not be as tidy as the BS2 debug screen, but at least you'll be able to see something, and it's a decent intro to serial communications.
Go. Have fun. Play.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno

StefanL38
01-25-2009, 03:40 PM
Hello WNed,

good info - but you did not finish the foolproof testings.

When compiling your code the result is to get some errors

this forum provides a function to insert well formatted code
and as indention is very important code should be always inserted with the

[ code]

[ /code] brackets

or for bigger codes use tha attach-function

you can access this by using the "Post Reply" button

I highly recommend using the Extended_FDSerial-object instead of the simple_serial-object !

simple-serial is sooo simple that the USE of it is COMPLICATED and hits limitations quickly

So here is a working democode with some more basic hints about errors that newbees like to step into




CON
'serial communication requires a precise clockmode
'internal oscillator-mode is much too much unprecise
'so ALWAYS use a xtal1-mode
_clkmode = xtal1 + pll16x
'when using another chrystal than 5 MHz adjust constant _xinfreq
'to the right value
_xinfreq = 5_000_000

'result of pll16x * _xinfreq should NOT exceed 80MHz
'example if _xinfreq = 10_000_000 than use pll8x instead of pll16x
'as 10_000_000 * 16 = 160MHz and 10_000_000 * 8 = 80MHz

OBJ
'download the Extended_FDSerial-object from the obex
'link http://obex.parallax.com/objects/31/
'or use search-function with keyword "fullduplex"

Debug : "Extended_FDSerial"


VAR
long MyVar


PUB Main
'FIRST thing to do is to start the Extended_FDSerial-object
'by using rx-pin no 31 and tx-pin no 30 you use the SAME serial connection
'for debugging as for programming the propeller
'start PST.EXE and adjust baudrate to 115200
Debug.Start(31, 30,0,115200) 'start(rxpin, txpin, mode, baudrate) :

'' '"rx" and "tx" viewed from Propeller-Chip. Propeller-Chip-PIN-Tx ----> PC

Debug.Str(string("Debug.Start(31, 30,0,115200) done"))

MyVar := 1

repeat
Debug.Str(string("Decimal Value of MyVar="))
Debug.dec(MyVar)
Debug.Tx(13) 'carriage return
Debug.Tx(13) 'carriage return
Debug.Str(string("take a look into the Extended_FDSerial.SPIN-File",13))
Debug.Str(string("to see how many useful functions it has for",13))
Debug.Str(string("send and receive strings hex-values, bin-values etc",13))
Debug.Tx(13) 'carriage return
Debug.Tx(13) 'carriage return
Debug.Tx(13) 'carriage return
'use systemvariable ClkFreq for waiting. ClkFreq provides ALWAYS an easy way
'to calculate waittimes ClkFreq waits for ONE second
'ClkFreq * 5 waits for 5 seconds
'ClkFreq / 4 waits for 1/4 seconds etc.
waitCnt(ClkFreq * 2 + cnt)

MyVar ++ 'incremenet variable MyVar by 1





finishing foolproof testing means

1.) submit your posting
2.) copy code from the posting to clipboard
3.) insert code from clipboard into a blank *.SPIN-file
4.) compile and download it to the propeller and check if EVERYTHING is running

if this works your code is NEARLY foolproof tested (fools ALWAYS find another thing to get errors)

running this code ou should see the following text in PST.EXE




Decimal Value of MyVar=4

take a look into the Extended_FDSerial.SPIN-File
to see how many useful functions it has for
send and receive strings hex-values, bin-values etc



Decimal Value of MyVar=5

take a look into the Extended_FDSerial.SPIN-File
to see how many useful functions it has for
send and receive strings hex-values, bin-values etc



Decimal Value of MyVar=6

take a look into the Extended_FDSerial.SPIN-File
to see how many useful functions it has for
send and receive strings hex-values, bin-values etc





best regards

Stefan

Post Edited (StefanL38) : 1/25/2009 9:49:49 AM GMT

WNed
01-26-2009, 04:43 AM
Hi StefanL38,
Einstein once said that the life's work of a genius can be undone by a fool in 5 minutes... and I'm no genius.
I only knew after I posted my message that all the leading spaces would get removed by the forum software... should have known really, but I didn't think of it. Anyway, after it was posted, I couldn't see any way to go in and edit it, thus the missing indents under the 'Repeat'. I'll keep your message in mind next time I need to post any code snippets. Thanks.
I should note that the whole block of short lines of text is not meant to be copied as a whole and dropped into a blank page. If you do that, yes you will get errors. I meant the post to be a reference for the pieces that make a quick serial connection. In the end, I have to conclude that I didn't create a document that is as easily understood as I wanted, but it got you to post one that's much clearer, and newbies will be able to use it... which was my original purpose! Now anyone doing a search for newbie, serial, debug or terminal should find this, read your document and be good to go. That's what makes these forums so cool.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno