This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC with external 32.768kHz oscillator on lpc2378

I'm trying to use the RTC on my MCB2300 with Keil IDE. The NXP example is only using the internal clock. My initialization seems to be ok, according to the lpc23xx manual. But I'm facing 2 issues.
First, my code is running only in debug mode. When not in debug mode, it seems that interrupt is never fired. In debug mode (even without breakpoint) interrupt behaviour is great but timing is really slow (1seconde every 4 or 5sec).
I'm powering RTC with PCONP register before initialization, then I set CCR register to use external oscillator. Then I set my interrupt and I
enable my RTC. I don't understand what I'm missing here.
Thanks for any help !

Parents
  • Dear Aurelien
    Shyam here, Do u rememember? that u send me code during my SPI communication.

    here I am sending Whole (RTC initalation ,RTC_ISR) RTC code which is I implemented in my project.

    void InitRTC(void)
    {
    //  Enable power for RTC
            PCONP |= 0x200;
    //  CTC reset and select RTC clock from 32 Khz.oscillator
            RTC_CCR = 0x12;
    //  Clear RTC interrupt register
            RTC_ILR = 0xFF;
    //  Dasable all the alrams.
            RTC_AMR = 0xFF;
    //  Enable only second count interrupt.
            RTC_CIIR = 0x01;            // minute
    //  Disable all subsecond interrupts.
            RTC_CISS = 0;
    //  Enable RTC
            RTC_CCR = 0x11;
            return;
    }
    void Set_RTC(RTC Time)
    {
            RTC_CCR &= 0xFE;
            RTC_SEC = Time.RTC_Sec;
    //  Minute value [0-59]
            RTC_MIN = Time.RTC_Min;
    //  Hour value [0-23]
            RTC_HOUR = Time.RTC_Hour;
    //  Day of week value [0-6]
            RTC_DOW = Time.RTC_Wday;
    //  Day of month value [1-31]
            RTC_DOM = Time.RTC_Mday;
    //  Month value [1-12]
            RTC_MONTH = Time.RTC_Mon;
    //  Year value
            RTC_YEAR = Time.RTC_Year;
    //  Day of year value [1-365]
            RTC_DOY = Time.RTC_Yday;
            RTC_CCR |= 0x01;
            return;
    }
    RTC Read_RTC(void)
    {
            RTC Local_time;
            Local_time.RTC_Sec = ((RTC_CTIME0 & 0x0000003F)>>0);
            rtcdata = ((RTC_CTIME0 & 0x0000003F)>>0);
    //  Minute value [0-59]
            Local_time.RTC_Min = ((RTC_CTIME0 & 0x00003F00)>>8);
    //  Hour value [0-23]
            Local_time.RTC_Hour = ((RTC_CTIME0 & 0x001F0000)>>16);
    //  Day of week value [0-6]
            Local_time.RTC_Wday = ((RTC_CTIME0 & 0x07000000)>>24) ;
    //  Day of month value [1-31]
            Local_time.RTC_Mday = ((RTC_CTIME1 & 0x0000001F)>>0);
    //  Month value [1-12]
            Local_time.RTC_Mon = ((RTC_CTIME1 & 0x0000FF00)>>8);
    //  Year value
            Local_time.RTC_Year = ((RTC_CTIME1 & 0x0FFF0000)>>16);
    //  Day of year value [1-365]
            Local_time.RTC_Yday = RTC_DOY;
            RTC_CCR |= 0x01;
            return (Local_time);
    }
    void RTC_ISR (void) __irq
    {
    
            if (RTC_ILR &=0x00000001)
            {
    
                 Count++;
            }
            RTC_ILR = 0x00000001;
            VICVectAddr = 0x00000000;
    }
    


    if any problem give me meg.

    Thanks
    Shyam T.

Reply
  • Dear Aurelien
    Shyam here, Do u rememember? that u send me code during my SPI communication.

    here I am sending Whole (RTC initalation ,RTC_ISR) RTC code which is I implemented in my project.

    void InitRTC(void)
    {
    //  Enable power for RTC
            PCONP |= 0x200;
    //  CTC reset and select RTC clock from 32 Khz.oscillator
            RTC_CCR = 0x12;
    //  Clear RTC interrupt register
            RTC_ILR = 0xFF;
    //  Dasable all the alrams.
            RTC_AMR = 0xFF;
    //  Enable only second count interrupt.
            RTC_CIIR = 0x01;            // minute
    //  Disable all subsecond interrupts.
            RTC_CISS = 0;
    //  Enable RTC
            RTC_CCR = 0x11;
            return;
    }
    void Set_RTC(RTC Time)
    {
            RTC_CCR &= 0xFE;
            RTC_SEC = Time.RTC_Sec;
    //  Minute value [0-59]
            RTC_MIN = Time.RTC_Min;
    //  Hour value [0-23]
            RTC_HOUR = Time.RTC_Hour;
    //  Day of week value [0-6]
            RTC_DOW = Time.RTC_Wday;
    //  Day of month value [1-31]
            RTC_DOM = Time.RTC_Mday;
    //  Month value [1-12]
            RTC_MONTH = Time.RTC_Mon;
    //  Year value
            RTC_YEAR = Time.RTC_Year;
    //  Day of year value [1-365]
            RTC_DOY = Time.RTC_Yday;
            RTC_CCR |= 0x01;
            return;
    }
    RTC Read_RTC(void)
    {
            RTC Local_time;
            Local_time.RTC_Sec = ((RTC_CTIME0 & 0x0000003F)>>0);
            rtcdata = ((RTC_CTIME0 & 0x0000003F)>>0);
    //  Minute value [0-59]
            Local_time.RTC_Min = ((RTC_CTIME0 & 0x00003F00)>>8);
    //  Hour value [0-23]
            Local_time.RTC_Hour = ((RTC_CTIME0 & 0x001F0000)>>16);
    //  Day of week value [0-6]
            Local_time.RTC_Wday = ((RTC_CTIME0 & 0x07000000)>>24) ;
    //  Day of month value [1-31]
            Local_time.RTC_Mday = ((RTC_CTIME1 & 0x0000001F)>>0);
    //  Month value [1-12]
            Local_time.RTC_Mon = ((RTC_CTIME1 & 0x0000FF00)>>8);
    //  Year value
            Local_time.RTC_Year = ((RTC_CTIME1 & 0x0FFF0000)>>16);
    //  Day of year value [1-365]
            Local_time.RTC_Yday = RTC_DOY;
            RTC_CCR |= 0x01;
            return (Local_time);
    }
    void RTC_ISR (void) __irq
    {
    
            if (RTC_ILR &=0x00000001)
            {
    
                 Count++;
            }
            RTC_ILR = 0x00000001;
            VICVectAddr = 0x00000000;
    }
    


    if any problem give me meg.

    Thanks
    Shyam T.

Children