Setintflags off doesn't work outside of interrupt

oracacle

Senior Member
I have found that running the setintflags off outside of the interrupt routine doesn't switch them off. It seems to work fine inside.
I found this with a routine were the end of the routine could either switch the interrupt back on or leave it off.
There is a work around that I haven't written up yet but seem kind of weird for it not to work outside the interrupt routine.
This is running on a 20x2, the entire code is too large to post and has not affect on this issue.

Code:
                  [color=Blue]setintflags [/color][color=Navy]%00010000[/color][color=Black], [/color][color=Navy]%00010000
                  [/color][color=Blue]do
                        if [/color][color=Purple]hserptr [/color][color=DarkCyan]> [/color][color=Navy]0 [/color][color=DarkCyan]or [/color][color=Purple]tempbyte0 [/color][color=DarkCyan]= [/color][color=Navy]10 [/color][color=Blue]then exit
                  loop
                  setintflags off
                  [/color][color=Green]'low shutter
                  'low focus
                  [/color][color=Blue]if [/color][color=Purple]lite [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
                        high LEDs
                  end if
                  setfreq m8
                  [/color][color=Green]'reutrn to detector page
                  [/color][color=Blue]hserout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Red]"page "[/color][color=Black],[/color][color=Red]"9"[/color][color=Black],[/color][color=Navy]$FF[/color][color=Black],[/color][color=Navy]$FF[/color][color=Black],[/color][color=Navy]$FF[/color][color=Blue])
      endselect
      return
      

interrupt:
      setintflags off
      [/color][color=Green]'sertxd ("Trig", 13,10)
      [/color][color=Blue]if [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then                                  [/color][color=Green]'check for bulb setting
            [/color][color=Blue]pause [/color][color=Purple]usvalue                             [/color][color=Green]'add pause if required
            'pulsout flash, 10                              'fire flash
            [/color][color=Blue]if [/color][color=Purple]strobe_flag [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then                   [/color][color=Green]'check for strobe active
                  [/color][color=Blue]for [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Purple]strobes        [/color][color=Green]'loop for number of srobes
                  [/color][color=Blue]pause [/color][color=Purple]strobe_dur                    [/color][color=Green]'wait for time between each flash
                  'pulsout flash, 10                        'fire flash
                  [/color][color=Blue]next [/color][color=Purple]tempbyte1                      [/color][color=Green]'continue loop
            [/color][color=Blue]end if
      end if
      if [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]2 [/color][color=DarkCyan]or [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]6 [/color][color=DarkCyan]or [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=DarkCyan]or [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]5 [/color][color=Blue]then    
                                                      [/color][color=Green]'mirror up, single shot
            [/color][color=Blue]pause [/color][color=Purple]usvalue                             [/color][color=Green]'wait for delay time if needed
            'high shutter                             'open shutter - 0.055 second in single shot, or 0.054 if mirror up mode
            [/color][color=Blue]if [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=DarkCyan]or [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]2 [/color][color=Blue]then      [/color][color=Green]'chec for flash activation
                  'pulsout flash, 10                        'fire flash if true
            [/color][color=Blue]end if      
            if [/color][color=Purple]strobe_flag [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then                   [/color][color=Green]'check for strobe activation
                  [/color][color=Blue]for [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Purple]strobes
                  [/color][color=Blue]pause [/color][color=Purple]strobe_dur
                  [/color][color=Green]'pulsout flash, 10
                  [/color][color=Blue]next [/color][color=Purple]tempbyte1
            [/color][color=Blue]end if
      pause [/color][color=Navy]500                                       [/color][color=Green]'shutter needs a small activation period for reliable operation.
      [/color][color=Blue]end if
      if [/color][color=Purple]prg_flag [/color][color=DarkCyan]= [/color][color=Navy]7 [/color][color=Blue]then                                  [/color][color=Green]'check for burst mode
            [/color][color=Blue]pause [/color][color=Purple]usvalue                             [/color][color=Green]'wait if needed
            'high shutter                             'open shutter
            [/color][color=Blue]pause [/color][color=Purple]burst_time                          [/color][color=Green]'hold shutter open for some time
      [/color][color=Blue]end if
      inc [/color][color=Purple]tempword1     
      [/color][color=Blue]if [/color][color=Purple]cont_flag [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
            let [/color][color=Purple]tempbyte0 [/color][color=DarkCyan]= [/color][color=Navy]10                              [/color][color=Green]'set flag so holding loop exits
      [/color][color=Blue]else
            setfreq m8
            [/color][color=Green]'send tempword1 to dislay
            [/color][color=Blue]hserout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Red]"taken.val="[/color][color=Black],#[/color][color=Purple]tempbyte3[/color][color=Black],#[/color][color=Purple]tempbyte2[/color][color=Blue])
            gosub [/color][color=Black]nextion_stop
            [/color][color=Blue]setfreq m64
            let [/color][color=Purple]flags [/color][color=DarkCyan]= [/color][color=Navy]0                                   [/color][color=Green]'reset interupt flags
            [/color][color=Blue]setintflags [/color][color=Navy]%00010000[/color][color=Black], [/color][color=Navy]%00010000
      [/color][color=Blue]end if
      [/color][color=Green]'sertxd (#hserptr,44,#tempbyte0,13,10)
      [/color][color=Blue]return[/color]
 

hippy

Technical Support
Staff member
I haven't tested it with a 20X2 or comparator interrupts but "SetIntFlags Off" behaviour works as expected outside the interrupt routine on a 28X2 using background serial receive interrupts so I would have expected it to be the same on a 20X2 and for comparators.

Are you sure you are executing the "SetIntFlags Off" and not re-enabling "SetIntFlags" elsewhere ?
 

hippy

Technical Support
Staff member
Tested a 20X2 and comparator interrupts and, once "SetIntFlags Off" is executed outside the interrupt, no further interrupt invocations are made. It's working as expected in my testing.
 

inglewoodpete

Senior Member
I would not include a subroutine call from the interrupt routine. I seem to recall that the subroutine's "return" statement interferes with the orderly exitting from the interrupt routine. The "return" statement in an interrupt routine is used to trigger the re-enabling of interrupts if they were enabled within the routine.
 

oracacle

Senior Member
I found the problem. Of all things it tracked back to when the hserptr was reset.
The picaxe calls a standard page when there is a user call to end the routine, this routine is triggered when the display send an arbitrary (in this case the page number) piece of data causing the hserptr to increase and trigger a loop exit. the original code lacked the hserptr = 0 command meaning the when returned to the main code body it automatically ran back through and assumed it was on the running page and reset the interrupt. By adding the hserptr = 0 just before the page call and after serial data has finished being sent any information that has been sent is ignored due to the hserptr being set to 0.

the main programme loop looks for hserptr > 0 to check for user input and calls a routine containing all the cases that might occur. so by not resetting the hserptr it thought it was just receiving a call for user input, even then the hserptr needed to be done after the entre data set had been received from the display.

Thanks for your help guys.

Also inglewoodpete, remove the nextion_stop call made seemed no difference, but seeing as the call has been removed, I will leave it removed.
 
Top