Setting Real Time Clock RTC

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

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);
}
}