Thank you very much, Nominal Animal!
Sorry for taking so much time to answer, but I've been struggling with it... Seems like the syntax in the DSO's linux is a bit different from what you proposed, it must be a simplified and/or non standard one. Here is what its finally working:
#!/bin/sh
I2CGET="/bin/i2cget -y 0 0x68"
DATE="/bin/date"
Decade="0x20"
Year=$($I2CGET 0x06)
Month=$($I2CGET 0x05)
Day=$($I2CGET 0x04)
Hour=$($I2CGET 0x02)
Minute=$($I2CGET 0x01)
Second=$($I2CGET 0x00)
$DATE -u --set "$(printf '%02x%02x%02x%02x%02x%02x.%02x' $Decade $Year $Month $Day $Hour $Minute $Second)"
#
You were proposing MMDDHHmmYYYY.ss for the "date" argument, and according to the help in the command it should work:
# date -?
date: invalid option -- '?'
BusyBox v1.26.2 (2020-06-08 11:06:44 CST) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string
SPEC='date' (default) for date only,
'hours', 'minutes', or 'seconds' for date and
time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats:
hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]
'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
But, although if you issue the command manually it's OK, when doing it from the script it only seems to accept YYYYMMDDhhmm.ss
Also, I had to find a workaround for another problem I found when using your script:
# Year=$[2000 + $($I2CGET 0x06)]
/bin/sh: +: not found
#
Apparently, it doesn't like the "+" sign in the definition... I don't know if all these issues are my fault for not understanding well the environment or if they were due to particularities of this specific linux implementation, or a mix of both
Finally, I had to use %02x in the format instead of %02d; this is because, although the registers are i2cget like hexadecimal, in fact, according to the datasheet,
"The contents of the time and calendar registers are in the binary-coded decimal (BCD) format", so when i2cget returns 0x22 for minutes it doesn't mean the actual minutes are 34, but 22.
After I got a working script, now I had to get it running at boot time. The tutorials I found on internet (update-rc.d
scriptname defaults after copying the script in /etc/init.d) didn't work, as update-rc is not a valid command here... Finally, studying
David's example and the existing scripts in /etc/init.d, I could make it work creating a script named "RTC_Script" with the code at the beginning of this post in /usr/bin, and another script in /etc/init.d calling it with the following content:
#!/bin/sh
/usr/bin/RTC_script &
And now finally the scope gets the correct time and date from the RTC module after booting!!
Thanks a lot to all of you for your help!
Now I'll try to do the opposite: setting the RTC module from the USB pen drive in case it lost time, probably with a similar approach as David's in the aforementioned post (disconnecting it from the scope and setting it with an Arduino doesn't seem an easy method...)