problems with rtc interrupt

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

problems with rtc interrupt

跳至解决方案
1,188 次查看
milchshake
Contributor II

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;}
标签 (1)
0 项奖励
1 解答
834 次查看
milchshake
Contributor II

haha forgot to add the rtc in the "Component Development Environment". it works now thanks for help

在原帖中查看解决方案

0 项奖励
8 回复数
834 次查看
Lundin
Senior Contributor IV

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.)

0 项奖励
834 次查看
bigmac
Specialist III

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

 

0 项奖励
834 次查看
milchshake
Contributor II

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? :smileyindifferent:

0 项奖励
834 次查看
bigmac
Specialist III

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

 

0 项奖励
834 次查看
milchshake
Contributor II

yes that with the prm file i know that it was totally wrong :smileyvery-happy: thanks for your additional information!

0 项奖励
834 次查看
milchshake
Contributor II

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

0 项奖励
834 次查看
milchshake
Contributor II

it seems that the rtc is not working.. the counter always stays at 0

0 项奖励
835 次查看
milchshake
Contributor II

haha forgot to add the rtc in the "Component Development Environment". it works now thanks for help

0 项奖励