sleepus interruptus

johndk

Senior Member
Okay, I'm confused with interrupt causing a wake from deep sleep. Maybe there's someone out there who knows about kissing the (sleeping) princess?

I'm running a 28x2 and wanting to put it into deep sleep (sleep 0) until my RTC says it's time to do your thing. I've found setting up interrupts to be somewhat less than intuitive, so I wrote a little test program first to make sure the PicAxe would do what it was supposed to.

I set up on hint2 (pin B.2) so that my RTC (DS3231) would send an alarm pulse (pulling B.2 low .. it has a pullup to keep it high otherwise). That was supposed to wake up my PicAxe to read the sensors and then go back to sleep for a while. The test program was to verify the activity of the interrupt before committing to the entire code.

Oddly enough, my test code works ... but doesn't. The code responds to the pulse on B.2 but it does not run anything that is contained in the interrupt sub. Is this by design? Certainly, I can code around it. But I want to be sure I'm not doing something wrong. It aprears that using an interrupt to wake from deep sleep does ONLY that and nothing else that might be contained within the interrupt sub. Can someone verify ... or tell me what I'm doing wrong? When I run the test code, I see only "sleep" and "wake" and not "int" or "msg" as I expected.

Also, it doesn't seem to make a difference if I include the "setintflags" line in the interrupt code as seems to be recommended in the docs.

Here's the test code:

#picaxe 28x2
#terminal 9600
#simspeed 10
#no_table

hintsetup %00000100
SETINTFLAGS %00000100,%00000000 ;interrupt for B.2 low pulse

main:
sertxd("sleep",cr,lf)
sleep 0
sertxd("wake",cr,lf)
goto main
end

message:
sertxd("msg",cr,lf)
return

interrupt:
sertxd("int",cr,lf)
call message
return
 

hippy

Technical Support
Staff member
I haven't tested it but shouldn't it be ...

SETINTFLAGS %00000100,%00000100

SETINTFLAGS configures the interrupt when 'flag2' is set, not the pin going low. HINTSETUP configures B.2 going low to set 'flag2'.
 

hippy

Technical Support
Staff member
This works for me ...

Code:
#picaxe 28x2
#terminal 9600
#simspeed 10
#no_table

hintsetup   %00000100           ; Set flag2 on B.2 going low
setintflags %00000100,%00000100 ; Interrupt on flag2 set

main:
sertxd("sleep",cr,lf)
sleep 0
sertxd("wake",cr,lf)
goto main
end

message:
sertxd("msg",cr,lf)
return

interrupt:
sertxd("int",cr,lf)
call message
flag2 = 0                       ; Clear flag2
setintflags %00000100,%00000100 ; Interrupt on flag2 set
return
 

johndk

Senior Member
Ahh... much better. I read the docs I don't know how many times but didn't catch the relationship between the pin and the flag. Makes sense once the addled mind makes the proper connection.

Thanks much! The princess is waking up and doing her royal chores on schedule now.
 
Top