hello, have problems with my rtc interrupt. i want to test the code in debug mode , but the interrupt service routine is never called..
controller: mc9s08JM60
please can anyone view my code and say if there is something wrong
#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include "MCUinit.h"#ifdef __cplusplusextern "C"#endifvoid MCU_init(void); /* Device initialization function declaration */Bool Tick = FALSE;void main(void) { MCU_init(); /* call Device Initialization */ EnableInterrupts; RTCMOD= 0x00; RTCSC = 0x1F | 0x80; for(;;){ if (Tick == TRUE) { RTCMOD = 0x00;//Re-setting the counter value RTCSC = 0x1F; //Re-enabling the interrupt re-configuring the clock source Tick = FALSE; } }}__interrupt void RTC_ISR(void){ RTCSC = RTCSC | 0x80; Tick = TRUE;}
Solved! Go to Solution.
haha forgot to add the rtc in the "Component Development Environment". it works now thanks for help
The Tick variable must be declared as volatile to protect against dangerous optimization assumptions by the compiler. Some Codewarriors are known to make such optimizations. (I don't remember which MCU and version.)
Hello, and welcome to the forum.
It is probable that the interrupt vector has not been programmed. There are a number of ways to handle this, including an explicit vector table, or as an entry within the PRM file. If neither of these exist in your program, as I suspect, you might use the following method:
__interrupt VectorNumber_Vrtc void RTC_ISR(void){ RTCSC = RTCSC | 0x80; Tick = TRUE;}
Regards,
Mac
added following entry in prm file:
RTC_ISR = READ_WRITE 0xFFC4 TO 0xFFC5;
void interrupt 29 RTC_ISR(void){ RTCSC = RTCSC | 0x80; Tick = TRUE;}
Error:
Faileed writing target adressffc4.
Expected value: 0x1a7d4f00
Actual value: 0xfff2900
What am i doing wrong?
Hello,
Your addition to the PRM file is wrong on several counts, and is totally unnecessary.
By specifying the vector number 29, the linker already knows the actual address of the RTI interrupt vector.
With a modulo value of zero, of course the counter register will remain at zero. Only the prescaler counts in this instance.
Since you are not stopping the RTC module, but require a periodic interrupt at very approximate one second intervals, it is unnecessary to write to the RTC registers within the main loop, once they have been initialised. The following code should suffice.
if (Tick == TRUE) {
Tick = FALSE;
// Do other tasks here
}
Regards,
Mac
yes that with the prm file i know that it was totally wrong thanks for your additional information!
can it be that interrupts are disabled in debug mode?
ok found in debugger configuration the option disable interrupt during stepping. it was checked but still don´t work
it seems that the rtc is not working.. the counter always stays at 0
haha forgot to add the rtc in the "Component Development Environment". it works now thanks for help