PDA

View Full Version : New cog to run serial comms



realolman
01-23-2009, 05:23 AM
I am using the following code to communicate serially with the propeller. It, of course, includes Extended_FD_Serial

Is it OK to include only the portions of FD_Serial and Extended_FD_Serial that are used in the application?

And finally, to the question I originally wanted to know... I want the serial communication to occur in a new cog so that I can use a different cog to do something else . How do I figure how much stack space to allot to the new cog?

I know there was a portion of one of the manuals that addressed that, but I didn't really understand it, and this seems to be much more complicated than the examples.

I just arbitrarily set it at 40, which seems to work. If I were to just keep decreasing it to just above the point that the serial comms didn't work, would that be sufficient?




OBJ
SER : "Extended_FDSerial"

VAR
'place to put recieved transmission
long MyVariable

' to run new cog
long Stack[40]

CON
' spin stamp
'_CLKMODE = XTAL1 + PLL4X ' clock speed too low = 1X=10Mhz
'_XINFREQ = 10_000_000
' non-spin stamp
_CLKMODE = XTAL1 + PLL8X ' clock speed too high = 80Mhz
_XINFREQ = 5_000_000

PUB Main
cognew (Serial, @Stack)

Pub Serial
'handle serial transmissions

dira[17..21]:=%111111

ser.start(31,30,0,38400)

ser.str(string("Communication with propeller", $0D))
ser.dec(MyVariable)

waitcnt(10_000 + cnt)

ser.tx(13)
ser.tx(10)

outa[15] := 0
repeat
MyVariable :=ser.rxDec
outa[17..21] :=MyVariable

Paul Baker
01-23-2009, 05:55 AM
You can safely remove methods which are not used directly or by called methods. The compiler with throw an error if there is still a reference to a removed method which will indicate a dependency, replace the referenced method to get it functional again.

The stack question was asked (and answered) a couple days ago, check page 2, thread titled "Stack (Spin & PASM)" started by ImmNek.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)


Post Edited (Paul Baker) : 1/22/2009 10:00:32 PM GMT