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.
Setting day of week in the RTC can both disable the battery and set the wrong day
Re: Setting day of week in the RTC can both disable the battery and set the wrong day
Thank you. I've reported this on the ROM Repo. You can track it here:
https://github.com/X16Community/x16-rom/issues/249
https://github.com/X16Community/x16-rom/issues/249
Re: Setting day of week in the RTC can both disable the battery and set the wrong day
I should mention this as well, it's not a bug, but a documentation error.
The docs say the range of the dayofweek value stored in the RTC is 0 to 6, but it's not, it's 1 to 7. The way the RTC works is at midnight it rolls some of it's internal values over, and if the dayofweek is 7 at that time, it's rolled over to 1.
The end user is free to decide what that number means... the "week" can start on Sunday as 1, or Monday... or whatever.
The docs say the range of the dayofweek value stored in the RTC is 0 to 6, but it's not, it's 1 to 7. The way the RTC works is at midnight it rolls some of it's internal values over, and if the dayofweek is 7 at that time, it's rolled over to 1.
The end user is free to decide what that number means... the "week" can start on Sunday as 1, or Monday... or whatever.
Re: Setting day of week in the RTC can both disable the battery and set the wrong day
Come to think of it, I remember an issue with that somewhere else, too.
Do you know which file this is documented in? I can make that change.
Do you know which file this is documented in? I can make that change.
Re: Setting day of week in the RTC can both disable the battery and set the wrong day
It's in the KERNAL section, under "Clock" It's detailing the fields for the "clock_set_data_time" call. It's the last line in the block. The other data look correct, things like day and month properly start at 1, but day of week starts at 0.