Skip to content

rtc: select 24-hour mode at adoption, and refuse a 12-hour read #51

Closed

Description

@ptr727

ZephCore never selects 24-hour mode on an I2C RTC, and it decodes a 12-hour PM hour as a wrong 24-hour one.

zephcore_rtc_restore() and zephcore_rtc_save() (zephcore/adapters/clock/ZephyrRTCDiscover.c) assume 24-hour mode, and the header says so: "12-hour mode is not decoded". Nothing sets or checks the mode. If other firmware or a tool has left the chip in 12-hour mode:

  • Read. Hours are masked & 0x3F and must be BCD 00-23. In 12-hour mode bit 5 is AM/PM, and bits 4:0 hold 01-12. So PM 1-3 (21h-23h) decode as 21:00-23:00, eight hours ahead, and are accepted. PM 4-12 (24h-32h) fail the range check, so no time is taken. AM hours decode correctly.
  • Write. The save writes 24-hour BCD, which a 12-hour chip reads as a different hour. 15:00 (15h), for example, is an invalid 12-hour value.

Which chips: the RV3028 (Control 2, 10h, bit 1 12_24) and the DS3231/DS3232 (hours register bit 6). Check the PCF8563 and RX8130CE data sheets for whether they have a 12-hour mode at all.

Parity. Zephyr's rtc_rv3028 writes Control 2 = 00h (24h) at init. MeshCore (meshcore-dev/MeshCore#3421, 6033e3e4) reads Status and Control 2 with the time, clears 12_24 when it is set and re-reads, and selects 24h before a write. ZephCore is the odd one out.

Proposed fix. Select 24-hour mode when a chip is adopted, for each chip that has the bit, and refuse a time read while the chip reports 12-hour mode. This is kept separate from liquidraver#103 (the RV3028 A0h year mark), which is upstream as agreed.

Activity

  1. ptr727 commented on Oct 8, 2026

    @ptr727
    OwnerAuthor

    Fixed for the RV3028 by liquidraver#106, merged 2026-10-08. Once the chip is cleanly identified at boot, ZephCore clears 12_24, and it takes no time from the chip if that clear fails. The DS3231/DS3232 case remains, tracked in #34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions