Trucrux Inc

Testing RTC

To check software date and time #

root@imx8mm-trux-q01:~# date
To set software date and time #
root@imx8mm-trux-q01:~# date --set="20211229 15:35"

output

Wed Dec 29 15:35:00 UTC 2021

To check hardware RTC #

root@imx8mm-trux-q01:~# hwclock
To set the hardware RTC #
root@imx8mm-trux-q01:~# hwclock --systohc --utc

Now reboot the device and check for software and hardware date and time

root@imx8mm-trux-q01:~# date
Wed Dec 29 15:35:28 UTC 2021

root@imx8mm-trux-q01:~# hwclock
2021-12-29 15:35:11.696826+00:00

NOTE: Commonly faced errors for hardware RTC

Even after syncing software and hardware clock, if the hardware clock does not update after reboot and/or returns the following error

root@imx8mm-trux-q01:~# hwclock
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Read the register value 0x37 of RV3028 by using

root@imx8mm-trux-q01:~# i2cget -y -f -a 1 0x52 0x37

If the output of the above command is anything else except 0x94 then use the below command. (Make sure the coin cell is connected)

root@imx8mm-trux-q01:~# i2cset -y -f -a 1 0x52 0x37 0x94

Now set the hardware RTC to sync software and hardware date and time.