Hi XJC,
I am glad that it works now.
The problem is that the COP do not cause any watchdog interrupt and CopInterrupt() isn’t an interrupt routine (ISR).
When COP is not triggered properly, it will reset MCU. If COP is detected as reset source, vector at address 0xFFFA will be fetched. This vector points to your CopInterrupt() routine.
Similar is valid also for CM reset (vector at 0xFFFC).
POR/External/Illegal Address resets will fetch reset vector at address 0xFFFE.
So, the CopInterrupt() routine is executed as first code after MCU reset (while the stack is not initialized yet) and RTI instruction at end of routine doesn’t have sense (there isn’t any context which might be restored). The CopInterrupt() (CMInterrupt()) routine must end by jump into some code. For example:
asm jmp _Startup;
If you do not want different behavior/code for POR/CM/COP resets, you may define _Startup() routine for all three vectors inside prm file. For example:
VECTOR 0 _Startup //Power On, External, Illegal Address resets
VECTOR 1 _Startup //Clock Monitor reset
VECTOR 2 _Startup //COP Watchdog reset
In that case you don’t need to define CopInterrupt()/CMInterrupt() routines.
I hope it helps you.
Have a great day,
Radek
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------