Object Calls from Spin Cogs
JonnyMac
Posts: 9,202
I'm a little perplexed... I'm working on a project that sends CAN message from time to time and I want this to run as "background" process so that the main process can set flags for the required message. If I have this snippet of code in the main loop:
... but if I move it to another Spin cog -- no go.
What's really odd is that I put a marker for FDS (called term in my test code) and that works just fine, even from the background cog. Any ideas?
And yes, I have pushed the stack size up but with no change. The CAN object is very simple, Spin-based SPI interface for MCP2515.
work := (hrs << 16) | (mns << 8) | scs work := (work << 8) | $40 can.tx_msg(0, $91, $00, $04, @work)
... but if I move it to another Spin cog -- no go.
pri can_coms | work repeat if (canflags & %0000_0001) work := (hrs << 16) | (mns << 8) | scs work := (work << 8) | $40 can.tx_msg(0, $91, $00, $04, @work) ' does not work from bg cog canflags := 0 term.tx("*") ' works term.tx(CR) ' works
What's really odd is that I put a marker for FDS (called term in my test code) and that works just fine, even from the background cog. Any ideas?
And yes, I have pushed the stack size up but with no change. The CAN object is very simple, Spin-based SPI interface for MCP2515.
Comments
From which cog did you call the CAN object's start method?
-Phil
Did you also remove the variable work from VAR or DAT section? Maybe the address-operator and usual assignment behave different in case the variable exists twice (once in VAR/DAT and once as local variable)?
Could you post the rest of your code? Specifically the top level object and the 'CAN' driver object would be most helpful so we can determine what the issue might be. Alternately, you could email your code directly to me at: kmccullough@parallaxsemiconductor.com.
Thanks a lot!
Indeed this issue has to do with from which cog the start method is called (which initialized several pin directions). When the code loop is moved to a different cog, the other cog is essentially trying to drive the pin states but the pins were never set as outputs in that cog. The fix is to place your start method in the can_coms method before it falls into the repeat loop, so that it will be called when it is launched into a new cog. See example demo code attached.
Demo - Archive [Date 2011.10.18 Time 09.55].zip
The demo program runs on a quickstart board and blinks an LED (P16) whenever the pin (P15) is high. Suggest connecting a pull-down resistor from P15 to ground for this demo.
Cheers,