| Crates.io | ds3231 |
| lib.rs | ds3231 |
| version | 0.3.0 |
| created_at | 2025-05-04 20:34:06.181116+00 |
| updated_at | 2025-06-09 13:57:12.166247+00 |
| description | A platform-agnostic driver for the DS3231 precision real-time clock |
| homepage | |
| repository | https://github.com/liebman/ds3231-rs |
| max_upload_size | |
| id | 1659915 |
| size | 308,752 |
A platform-agnostic Rust driver for the DS3231 Real-Time Clock, built on the embedded-hal ecosystem.
The DS3231 is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated
temperature-compensated crystal oscillator (TCXO).
log or defmtunsafe codeAdd this to your Cargo.toml:
[dependencies]
ds3231 = "0.3.0"
use ds3231::{DS3231, Config, TimeRepresentation, SquareWaveFrequency, InterruptControl, Oscillator};
// Create configuration
let config = Config {
time_representation: TimeRepresentation::TwentyFourHour,
square_wave_frequency: SquareWaveFrequency::Hz1,
interrupt_control: InterruptControl::SquareWave,
battery_backed_square_wave: false,
oscillator_enable: Oscillator::Enabled,
};
// Initialize device with I2C
let mut rtc = DS3231::new(i2c, 0x68);
// Configure the device
rtc.configure(&config)?;
// Get current date/time
let datetime = rtc.datetime()?;
Enable the async feature in your Cargo.toml and use with async/await:
use ds3231::asynch::DS3231;
// Initialize device
let mut rtc = DS3231::new(i2c, 0x68);
// Configure asynchronously
rtc.configure(&config).await?;
// Get current date/time asynchronously
let datetime = rtc.datetime().await?;
The crate can be compiled with the following features:
async: Enables async I²C supportlog: Enables logging via the log cratedefmt: Enables logging via the defmt cratetemperature_f32 - Enables temperature reading as f32Licensed 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.