# Setting Real Time Clock RTC

**URL:** <https://forums.digi.com/t/setting-real-time-clock-rtc/10027>\
**Category:** Rabbit\
**Created:** [January 15, 2008, 11:07am UTC](https://forums.digi.com/t/setting-real-time-clock-rtc/10027 "2008-01-15T11:07:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickmercury](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@nickmercury](https://forums.digi.com/u/nickmercury)\
**Post date:** [January 15, 2008, 11:07am UTC](https://forums.digi.com/t/setting-real-time-clock-rtc/10027/1 "2008-01-15T11:07:16Z")

</div>

Hi,

I’m using a RCM3700 with my own LCD module, which is working fine.  
I’m send new RTC clock data via serial comms to the rabbit. This is in the  
form of seconds since 01/01/1980, then using the “write\_rtc” function to set the time.

But the RTC doesn’t update until I reset the power. When I reset the power the date and time is correct to the data I sent down the comms. Surely there was way of updating the RTC without the reset.

// my code example  
temp\_long = 0;  
char\_ptr = (unsigned char\*)&temp\_long;  
// rx\_buf contains serial comms data  
\*char\_ptr++ = rx\_buf[2];  
\*char\_ptr++ = rx\_buf[3];  
\*char\_ptr++ = rx\_buf[4];  
\*char\_ptr = rx\_buf[5];  
// now write to RTC  
write\_rtc(temp\_long);

Thanks

Nick Price  
England

---

<div class="post-metadata">

**Author:** ![nickmercury](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@nickmercury](https://forums.digi.com/u/nickmercury)\
**Post date:** [January 15, 2008, 12:09pm UTC](https://forums.digi.com/t/setting-real-time-clock-rtc/10027/2 "2008-01-15T12:09:30Z")

</div>

Hi,

found the answer myself. need to update the SEC\_TIMER. But need to make  
sure no costate running. This seems to work ok, anyone disagree???

Below is my background loop.

while (1)  
{  
if( clock\_update\_pending == B\_TRUE )  
{  
// need to pause the co-states  
CoPause(&cd1);  
CoPause(&cd2);  
while(isCoRunning(&cd1));  
while(isCoRunning(&cd2));  
// costate not running  
// now write to RTC  
write\_rtc(new\_rtc);  
SEC\_TIMER = new\_rtc;  
clock\_update\_pending = B\_FALSE;  
// now re-enable costates  
CoResume(&cd1);  
CoResume(&cd2);  
}  
handle\_uart\_message();  
loophead();  
costate cd1 always\_on  
{  
tm\_rd(&rtc);  
// convert to seconds  
rtc\_secs = mktime(&rtc);  
print\_time(rtc\_secs);  
LCD\_display\_refresh();  
serFputc (170);  
waitfor(DelayMs(1000));  
}  
costate cd2 always\_on  
{  
waitfordone c = cof\_serFgetc();  
frame\_received\_data(c);  
}  
}
