Crates.io | ds323x |
lib.rs | ds323x |
version | 0.5.1 |
source | src |
created_at | 2018-10-31 10:32:35.123855 |
updated_at | 2023-07-17 19:54:24.854339 |
description | Platform-agnostic Rust driver for the DS3231, DS3232 and DS3234 extremely accurate real-time clocks (RTC). |
homepage | https://github.com/eldruin/ds323x-rs |
repository | https://github.com/eldruin/ds323x-rs |
max_upload_size | |
id | 93783 |
size | 153,661 |
This is a platform agnostic Rust driver for the DS3231, DS3232 and DS3234
extremely accurate real-time clocks, based on the embedded-hal
traits.
This driver allows you to:
datetime
.year
.enable
.busy
.has_been_stopped
.clear_has_been_stopped_flag
.set_aging_offset
.use_int_sqw_output_as_interrupt
.set_alarm1_day
.set_alarm1_hms
.has_alarm1_matched
.clear_alarm1_matched_flag
.enable_alarm1_interrupts
.enable_square_wave
.set_square_wave_frequency
.enable_32khz_output
.enable_32khz_output_on_battery
.temperature
.convert_temperature
.set_temperature_conversion_rate
.enable_temperature_conversions_on_battery
.This driver is compatible with the DS3231 and DS3232 I2C devices and the DS3234 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.
The devices incorporate a battery input, and maintain accurate timekeeping when main power to the devices is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the devices as well as reduces 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 year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an AM/PM indicator. Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially through an I2C bidirectional bus.
A precision temperature-compensated voltage reference and comparator circuit monitors the status of VCC to detect power failures, to provide a reset output, and to automatically switch to the backup supply when necessary. Additionally, the RST pin is monitored as a pushbutton input for generating a μP reset.
The DS3234 incorporates a precision, temperature-compensated voltage reference and comparator circuit to monitor VCC. When VCC drops below the power-fail voltage (VPF), the device asserts the RST output and also disables read and write access to the part when VCC drops below both VPF and VBAT. The RST pin is monitored as a pushbutton input for generating a μP reset. The device switches to the backup supply input and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the 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 event of main power loss, the contents of the memory are maintained by the power source connected to the V BAT pin. The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially by an SPI bidirectional bus.
Datasheets:
To use this driver, import this crate and an embedded_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;
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut 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();
}
For questions, issues, feature requests like compatibility with other devices and other changes, please file an issue in the github project.
This crate is guaranteed to compile on stable Rust 1.35 and up. It might compile with older versions but that may change in any new patch release.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.