DS1302 RAM - Trouble accessing from a seperate COG
While I am a newbie, I thought I had a pretty good handle on how this should work. However I can't seem to figure out what I am doing wrong.
I have a value stored in the first two byte registers of the DS1302 RAM.
The following works fine and displays the correct value.
However, moving the module to run under a COG doesn't produce the same result.
I have scoured the manual and can't seem to idnetify where my logic goes astray.
Would appreciate any help I can get.
Thanks!
I have a value stored in the first two byte registers of the DS1302 RAM.
The following works fine and displays the correct value.
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
VAR
word SwitchCount ' Counter to hold total number of switch closures
byte cmd
OBJ
pst : "Parallax Serial Terminal" ' Serial Terminal object - requires 1 cog
rtc : "DS1302_full"
PUB Start ' Main method
pst.Start(115_200)
pst.Str(string("Starting up..."))
rtc.init( 22, 21, 20 ) 'ports Clock, io, chip enable
rtc.config 'Set configuration register
SwitchWatch(@SwitchCount)
waitcnt(clkfreq * 2 + cnt) ' Wait 1 second -> .5 Hz
pst.Str(string(pst#NL, "RAM value..."))
pst.Dec(SwitchCount)
PRI SwitchWatch(CounterAddr)
cmd:=rtc.command(rtc#ram,rtc#burst,rtc#r)
rtc.readN(cmd, CounterAddr, 1)
However, moving the module to run under a COG doesn't produce the same result.
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
VAR
word SwitchCount ' Counter to hold total number of switch closures
long Stack[20] ' Sets up a stack space
byte SwitchCogID ' Cog ID of the SwitchWatch Cog
byte cmd
OBJ
pst : "Parallax Serial Terminal" ' Serial Terminal object - requires 1 cog
rtc : "DS1302_full"
PUB Start ' Main method
pst.Start(115_200)
pst.Str(string("Starting up..."))
rtc.init( 22, 21, 20 ) 'ports Clock, io, chip enable
rtc.config 'Set configuration register
SwitchCogID := cognew(SwitchWatch(@SwitchCount), @Stack) 'Starts a Cog, calls SwitchWatch, the Cog uses @stack
waitcnt(clkfreq * 2 + cnt) ' Wait 1 second -> .5 Hz
pst.Str(string(pst#NL, "RAM value..."))
pst.Dec(SwitchCount)
PRI SwitchWatch(CounterAddr)
cmd:=rtc.command(rtc#ram, rtc#burst, rtc#r)
rtc.readN(cmd, CounterAddr, 1)
I have scoured the manual and can't seem to idnetify where my logic goes astray.
Would appreciate any help I can get.
Thanks!
