cancel
Showing results for 
Search instead for 
Did you mean: 

using fprintf problem

aeolia_amha
Associate II
Posted on June 18, 2010 at 09:15

using fprintf problem

11 REPLIES 11
trevor23
Associate III
Posted on May 17, 2011 at 13:55

Please be more specific. How are you sending this time number? Serial I preaume (UART)? Are you sending this number in ascii or binary format ? If ascii than assuming the number is received into a buffer called buffer that is null terminated the code to set the time would look something like this

RTC_SetCounter( (u32)atol(buffer) );

t1
Associate II
Posted on May 17, 2011 at 13:55

You are receiving a 4 byte number (time_t). You can use this number directly in a function such as gmtime(). This will convert your number into a tm structure. You can use asctime() to convert the tm structure to a string. You can use mktime() to convert the tm structure back to a time_t number.

struct tm {

int tm_sec; // seconds after the minute - [0,59]

int tm_min; // minutes after the hour - [0,59]

int tm_hour; // hours since midnight - [0,23]

int tm_mday; // day of the month - [1,31]

int tm_mon; // months since January - [0,11]

int tm_year; // years since 1900

int tm_wday; // days since Sunday - [0,6]

int tm_yday; // days since January 1 - [0,365]

int tm_isdst; // daylight savings time flag

};