I'm baffled by this one!
** please note I have simplified the code, kindly don't offer to change the approach it's done this way for a reason not shown here **
I have the RTC PTC with interrupt running (sei() is called), and AC2 also with interrupt running. I can trigger the AC2 change with a hardware wire.
All LED outputs which I'm using for visual checks are tested and working.
First I have a few shortcuts for the comparator....
#define HW_CMP_STATE(CMP) CMP.STATUS & AC_STATE_bm #define HW_CMP_INT_RESET(CMP) CMP.STATUS |= AC_CMP_bm #define HW_CMP_INT_ENABLE(CMP) HW_CMP_INT_RESET(CMP); CMP.INTCTRL |= AC_CMP_bm; #define HW_CMP_INT_DISABLE(CMP) CMP.INTCTRL &= ~AC_CMP_bm; HW_CMP_INT_RESET(CMP) #define HW_CMP_INT_STATUS(CMP) CMP.STATUS & AC_CMP_bm
And the interrupt handler which sets a flag then disables the interrupt.
ISR(AC2_AC_vect) { motionDetected = 1; HW_PIN_SET_HIGH(STORAGE_PIN_HIGH_PORT, STORAGE_PIN_HIGH_NUM); HW_CMP_INT_DISABLE(AC2); }
And the while loop. The RTC PTC handler is setting tasker.ops.tasks = 1 and it's being cleared later. For brevity I didn't include that code but wanted to leave it in to state that interrupts are enabled and working for RTC PTC.
HW_CMP_INT_ENABLE(AC2); while(1) { if (tasker.ops.tasks) { tasker.ops.tasks = 0; if (HW_CMP_INT_STATUS(AC2)) { HW_PIN_SET_HIGH(STORAGE_PIN_MEDIUM_PORT, STORAGE_PIN_MEDIUM_NUM); } if (motionDetected) { HW_PIN_SET_HIGH(USB_LED_PIN_PORT, USB_LED_PIN_NUM); } } }
So, what happens is it runs and no LED's light up. I then do the hardware level change and STORAGE_PIN_MEDIUM_PORT lights up when the RTC PTC next triggers. This means the AC2 interrupt is working and has set the STATUS flag.
However there's no jump to AC2 (vector 19). The STORAGE_PIN_HIGH_PORT doesn't light up. Neither is motionDetected set, so USB_LED_PIN_PORT doesn't light up either.
Bewildering!