Hi Daehyeon,
The problem is in the place where you execute asm STOP; command.
For successful wake-up, the appropriate interrupt must be enabled and if this interrupt is I-bit maskable, also I-bit must be cleared prior enter stop mode.
The port L interrupt is I-bit maskable interrupt and you correctly used EnableInterrupts; in the main loop for enabling interrupts.
When a timer interrupt occurs, the I-bit is set for preventing another interrupt. The I-bit is automatically cleared by last instruction (RTI) in interrupt routine (except cases where interrupt routine continues by next interrupt routine).
Since, you call asm STOP; inside the interrupt routine, the I-bit maskable interrupts are disabled during stop mode and you cannot wake-up MCU by port L interrupt event (the MCU may be wake-up by reset or any non-maskable interrupt like XIRQ).
So, you have two basic option where I recommend rather the first one:
1. You should just set some flag instead asm STOP; command in TIM_OutputCompare_ISR() ISR and periodically check that flag in the main loop.
For example:
Unsigned char go_stop = 0;
void interrupt 12 TIM_OutputCompare_ISR(void)
{
go_stop = 1;
}
void main(void)
{
for(;;)
{
If (go_stop)
{
asm STOP;
go_stop = 0;
}
}
}
2. You may use interrupt nesting. When you clear I-bit inside the interrupt routine, the interrupt routine can be interrupted by an interrupt request with a higher priority. So, you should place EnableInterrupts; prior asm STOP command; and configure port L interrupt for a higher priority than TC0 interrupt.
For example:
void interrupt 12 TIM_OutputCompare_ISR(void)
{
EnableInterrupts;
asm STOP;
}
void main(void)
{
INT_CFADDR = 0x70;
INT_CFDATA3_PRIOLVL = 0x01;
INT_CFADDR = 0x30;
INT_CFDATA0_PRIOLVL = 0x02;
}
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!
-----------------------------------------------------------------------------------------------------------------------