Setting day of week in the RTC can both disable the battery and set the wrong day
Posted: Sat Dec 30, 2023 9:57 pm
The KERNAL call clock_set_date_time (Which in is the file rtc.s and called rtc_set_date_time) has a bug in the section that sets the day of week. After it sets the battery enable bit with ora $08, it calls i2c_write_byte_as_bcd. In doing so, depending on which day of week you were trying to set, it can set the wrong day of week, and if the bin_to_bcd conversion (In the same file.) resets the battery enable bit in the BCD conversion, it will disable the battery.
Changing the i2c_write_byte_as_bcd call to i2c_write_byte fixes it. It was never needed to do the BCD conversion as the legal data is never over 7, attempting to do the bcd conversion IF the battery enable bit PLUS the day of week results in a BCD value over 9 it will create 2 BCD digits, with the low order one wrong and the battery enable bit not set.
Changing the i2c_write_byte_as_bcd call to i2c_write_byte fixes it. It was never needed to do the BCD conversion as the legal data is never over 7, attempting to do the bcd conversion IF the battery enable bit PLUS the day of week results in a BCD value over 9 it will create 2 BCD digits, with the low order one wrong and the battery enable bit not set.