{"id":16064682,"url":"https://github.com/eldruin/ds323x-rs","last_synced_at":"2025-07-09T12:42:33.550Z","repository":{"id":54380609,"uuid":"155054415","full_name":"eldruin/ds323x-rs","owner":"eldruin","description":"Platform-agnostic Rust driver for the DS3231, DS3232 and DS3234 extremely accurate real-time clocks (RTC).","archived":false,"fork":false,"pushed_at":"2025-01-02T08:26:31.000Z","size":202,"stargazers_count":17,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-10T10:46:00.819Z","etag":null,"topics":["clock","embedded","embedded-hal","embedded-hal-driver","i2c","no-std","real-time","rtc","rust","spi"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eldruin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-28T09:29:41.000Z","updated_at":"2025-04-14T02:55:17.000Z","dependencies_parsed_at":"2024-10-27T10:12:29.570Z","dependency_job_id":"520e61da-a509-43aa-b1a1-f488ae5c6d28","html_url":"https://github.com/eldruin/ds323x-rs","commit_stats":{"total_commits":182,"total_committers":5,"mean_commits":36.4,"dds":"0.038461538461538436","last_synced_commit":"fa431720876e0a8b47b32940fdeda91eba322cfc"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldruin%2Fds323x-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldruin%2Fds323x-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldruin%2Fds323x-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldruin%2Fds323x-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eldruin","download_url":"https://codeload.github.com/eldruin/ds323x-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253668049,"owners_count":21944967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clock","embedded","embedded-hal","embedded-hal-driver","i2c","no-std","real-time","rtc","rust","spi"],"created_at":"2024-10-09T05:09:07.090Z","updated_at":"2025-05-12T03:31:39.153Z","avatar_url":"https://github.com/eldruin.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust DS3231, DS3232 and DS3234 Extremely Accurate Real-Time Clock Driver\n\n[![crates.io](https://img.shields.io/crates/v/ds323x.svg)](https://crates.io/crates/ds323x)\n[![Docs](https://docs.rs/ds323x/badge.svg)](https://docs.rs/ds323x)\n![MSRV](https://img.shields.io/badge/rustc-1.75+-blue.svg)\n[![Build Status](https://github.com/eldruin/ds323x-rs/workflows/Build/badge.svg)](https://github.com/eldruin/ds323x-rs/actions?query=workflow%3ABuild)\n[![Coverage Status](https://coveralls.io/repos/eldruin/ds323x-rs/badge.svg?branch=master)](https://coveralls.io/r/eldruin/ds323x-rs?branch=master)\n\nThis is a platform agnostic Rust driver for the DS3231, DS3232 and DS3234\nextremely accurate real-time clocks, based on the [`embedded-hal`] traits.\n\n[`embedded-hal`]: https://github.com/rust-embedded/embedded-hal\n\nThis driver allows you to:\n- Read and set date and time in 12-hour and 24-hour format. See: `datetime`.\n- Read and set date and time individual elements. For example, see: `year`.\n- Enable and disable the real-time clock. See: `enable`.\n- Read the busy status. See `busy`.\n- Read whether the oscillator is or has been stopped. See `has_been_stopped`.\n- Clear the has-been-stopped flag. See `clear_has_been_stopped_flag`.\n- Set and read the aging offset. See `set_aging_offset`.\n- Select the function of the INT/SQW output pin. See `use_int_sqw_output_as_interrupt`.\n- Alarms:\n    - Set alarms 1 and 2 with several matching policies. See `set_alarm1_day`.\n    - Set alarms 1 and 2 for a time. See `set_alarm1_hms`.\n    - Read whether alarms 1 or 2 have matched. See `has_alarm1_matched`.\n    - Clear flag indicating that alarms 1 or 2 have matched. See `clear_alarm1_matched_flag`.\n    - Enable and disable alarms 1 and 2 interrupt generation. See `enable_alarm1_interrupts`.\n- Wave generation:\n    - Enable and disable the square-wave generation. See `enable_square_wave`.\n    - Select the square-wave frequency. See `set_square_wave_frequency`.\n    - Enable and disable the 32kHz output. See `enable_32khz_output`.\n    - Enable and disable the 32kHz output when battery powered. See `enable_32khz_output_on_battery`.\n- Temperature conversion:\n    - Read the temperature. See `temperature`.\n    - Force a temperature conversion and time compensation. See `convert_temperature`.\n    - Set the temperature conversion rate. See `set_temperature_conversion_rate`.\n    - Enable and disable the temperature conversions when battery-powered. See `enable_temperature_conversions_on_battery`.\n\n## The devices\n\nThis driver is compatible with the DS3231 and DS3232 I2C devices and the\nDS3234 SPI device.\n\nThese devices are low-cost temperature-compensated crystal oscillator (TCXO)\nwith a very accurate, temperature-compensated, integrated real-time clock\n(RTC) including 236/256 bytes of battery-backed SRAM, depending on the model.\n\n### DS3231 and DS3232 details\n\nThe devices incorporate a battery input, and maintain accurate timekeeping\nwhen main power to the devices is interrupted. The integration of the\ncrystal resonator enhances the long-term accuracy of the devices as well as\nreduces the piece-part count in a manufacturing line.\nThe devices are available in commercial and industrial temperature ranges,\nand are offered in a 16-pin, 300-mil SO package.\n\nThe RTC maintains seconds, minutes, hours, day, date, month, and year\ninformation. The date at the end of the month is automatically adjusted for\nmonths with fewer than 31 days, including corrections for leap year. The\nclock operates in either the 24-hour or 12-hour format with an AM/PM\nindicator. Two programmable time-of-day alarms and a programmable\nsquare-wave output are provided. Address and data are transferred serially\nthrough an I2C bidirectional bus.\n\nA precision temperature-compensated voltage reference and comparator\ncircuit monitors the status of VCC to detect power failures, to provide a\nreset output, and to automatically switch to the backup supply when\nnecessary. Additionally, the RST pin is monitored as a pushbutton\ninput for generating a μP reset.\n\n### DS3234 details\n\nThe DS3234 incorporates a precision, temperature-compensated voltage\nreference and comparator circuit to monitor VCC. When VCC drops below the\npower-fail voltage (VPF), the device asserts the RST output and also\ndisables read and write access to the part when VCC drops below both VPF\nand VBAT. The RST pin is monitored as a pushbutton input for generating a\nμP reset. The device switches to the backup supply input and maintains\naccurate timekeeping when main power to the device is interrupted.\nThe integration of the crystal resonator enhances the long-term accuracy of\nthe device as well as reduces the piece-part count in a manufacturing line.\nThe DS3234 is available in commercial and industrial temperature ranges,\nand is offered in an industry-standard 300-mil, 20-pin SO package.\n\nThe DS3234 also integrates 256 bytes of battery-backed SRAM. In the event\nof main power loss, the contents of the memory are maintained by the power\nsource connected to the V BAT pin. The RTC maintains seconds, minutes,\nhours, day, date, month, and year information. The date at the end of the\nmonth is automatically adjusted for months with fewer than 31 days,\nincluding corrections for leap year. The clock operates in either the\n24-hour or 12-hour format with AM/PM indicator. Two programmable\ntime-of-day alarms and a programmable square-wave output are provided.\nAddress and data are transferred serially by an SPI bidirectional bus.\n\nDatasheets:\n- [DS3231](https://datasheets.maximintegrated.com/en/ds/DS3231.pdf)\n- [DS3232](https://datasheets.maximintegrated.com/en/ds/DS3232.pdf)\n- [DS3234](https://datasheets.maximintegrated.com/en/ds/DS3234.pdf)\n\n## Usage\n\nTo use this driver, import this crate and an `embedded_hal` implementation,\nthen instantiate the appropriate device.\nIn the following example an instance of the device DS3231 will be created.\nOther devices can be created with similar methods like:\n`Ds323x::new_ds3234(...)`.\n\nPlease find additional examples using hardware in this repository: [driver-examples]\n\n[driver-examples]: https://github.com/eldruin/driver-examples\n\n```rust\nuse ds323x::{DateTimeAccess, Ds323x, NaiveDate, Rtcc};\nuse linux_embedded_hal::I2cdev;\n\nfn main() {\n    let dev = I2cdev::new(\"/dev/i2c-1\").unwrap();\n    let mut rtc = Ds323x::new_ds3231(dev);\n    let datetime = NaiveDate::from_ymd_opt(2020, 5, 1)\n        .unwrap()\n        .and_hms_opt(19, 59, 58)\n        .unwrap();\n    rtc.set_datetime(\u0026datetime).unwrap();\n    // do something else...\n    let time = rtc.time().unwrap();\n    println!(\"Time: {}\", time);\n\n    let _dev = rtc.destroy_ds3231();\n}\n```\n\n## Support\n\nFor questions, issues, feature requests like compatibility with other devices and other\nchanges, please file an\n[issue in the github project](https://github.com/eldruin/ds323x-rs/issues).\n\n## Minimum Supported Rust Version (MSRV)\n\nThis crate is guaranteed to compile on stable Rust 1.75 and up. It *might*\ncompile with older versions but that may change in any new patch release.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n   http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or\n   http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contributing\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldruin%2Fds323x-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feldruin%2Fds323x-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldruin%2Fds323x-rs/lists"}