cancel
Showing results for 
Search instead for 
Did you mean: 

usart printf float

aeolia_amha
Associate II
Posted on May 31, 2010 at 05:25

usart printf float

37 REPLIES 37
aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

How do you set up the date and time by making the computer automatically get the data from its own unix time. This way, there is no need to manually set up the time and the time will be more accurate.

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

I haven't found any sample application using RTC_SetCounter(PC time). Almost all applications let the user input the year, date, time, etc.. manually using the hyperterminal. I found out that Keil support rtl.h and netconfig.h. When I installed Keil, there is no such library that exist. Is this really possible to implement?

When I tried using printf(''%d'',time(0));, the hyperterminal freezes but when I used Visual C, it displayed seconds passed since Jan 1, 1970. Does Keil not support these functions? Any suggested alterantives?

What do you mean by this:

time() on the PC and UNIX share a common view of time. The value of time() on the STM32 will not contain the RTC value unless your library code hosts it that way, personally I'd just read the RTC register directly, and configure it to tick once per second.

Posted on May 17, 2011 at 13:53

You will have to HOST the time() function with RTC_GetCounter() on the STM32, because Keil doesn't have a magic timer hidden anywhere.

Once you have a time value (from RTC_GetCounter()) you can use the library functions localtime(),globaltime(),asctime() and strftime() to decode/display the time, or implement your own.

I recover the initial time setting on my system for a) an NTP server, b) a GPS receiver, or c) the cell network. If you have no such connectivity options, then the user will have to set the time into the RTC, or capture the time on a PC and inject it into your device when the user connects it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

How do you capture the time on a PC and inject it into your device when the user connects it. From what I understand, RTC get counter function only gets the current counter setup by RTC set counter. My problem is making the RTCsetcounter(time(0));, this doesn't work  because I think Keil doesn't have this functions support

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

''then the user will have to set the time into the RTC, or capture the time on a PC and inject it into your device when the user connects it.''

You're right, I used a seperate program and send it to the MCU using USART. The problem is after sending, it displays the time correctly but it states please enter number 0 to 9 after. This statement only happens when the input exceeded that of the max limit

Posted on May 17, 2011 at 13:53

''The problem is after sending,

it

displays the time correctly but

it

states please enter number 0 to 9 after''

What is ''it'' ??

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

the mcu displays the time correctly but states please enter number 0 to 9 after, this happens when the input is not fully correct or out of range

Posted on May 17, 2011 at 13:53

''this happens when the input is not fully correct or out of range''

So there's a bug in your code that makes it incorrectly see the value as, ''not fully correct or out of range''