Skip to main content

Meadow.Foundation.RTCs.Ds323x

Ds323x
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.RTCs.Ds323x

The DS323x is a low-cost and accurate real-time clock with a temperature compensation crystal oscillator. This range of chips offers the following functionality:

  • Temperature compensation
  • Battery backup
  • I2C (DS3231) and SPI (DS3234) interfaces.
  • Two programmable alarms
  • 32.768 KHz square wave output

Code Example

Ds3231 sensor;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

sensor = new Ds3231(Device.CreateI2cBus(), Device.Pins.D06);
sensor.OnAlarm1Raised += Sensor_OnAlarm1Raised;

return base.Initialize();
}

public override Task Run()
{
sensor.CurrentDateTime = new DateTime(2020, 1, 1);

Resolver.Log.Info($"Current time: {sensor.CurrentDateTime}");
Resolver.Log.Info($"Temperature: {sensor.Temperature}");

sensor.ClearInterrupt(Ds323x.Alarm.BothAlarmsRaised);

sensor.SetAlarm(Ds323x.Alarm.Alarm1Raised,
new DateTime(2020, 1, 1, 1, 0, 0),
Ds323x.AlarmType.WhenSecondsMatch);

sensor.DisplayRegisters();

return base.Run();
}

private void Sensor_OnAlarm1Raised(object sender)
{
var rtc = (Ds3231)sender;
Resolver.Log.Info("Alarm 1 has been activated: " + rtc.CurrentDateTime.ToString("dd MMM yyyy HH:mm:ss"));
rtc.ClearInterrupt(Ds323x.Alarm.Alarm1Raised);
}

Sample project(s) available on GitHub

Wiring Example

The DS3231 real time clock module (see image below) requires only four (for simple timekeeping) or five (for alarms) connections

DS323xMeadow Pin
VCC3.3V
GNDGND
SCKSC
SDASD
InterruptSQW

It should look like the following diagram:

The 32K pin outputs the 32,768 Hz clock signal from the module. This signal is only available when power is supplied by Vcc, it is not available when the module is on battery power.

The orange wire is only required if the alarms are being used to interrupt the Meadow.