One newbie to all others... serial debug terminal
WNed
Posts: 157
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
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
Comments
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
[noparse][[/noparse] code]
[noparse][[/noparse] /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
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
best regards
Stefan
Post Edited (StefanL38) : 1/25/2009 9:49:49 AM GMT
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