cancel
Showing results for 
Search instead for 
Did you mean: 

STM32wl55 getting devicetime millisecond resolution

BISIK.18
Associate II

Hi,

I get GPS time from lorawan network using "DevicetimeReq" command. There is an example how to convert UNIX epoch time to calender time in UM2073 application note. But it uses only second field of system, doesn't benefit from sub-second information. I need better accuracy in my application. Is it possible?

0693W00000Ns9A6QAJ.pngtypedef struct SysTime_s

{

uint32_t Seconds;

int16_t SubSeconds;

}SysTime_t;

2 REPLIES 2
Louis AUDOLY
ST Employee

Hello @BISIK.18​,

When you send a "DevicetimeReq" command, when you have the answer, you will call the SysTimeSet function that will set the time in second and store the subsecond difference between the Unix and RTC time.

Then when you will call the SysTimeLocalTime function, the seconds will change (as the timestamp is in seconds) but not the subseconds that will remain the same.

So when you will call SysTimeGet function, it will calculate the difference in subsecond with the time passed and the time store after the "DevicetimeAns".

I hope it help you

Best regards

Louis

BISIK.18
Associate II

Hi @Louis AUDOLY​ 

Thank you for your answer. But, I am a little bit confused.

When I request the time with "LmHandlerDeviceTimeReq()" command an OnSysTimeUpdate event is triggered. Then, I read the server time with SysTimeGet() function in this event.

I do not use SysTimeSet any time since as far as I know, it is called automatically in the stack level, right?

// Notifies the upper layer that the system time has been updated.

static void OnSysTimeUpdateM(void)

{

SysTime_t UnixEpoch = SysTimeGet();

struct tm localtime2;

UnixEpoch.Seconds-=18; /*removing leap seconds*/

UnixEpoch.Seconds+=3600*2; /*adding 2 hours*/

SysTimeLocalTime(UnixEpoch.Seconds, & localtime2);

 ...

But the my question was that I can get the local time with SysTimeLocalTime(...) function, but it is only in second level, was not milliseconds level.

So, I access millisecond value using SubSeconds of the UnixEpoch structure. Is this the correct way to get millisecond value? (UnixEpoch.SubSeconds)