Page 1 of 1

FT900 RTC Interrupt - Help needed

Posted: 25 Jun 2018 11:37
by PPK
Hi,

I have the RTC oscillator ticking over. So the RTC_start, RTC_Read, RTC_Write and RTC_Stop seem to be working.
It seems to be adding about 36 counts per second. Is this correct? This seems to be a bit of a strange value. How do you set a divisor for this?

Ultimately, what I would like to do is have a RTC interrupt that happens every second.

I have the RTC interrupt vector (void RTC_ISR() iv IVT_RTC_IRQ ics ICS_AUTO ) pointing to my RTC Time updating code but basically the system just locks up when I enable the interrupt
Using RTC_IEN_bit = 1 ;
RTC_CCR looks like 0x00 00 00 05.

Do I need to do something at the end of the interrupt ie clear a flag etc?

Thanks,
Neil.

Note tByte = unsigned char ;

Code: Select all

tByte rtc_start(void)
{
//    RTC->RTC_CCR |= MASK_RTC_CCR_EN;
    RTC_EN_bit = 1 ;
    return 0;
}


tByte rtc_stop(void)
{
//    RTC->RTC_CCR &= ~MASK_RTC_CCR_EN;
    RTC_EN_bit = 0 ;
    return 0;
}


tByte rtc_write(unsigned long val)
{
//    RTC->RTC_CLR = val;
    RTC_CLR = val;
    return 0;
}

tByte rtc_read(unsigned long *val)
{
//    *val = RTC->RTC_CCVR;
    *val = RTC_CCVR;
    return 0;
}


tByte rtc_init(rtc_wrap_t wrap)
{
    tByte iRet = 0;
    if (wrap > rtc_wrap_enabled)
    {
        iRet = -1;
    }

    if (iRet == 0)
    {
        rtc_write(0UL);

        switch(wrap)
        {
            case rtc_wrap_disabled: RTC_CCR |= RTC_WEN; break ;
            case rtc_wrap_enabled: RTC_CCR &= ~RTC_WEN; break ;
            default: break;
        }
    }

    RTC_IEN_bit = 1 ;
    return iRet;
}


void RTC_ISR() iv IVT_RTC_IRQ ics ICS_AUTO {
  tbyte a ;
  if (++RTClock.second==60)        //keep track of time, date, month, and year
  {
    RTClock.second=0;
    if (++RTClock.minute==60)
    {
      RTClock.minute=0;
      if (++RTClock.hour==24)
      {
        RTClock.hour=0;
        if (++RTClock.dow==7) RTClock.dow= SUN ;
        if (++RTClock.date==32)
        {

Etc etc

Re: FT900 RTC Interrupt - Help needed

Posted: 28 Jun 2018 08:12
by petar.suknjaja
Hi,
Yes, you need to clear the interrupt flag or you won't be able to enter that interrupt routine again.
You can check out this link, its an Interrupt Example for FT900x:
http://download.mikroe.com/documents/co ... rrupts.htm

If you need additional help regarding this, please post the zipped project so we could review it,.

Kind regards,
Petar