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 am using the MikroC compiler from Mikro Electronica.
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.
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