2014-01-11 01:28 PM
Guys,
Why suddenly sprintf doesn't work ? It was working yesterday, I shut down the power supply now, it's not giving me a good response code : uint32_t /*Tmp,*/THH,TMM,TSS,WEEKDAY,DATE,MONTH,YEAR; unsigned char date[10],day[10],month[10],year[10],hour[10],min[10],sec[10]; struct tm *utcTimeSnapshot; Tmp = RTC_GetCounter(); TSS = utcTimeSnapshot->tm_sec; sprintf(sec,''%02d'',TSS); lcd_string(sec); If I commented out sprintf, now it's running properly, I can see RTC on USART, but if I use sprintf, it's running 2 seconds and freeze......any ideas ? Thanks #learn-to-code2014-02-18 08:25 PM
2014-02-18 08:31 PM
1.
if
(button1)
2.
{
3.
time_struct.tm_year++;
4.
sprintf
(year,
''%.2d''
,time_struct.tm_year);
5.
lcd_string(year);
6.
}
2014-02-19 01:16 AM
> How can I change RTC counter ( year ) part ?
As per my many examples before in this thread that you continually choose to ignore and then ask a completely different question because maybe you don't like the answer because it's not as easy to understand as you might like.Did you read my post from the 13th January that showed how to use a time structure to set the RTC counter (set_time function)? With this you just manipulate the structure to what you need ans use it to set the epoch time (simples).Or how about just setting up the RTC hardware to tick once per second and observing that with a debugger (or UART debug). Until that much is confirmed working you are just wasting your time and everyone else's time trying to help you.2014-02-19 01:33 AM
> How can I change RTC counter ( year ) part ?
You stated in another thread that you were using STM32103. The STM32103 does not have a ''year'' part to the RTC. It has one 32 bit counter for the RTC. That's all, no weekdays, no days, no months, no years etc. or any other calendar nonsense - just a big seconds counter. But this is all good because time is easy to compare and manipulate when it is a number and all the other items can easily be calculated from the seconds count when needed. I like time as a number. The standard to use is number of seconds since midnight 1st Jan 1970 - this is called the epoch (you could use another starting point but use this one and keep it simple at lest for now). If you use epoch time you can then make use of all the nice functions from time.h so all the hard work is done for you. Do you get this concept?2014-02-19 01:33 AM
> How can I change RTC counter ( year ) part ?
You stated in another thread that you were using STM32103. The STM32103 does not have a ''year'' part to the RTC. It has one 32 bit counter for the RTC. That's all, no weekdays, no days, no months, no years etc. or any other calendar nonsense - just a big seconds counter. But this is all good because time is easy to compare and manipulate when it is a number and all the other items can easily be calculated from the seconds count when needed. I like time as a number. The standard to use is number of seconds since midnight 1st Jan 1970 - this is called the epoch (you could use another starting point but use this one and keep it simple at lest for now). If you use epoch time you can then make use of all the nice functions from time.h so all the hard work is done for you. Do you get this concept?2014-02-20 04:33 PM
I used my own board with STM32F107VCT on it...
Ok I'll try to understand the simplest thing, it's different with DS1307 I used before....2014-02-23 12:02 AM
I have made
if
(button2)
{
lcd_cmd(LCD_CLEAR);
lcd_string(
''SET TIME SELECTED''
);
init_RTCTime();
/*====LED-ON=======*/
GPIO_SetBits(GPIOB , GPIO_Pin_5);
vTaskDelay(1500);
/*====LED-OFF=======*/
GPIO_ResetBits(GPIOB , GPIO_Pin_5);
vTaskDelay(1500);
/*====LED-ON=======*/
GPIO_SetBits(GPIOB , GPIO_Pin_6);
vTaskDelay(1500);
/*====LED-OFF=======*/
GPIO_ResetBits(GPIOB , GPIO_Pin_6);
vTaskDelay(1500);
}
static
void
set_time(
struct
tm
*time_struct_ptr)
{
time_t
seconds_from_epoch =
mktime
(time_struct_ptr);
RTC_SetCounter(seconds_from_epoch);
}
init_RTCTime()
{
struct
tm
time_struct;
struct
tm
*system_time_struct_ptr;
time_t
number_of_seconds_from_epoch;
// Setup the time to 12-Jan-2014 15:20:30
time_struct.tm_sec = 30;
// seconds after the minute 0 - 61 (60 and 61 only used for leap seconds))
time_struct.tm_min = 20;
// minutes after the hour 0 - 59
time_struct.tm_hour = 15;
// hours since midnight 0 - 23
time_struct.tm_mday = 14;
// day of the month 1 - 31
time_struct.tm_mon = 0;
// months since January 0 - 11
time_struct.tm_year = 2014 - 1900;
// years since 1900
time_struct.tm_isdst = 0;
// Daylight Saving Time flag
time_struct.tm_wday = 2;
//Tuesday
set_time(&time_struct);
// use the struct to set the RTC seconds counter value
//vTaskDelay(5000);
}
The time is not updated after I pressed the button, any ideas ?
I tried to follow the suggestions, it didn't work....it's not the right one yet...
thanks
2014-02-23 01:11 PM
I can't see any see any read of the RTC here or any RTC setup code.
As per my suggestion get the RTC setup to tick at once per second and write some code that observers the RTC counter increment every second. That is the starting point.2014-02-23 03:40 PM
@Trevor:
Or how about just getting the RTC counting seconds as a start. Set the RTC and observe it increment by one every second. That would be a good start. Any examples on doing that ? thanks