Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve SECONDS fields when clearing Clock Halt bit at initialisation (#77354) #77727

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions drivers/rtc/rtc_ds1307.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,23 @@ static int ds1307_init(const struct device *dev)
/* Disable squarewave output */
err = i2c_reg_write_byte_dt(&config->i2c_bus, DS1307_REG_CTRL, 0x00);
if (err < 0) {
LOG_ERR("Error: SQW:%d\n", err);
LOG_ERR("Error: SQW: %d\n", err);
}

/* Make clock halt = 0 */
err = i2c_reg_write_byte_dt(&config->i2c_bus, DS1307_REG_SECONDS, 0x00);
/* Ensure Clock Halt = 0 */
uint8_t reg = 0;

err = i2c_reg_read_byte_dt(&config->i2c_bus, DS1307_REG_SECONDS, &reg);
if (err < 0) {
LOG_ERR("Error: Set clock halt bit:%d\n", err);
LOG_ERR("Error: Read SECONDS/Clock Halt register: %d\n", err);
}
if (reg & ~SECONDS_BITS) {
/* Clock Halt bit is set */
err = i2c_reg_write_byte_dt(&config->i2c_bus, DS1307_REG_SECONDS,
reg & SECONDS_BITS);
if (err < 0) {
LOG_ERR("Error: Clear Clock Halt bit: %d\n", err);
}
}

return 0;
Expand Down
Loading