Hi, just want to add up to here for others' reference.
I had the almost similar issue which bring me to this thread.
After looking at Edward Karpicz, I checked through my code which found following:
- RESET_MONITOR: BRCLR CRGFLG,#LVRF,RESET_MONITOR1 ;check if this is power reset / low voltage reset
- BSET CRGFLG,#LVRF ;clear the flag
- ;do something with low voltage reset
- RESET_MONITOR1: BRCLR CRGFLG,#PORF,RESET_MONITOR9
- BSET CRGFLG,#PORF ;clear the flag
- ;do something with power reset detection
- MOVB #ATR_PWR_RESET,ADDATR_CODE
- BRA RESET_MONITOR2
- RESET_MONITOR9: MOVB #ATR_WDOG_RESET,ADDATR_CODE
- RESET_MONITOR2: JSR ADD_ATRANS
- RTS
which has the flaw on line 2 and cost the line 4 flag being cleared before even being detect. After change it to following:
- RESET_MONITOR: BRCLR CRGFLG,#LVRF,RESET_MONITOR1 ;check if this is power reset / low voltage reset
- BCLR CRGFLG,#LOW(~LVRF) ;clear the flag
- ;do something with low voltage reset
- RESET_MONITOR1: BRCLR CRGFLG,#PORF,RESET_MONITOR9
- BCLR CRGFLG,#LOW(~PORF) ;clear the flag
- ;do something with power reset detection
- MOVB #ATR_PWR_RESET,ADDATR_CODE
- BRA RESET_MONITOR2
- RESET_MONITOR9: MOVB #ATR_WDOG_RESET,ADDATR_CODE
- RESET_MONITOR2: JSR ADD_ATRANS
- RTS
everything work as expected. Hope this help.