Using RTC DS3231
-
Hi, guys. i need your help. i'm using a RTC DS3231 and i have this problem:
I'm having this problem because of the least significant bit overflow?
what kind of function could I apply to fix this problem?
(00h address of seconds)I would like to ream from 0-59s in integer. Thank you for your supp!
-
'\t' is the same code as '\x09', see https://theasciicode.com.ar/ascii-control-characters/horizontal-tab-ascii-code-9.html
-
@Lucas_Vieira @Eric73 Actually it should (could) be:
sec = (segundos[0] >> 4) * 10 + (segundos[0] & 0x0f)
or
sec = (segundos[0] // 16) * 10 + (segundos[0] & 0x0f)
The conversion to seg is not needed, since array access to a single bytearray element returns an integer.
-
So, your trouble is second RTC register is in BCD format.
Something like this in line 18sec=(seg&0xF0)*10+seg&0x0F print(sec)
will give you the correct int value