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
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