Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Platform-agnostic Rust driver for the DS3231, DS3232 and DS3234 extremely accurate real-time clocks (RTC).

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

eldruin/ds323x-rs

Repository files navigation

crates.ioDocsMSRVBuild StatusCoverage Status

This is a platform agnostic Rust driver for the DS3231, DS3232 and DS3234extremely accurate real-time clocks, based on theembedded-hal traits.

This driver allows you to:

  • Read and set date and time in 12-hour and 24-hour format. See:datetime.
  • Read and set date and time individual elements. For example, see:year.
  • Enable and disable the real-time clock. See:enable.
  • Read the busy status. Seebusy.
  • Read whether the oscillator is or has been stopped. Seehas_been_stopped.
  • Clear the has-been-stopped flag. Seeclear_has_been_stopped_flag.
  • Set and read the aging offset. Seeset_aging_offset.
  • Select the function of the INT/SQW output pin. Seeuse_int_sqw_output_as_interrupt.
  • Alarms:
    • Set alarms 1 and 2 with several matching policies. Seeset_alarm1_day.
    • Set alarms 1 and 2 for a time. Seeset_alarm1_hms.
    • Read whether alarms 1 or 2 have matched. Seehas_alarm1_matched.
    • Clear flag indicating that alarms 1 or 2 have matched. Seeclear_alarm1_matched_flag.
    • Enable and disable alarms 1 and 2 interrupt generation. Seeenable_alarm1_interrupts.
  • Wave generation:
    • Enable and disable the square-wave generation. Seeenable_square_wave.
    • Select the square-wave frequency. Seeset_square_wave_frequency.
    • Enable and disable the 32kHz output. Seeenable_32khz_output.
    • Enable and disable the 32kHz output when battery powered. Seeenable_32khz_output_on_battery.
  • Temperature conversion:
    • Read the temperature. Seetemperature.
    • Force a temperature conversion and time compensation. Seeconvert_temperature.
    • Set the temperature conversion rate. Seeset_temperature_conversion_rate.
    • Enable and disable the temperature conversions when battery-powered. Seeenable_temperature_conversions_on_battery.

The devices

This driver is compatible with the DS3231 and DS3232 I2C devices and theDS3234 SPI device.

These devices are low-cost temperature-compensated crystal oscillator (TCXO)with a very accurate, temperature-compensated, integrated real-time clock(RTC) including 236/256 bytes of battery-backed SRAM, depending on the model.

DS3231 and DS3232 details

The devices incorporate a battery input, and maintain accurate timekeepingwhen main power to the devices is interrupted. The integration of thecrystal resonator enhances the long-term accuracy of the devices as well asreduces the piece-part count in a manufacturing line.The devices are available in commercial and industrial temperature ranges,and are offered in a 16-pin, 300-mil SO package.

The RTC maintains seconds, minutes, hours, day, date, month, and yearinformation. The date at the end of the month is automatically adjusted formonths with fewer than 31 days, including corrections for leap year. Theclock operates in either the 24-hour or 12-hour format with an AM/PMindicator. Two programmable time-of-day alarms and a programmablesquare-wave output are provided. Address and data are transferred seriallythrough an I2C bidirectional bus.

A precision temperature-compensated voltage reference and comparatorcircuit monitors the status of VCC to detect power failures, to provide areset output, and to automatically switch to the backup supply whennecessary. Additionally, the RST pin is monitored as a pushbuttoninput for generating a μP reset.

DS3234 details

The DS3234 incorporates a precision, temperature-compensated voltagereference and comparator circuit to monitor VCC. When VCC drops below thepower-fail voltage (VPF), the device asserts the RST output and alsodisables read and write access to the part when VCC drops below both VPFand VBAT. The RST pin is monitored as a pushbutton input for generating aμP reset. The device switches to the backup supply input and maintainsaccurate timekeeping when main power to the device is interrupted.The integration of the crystal resonator enhances the long-term accuracy ofthe device as well as reduces the piece-part count in a manufacturing line.The DS3234 is available in commercial and industrial temperature ranges,and is offered in an industry-standard 300-mil, 20-pin SO package.

The DS3234 also integrates 256 bytes of battery-backed SRAM. In the eventof main power loss, the contents of the memory are maintained by the powersource connected to the V BAT pin. The RTC maintains seconds, minutes,hours, day, date, month, and year information. The date at the end of themonth is automatically adjusted for months with fewer than 31 days,including corrections for leap year. The clock operates in either the24-hour or 12-hour format with AM/PM indicator. Two programmabletime-of-day alarms and a programmable square-wave output are provided.Address and data are transferred serially by an SPI bidirectional bus.

Datasheets:

Usage

To use this driver, import this crate and anembedded_hal implementation,then instantiate the appropriate device.In the following example an instance of the device DS3231 will be created.Other devices can be created with similar methods like:Ds323x::new_ds3234(...).

Please find additional examples using hardware in this repository:driver-examples

use ds323x::{DateTimeAccess,Ds323x,NaiveDate,Rtcc};use linux_embedded_hal::I2cdev;fnmain(){let dev =I2cdev::new("/dev/i2c-1").unwrap();letmut rtc =Ds323x::new_ds3231(dev);let datetime =NaiveDate::from_ymd_opt(2020,5,1).unwrap().and_hms_opt(19,59,58).unwrap();    rtc.set_datetime(&datetime).unwrap();// do something else...let time = rtc.time().unwrap();println!("Time: {}", time);let _dev = rtc.destroy_ds3231();}

Support

For questions, issues, feature requests like compatibility with other devices and otherchanges, please file anissue in the github project.

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.75 and up. Itmightcompile with older versions but that may change in any new patch release.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.

About

Platform-agnostic Rust driver for the DS3231, DS3232 and DS3234 extremely accurate real-time clocks (RTC).

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors7

Languages


[8]ページ先頭

©2009-2025 Movatter.jp