Simple_Serial not so simple for me
redrocker
Posts: 10
Hello, I am trying to receive transmission from a digital compass to no avail.
The compass outputs an rs232 signal. I currently have it configured to to output the compass heading value at 10hz. The format goes like xxx.x<cr><lf>. I am running the signal through the RS232 port on the PPDB and into some I/O pins of the propeller. My first thought is that it may be a wiring mistake so I will take it to school and look at the output from the max232 driver on an osciliscope to be sure.
However in the mean time I thought I would test the spin code.
To do this I thought I would write a simple program utilizing Simple_Serial.spin object. My thinking was that I could use a COG and an I/O pin to transmit a a character twice a second. Then I would use a 2nd COG and I/O pin to continually receive output and record the value in a global variable "xx". To check my work I tried to use a third COG to transmit the value of "xx" to the parrallax serial terminal. But I dont ever see anything on the terminal. Though I have sent debug data to the terminal to test it out. This is my first spin program so try not to laugh:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
baud=9600 'speed of the I/O serial
tbaud=19200 'Baud of the Parrallax Serial Terminal
TR=31 'Recieving pin for Terminal
TT=30 'Transmit pin to Terminal
SR=21 'Recieving I/O pin
ST=20 'Trans I/O pin
mode=1 'Not needed for Simple_Serial
Var
long xx
long Stack[noparse][[/noparse]9]
long Stack2[noparse][[/noparse]9] 'not sure if I need 2 stack variables
OBJ
SERT: "Simple_Serial"
PUB Serialtest
cognew((StartTrans),@Stack ) 'Cog1
cognew((RecTrans), @Stack2 ) 'Cog2
SERT.init(TR,TT,tbaud) 'This should be the Cog0 sending helloA to the termial
repeat
SERT.str(string("hello"))
SERT.str(xx)
waitcnt(clkfreq/2+cnt)
PUB StartTrans
SERT.init(sR,sT,baud)
repeat
SERT.tx(65)
waitcnt(clkfreq/2+cnt)
PUB RecTrans
SERT.init(sR,ST,baud)
repeat
xx:=SERT.rx
Any help on this would be greatly appreciated. I have been banging my head against the wall days.
Thanks
Adam
The compass outputs an rs232 signal. I currently have it configured to to output the compass heading value at 10hz. The format goes like xxx.x<cr><lf>. I am running the signal through the RS232 port on the PPDB and into some I/O pins of the propeller. My first thought is that it may be a wiring mistake so I will take it to school and look at the output from the max232 driver on an osciliscope to be sure.
However in the mean time I thought I would test the spin code.
To do this I thought I would write a simple program utilizing Simple_Serial.spin object. My thinking was that I could use a COG and an I/O pin to transmit a a character twice a second. Then I would use a 2nd COG and I/O pin to continually receive output and record the value in a global variable "xx". To check my work I tried to use a third COG to transmit the value of "xx" to the parrallax serial terminal. But I dont ever see anything on the terminal. Though I have sent debug data to the terminal to test it out. This is my first spin program so try not to laugh:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
baud=9600 'speed of the I/O serial
tbaud=19200 'Baud of the Parrallax Serial Terminal
TR=31 'Recieving pin for Terminal
TT=30 'Transmit pin to Terminal
SR=21 'Recieving I/O pin
ST=20 'Trans I/O pin
mode=1 'Not needed for Simple_Serial
Var
long xx
long Stack[noparse][[/noparse]9]
long Stack2[noparse][[/noparse]9] 'not sure if I need 2 stack variables
OBJ
SERT: "Simple_Serial"
PUB Serialtest
cognew((StartTrans),@Stack ) 'Cog1
cognew((RecTrans), @Stack2 ) 'Cog2
SERT.init(TR,TT,tbaud) 'This should be the Cog0 sending helloA to the termial
repeat
SERT.str(string("hello"))
SERT.str(xx)
waitcnt(clkfreq/2+cnt)
PUB StartTrans
SERT.init(sR,sT,baud)
repeat
SERT.tx(65)
waitcnt(clkfreq/2+cnt)
PUB RecTrans
SERT.init(sR,ST,baud)
repeat
xx:=SERT.rx
Any help on this would be greatly appreciated. I have been banging my head against the wall days.
Thanks
Adam
Comments
Don't know if this helps but I know most of the languages are CASE sensative, just thought i would shoot that out there.
-Mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
======
······ I'll try everything once [noparse]:)[/noparse]
Look at the 4port full duplex serial object, run 4 serial devices with one object, all at different baud if needed.
Post Edited (TChapman) : 5/20/2009 6:32:26 PM GMT
Then you can use a max232 to turn the TTL signals into rs232 signals. The objects have a pretty good documentation on how they work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
You need at least 2 instances of SimpleSerial for 2 Transmitter and 1 Receiver. Always when you call SERT.init(..) you overwrite the Pin- and Baudrate settings of the SimpleSerial object.
As a first try: Comment out the 2 cognew(..) lines, then the text "hello" should appear on the terminal.
Then insert a second SimpleSerial object for the StartTrans and RecTrans cogs with another name, and init this only one time (the init can be in the main methode (Serialtest).
And finally: The receice methode of SimpleSerial has a bug, you need to add 1 line:
Andy
Andy,
Yes when I comment the Cognew lines I do get a hello through the terminal. However I added the suggested changes (and fixed the Simple_Serial.spin object) and I still get nothing with the cognews uncommented, which means something is still being overwritten?
Anyway here is the cod
simple_serial is so simple PROGRAMMED and has so many limitations that it is complicated to USE
switch over to FullDuplexSerialPlus or Kyes serial object
This objects runs it its own cog and can do sending and receiving at the same time
best regards
Stefan
By FullDuplexSerialPlus, do you mean Extended Full Duplex Serial? I am assuming so because I saw that you gave it a 5 star rating. I am not sure where to find the Kyes oject however.
Adam
I've tried your code now. The stack size was to little, and the parentheses around the methode name in cognew are not allowed (don't know why). This code works on my propeller. Caution: I have changed the pins for the 2. serial port.
Shown is also a possible synchronization between the rx cog and the output to the terminal (remove the waitcnt before).
Andy
You are a stud! Working like a champ! Can I ask how you found out the stack was too small? Thanks for the wonderful synchronization addition as well.
Thanks
Adam
Post Edited (redrocker) : 5/20/2009 10:08:26 PM GMT
The FullDuplexSerialPlus object·is bundled in with the Propeller Tool version 1.2.6, in the Examples > PE Kit > 6 - Objects folder. You might find the Spin Tutorial in the Help and the PE Kit Labs book pdf which is linked in the Help Resources page to be useful.
To determine how much stack space you need, check out the Stack Length.spin object that is included in the Propeller Tool v1.2.6 folder.·There is a Webinar video demonstrating how to use it, called How can you determine how much stack space is needed for Spin code launched into another cog?··posted on this page. under Memory Manangement:
http://www.parallax.com/tabid/766/Default.aspx·
Have fun!
-Stephanie Lindsay
Editor
Parallax Inc.