mpc5604b RTC interrupts

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mpc5604b RTC interrupts

1,387 Views
licanconstantin
Contributor I

Hi. I try to write a code that toggles on and off the leds on the bord using a rtc interrupt:

-first led toggles at every 100 ms

-second led toggles at every 1 second

-third led toggles at every 1 minute

-forth led toggles at every 1 h.

Can anyone tell my what I did wrong? It doesn't enter in the interrupt and doesn't sets the flag(sometimes sets the flag but it still doesn't enter in the interrupt routine).

 

This is my code:

 

void intrerupere()

{

    milisec++;

    if(milisec==100)

    {

        if(SIU.GPDO[68].R == 0)

        {  

            SIU.GPDO[68].R = 1;

            sec++;

        }

        else

        {

            SIU.GPDO[68].R = 0;

            sec++;

        }

        milisec=0;

    }  

    if(sec == 10)

    {

        if(SIU.GPDO[69].R == 0)

        {

            SIU.GPDO[69].R = 1;

            min++;

        }

        else

        {      

            SIU.GPDO[69].R = 0;

            min++;

        }

        sec=0;

    }

    if (min == 60)

    {

        if(SIU.GPDO[70].R == 0)

        {      

            SIU.GPDO[70].R = 1;

            h++;

        }

        else

        {

            SIU.GPDO[70].R = 0;

            h++;

        }

        min=0;

    }

    if (h == 60)

    {

        if(SIU.GPDO[71].R == 0)

        {

            SIU.GPDO[71].R = 1;  

        }

        else

        {              

            SIU.GPDO[71].R = 0;

        }  

        h=0;  

    }  

    RTC.RTCS.B.RTCF=1;

}

 

void init_rtc(void)

{

    RTC.RTCC.B.CNTEN=0;  

    RTC.RTCC.B.RTCIE=1;

    RTC.RTCC.B.FRZEN=0;

    RTC.RTCC.B.ROVREN=0;

    RTC.RTCC.B.RTCVAL=0x64;

    RTC.RTCC.B.APIEN=0;

    RTC.RTCC.B.APIIE=0;

    RTC.RTCC.B.CLKSEL=2; //16 MHz, 1 ms resolution

    RTC.RTCC.B.DIV512EN=1;

    RTC.RTCC.B.DIV32EN=1;

    RTC.RTCC.B.CNTEN=1;

  

    RTC.RTCS.B.RTCF=1;

}

 

void main (void)

{  

 

  EXCEP_InitExceptionHandlers();  

  INTC_InitINTCInterrupts();

  initModesAndClock(); /* Initialize mode entries and system clock */

  initPeriClkGen();  /* Initialize peripheral clock generation for DSPIs */

  disableWatchdog(); /* Disable watchdog */

  INTC_InstallINTCInterruptHandler(&intrerupere,60,15);

  init_rtc();

 

  SIU.PCR[68].R=0x0200;

  SIU.PCR[69].R=0x0200;

  SIU.PCR[70].R=0x0200;

  SIU.PCR[71].R=0x0200;

 

  INTC.CPR.B.PRI=0;

  asm(" wrteei 1");

  while (1)

  {

      ;

  }  /* Wait forever */  

}


Thanks!

Labels (1)
Tags (3)
0 Kudos
1 Reply

618 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Be aware that RTC is not reloaded automatically after timeout. Once the interrupt flag is set, it is necessary to clear it and reload new value to define next timeout. Otherwise it will take a lot of time until flag is set again.

You can find working example in AN2865. C file is attached here.

Initialization of RTC:

  1. RTC.RTCC.R = 0x00000000;    /* Clear CNTEN to reset RTC (counter) */
  2. RTC.RTCC.R = 0xA01B1000;    /* CLKSEL=SIRC (div. by 4), FRZEN=CNTEN=1, RTCVAL=27  */

Then it waits for flag:

while (RTC.RTCS.B.RTCF == 0) {} /* Wait for RTC timeout */

And reload RTC after that:

  1. RTC.RTCC.R = 0x00000000;  /* Clear CNTEN to reset RTC & enable reloading RTCVAL */
  2. RTC.RTCC.R = 0xA0031000;  /* CLKSEL=SIRC div. by 4, FRZEN=CNTEN=1, RTCVAL=3  */
  3. RTC.RTCS.R = 0x20000000;  /* Clear RTC flag */

Then I can see you have used wrong vector number. It is 38 for RTC, not 60.

And the last thing, do not call these functions in main:

EXCEP_InitExceptionHandlers();

INTC_InitINTCInterrupts();

They are called in startup files.

Lukas

0 Kudos