Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4 Forum Discussions

MikeAustin
Level 4
Level 4
25 replies posted 25 sign-ins 10 replies posted

Is there an API that will convert the CURRENT_TIME and LOCAL_TIME_INFO received from a CTS into UTC time?

Cheers,

Mike

0 Likes
1 Solution

Hi,

Attached is the code I wrote for an IoT PoC Project a few years ago.

In mcu_time.c line 31, I wrote

uint32_t utc_offset = 9 * 60 * 60 ;

as JST is +9.

moto

 

View solution in original post

0 Likes
6 Replies
MotooTanaka
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi,

I wonder if the following sample code can be some help?

https://community.cypress.com/t5/Code-Examples/CY8CKIT-044-RTC-with-32kHz-Crystal-Sample/td-p/95862

moto

P.S. In RTC.h there are functions, like
uint64 RTC_ConstructUnixAlarmTime(const RTC_DATE_TIME* alarmTime, uint8 alarmCfgMask);
uint64 RTC_GetDstUnixTime(const RTC_DST_TIME* dstTime);

 

0 Likes

Hi,

Attached is the code I wrote for an IoT PoC Project a few years ago.

In mcu_time.c line 31, I wrote

uint32_t utc_offset = 9 * 60 * 60 ;

as JST is +9.

moto

 

0 Likes
MikeAustin
Level 4
Level 4
25 replies posted 25 sign-ins 10 replies posted

Hi Moto,

Thanks for the reply.  Unfortunately that's more dealing with converting time from "standard" format to BCD, so it can be stored in the RTC.  I've managed to get that conversion working so I can write and read from my RTC.

I'm reading the local time off a Current Time Service (my iPhone), but want to store it in the RTC as UTC time. 

Seems simple enough to add/delete the time zone and DST offsets, but of course if (as is my case here in Australia) your local time is on the next day compared to UTC when you do the time read/conversion, you potentially need to make adjustments to day of the week, day of the month, month and year!  I was hoping someone had done the hard work of writing a suitable function to achieve this already 🙂

Cheers,

Mike

0 Likes

Hi, Mike-san,

I'm just curious, but have you taken a look at my mcu_time.c?

I though that I tried the "hard work" in ts2time() and ts2tm().

moto

0 Likes

Hi Moto,

My apologies - I didn't see your second post.  Had a quick look over those two functions, and I think ts2time() may have given me a few ideas on how to make my Convert2UTC() function a bit neater!

Arigatoo gozaimasu!

Mike

Hi Mike-san,

Arigatoo gozaimasu!

Dou Itashimasite!

moto

0 Likes