Table of Contents

Class Mcp7940m

Namespace
Iot.Device.Mcp7940xx
Assembly
Iot.Device.Mcp7940xx.dll

I2C Real-Time Clock/Calendar with SRAM.

public class Mcp7940m
Inheritance
Mcp7940m
Derived

Constructors

Mcp7940m(I2cDevice, ClockSource)

Initializes a new instance of the Mcp7940m class.

public Mcp7940m(I2cDevice i2cDevice, ClockSource clockSource)

Parameters

i2cDevice I2cDevice

The I2C device to use for communication.

clockSource ClockSource

The oscillator configuration of the clock.

Exceptions

ArgumentNullException

Thrown when i2cDevice is null.

Fields

DefaultI2cAddress

Default I2C address for the Mcp7940xx family.

public const byte DefaultI2cAddress = 111

Field Value

byte

_i2cDevice

The underlying I2C device used for communication.

protected readonly I2cDevice _i2cDevice

Field Value

I2cDevice

Properties

AlarmInterruptPolarity

Gets or sets the output polarity of the MFP pin when an alarm interrupt is asserted.

public PinValue AlarmInterruptPolarity { get; set; }

Property Value

PinValue

GeneralPurposeOutput

Gets or sets the MFP pin level when in general purpose output mode.

public PinValue GeneralPurposeOutput { get; set; }

Property Value

PinValue

Remarks

General purpose output can only be used when Alarm1, Alarm2 and square wave output are all disabled.

IsEnabledAlarm1

Gets a value indicating whether Alarm 1 is enabled.

public bool IsEnabledAlarm1 { get; }

Property Value

bool

IsEnabledAlarm2

Gets a value indicating whether Alarm 2 is enabled.

public bool IsEnabledAlarm2 { get; }

Property Value

bool

IsEnabledGeneralPurposeOutput

Gets a value indicating whether the general purpose output is enabled.

public bool IsEnabledGeneralPurposeOutput { get; }

Property Value

bool

IsEnabledSquareWaveOutput

Gets a value indicating whether the square wave output is enabled.

public bool IsEnabledSquareWaveOutput { get; }

Property Value

bool

IsHalted

Gets a value indicating whether the clocks oscillator has been halted.

public bool IsHalted { get; }

Property Value

bool

IsTriggeredAlarm1

Gets a value indicating whether Alarm 1 is triggered.

public bool IsTriggeredAlarm1 { get; }

Property Value

bool

IsTriggeredAlarm2

Gets a value indicating whether Alarm 2 is triggered.

public bool IsTriggeredAlarm2 { get; }

Property Value

bool

SquareWaveOutputFrequency

Gets or sets the frequency of the square wave output on the MFP pin.

public SquareWaveFrequency SquareWaveOutputFrequency { get; set; }

Property Value

SquareWaveFrequency

Methods

ClearTimeAdjustment()

Requests time trimming correction not be performed.

public void ClearTimeAdjustment()

DisableAlarm1()

Disables Alarm 1.

public void DisableAlarm1()

DisableAlarm2()

Disables Alarm 2.

public void DisableAlarm2()

DisableSquareWaveOutput()

Disables square wave output from the MFP pin.

public void DisableSquareWaveOutput()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

EnableAlarm1()

Enables Alarm 1.

public void EnableAlarm1()

Remarks

Alarm interrupt output can only be used when general purpose output and square wave output are both disabled.

EnableAlarm2()

Enables Alarm 2.

public void EnableAlarm2()

Remarks

Alarm interrupt output can only be used when general purpose output and square wave output are both disabled.

EnableSquareWaveOutput()

Enables square wave output from the MFP pin.

public void EnableSquareWaveOutput()

GetAlarm1()

Reads the settings of Alarm 1 from the device.

public Mcp7940m.Alarm GetAlarm1()

Returns

Mcp7940m.Alarm

An Mcp7940m.Alarm object whose value is the current settings of Alarm 1.

GetAlarm2()

Reads the settings of Alarm 2 from the device.

public Mcp7940m.Alarm GetAlarm2()

Returns

Mcp7940m.Alarm

An Mcp7940m.Alarm object whose value is the current settings of Alarm 2.

GetTime()

Gets a DateTime object that is set to the current date and time of the device.

public DateTime GetTime()

Returns

DateTime

A DateTime object whose value is the current device date and time.

Halt(bool)

Stops the clocks oscillator.

public void Halt(bool blockUntilOscillatorInactive = false)

Parameters

blockUntilOscillatorInactive bool

Determins if the function should block execution until the clocks oscillator is fully stopped.

ReadByteFromSRAM(byte)

Reads a single byte from the devices SRAM at the given address.

public byte ReadByteFromSRAM(byte address)

Parameters

address byte

The address to read from.

Returns

byte

The byte read from the device.

Remarks

Parameter address must be in the range 0 to 63.

Exceptions

ArgumentOutOfRangeException

Thrown when address falls outside of the addressable range for this device.

ResetAlarm1()

Clears the triggered state of Alarm 1.

public void ResetAlarm1()

ResetAlarm2()

Clears the triggered state of Alarm 2.

public void ResetAlarm2()

SetAlarm1(Alarm)

Sets Alarm 1 on the device.

public void SetAlarm1(Mcp7940m.Alarm alarm)

Parameters

alarm Mcp7940m.Alarm

The new settings for Alarm 1.

SetAlarm2(Alarm)

Sets Alarm 2 on the device.

public void SetAlarm2(Mcp7940m.Alarm alarm)

Parameters

alarm Mcp7940m.Alarm

The new settings for Alarm 2.

SetTime(DateTime)

Sets the time.

public void SetTime(DateTime time)

Parameters

time DateTime

The new time.

SetTimeAdjustment(int, SquareWaveFrequency, TrimmingMode)

Sets the time trimming correction to compensate for a clock frequency mismatch.

public void SetTimeAdjustment(int measuredFrequency, SquareWaveFrequency idealFrequency, TrimmingMode mode = TrimmingMode.NormalTrimMode)

Parameters

measuredFrequency int

The measured frequency of the clocks external crystal oscillator from the MFP pin.

idealFrequency SquareWaveFrequency

The desired clock frequency.

mode TrimmingMode

The rate that oscillator trimming adjustments are applied.

StartClock(bool)

Starts the clocks oscillator.

public void StartClock(bool blockUntilOscillatorActive = false)

Parameters

blockUntilOscillatorActive bool

Determins if the function should block execution until the clocks oscillator is fully active.

WriteByteToSRAM(byte, byte)

Writes a single byte to the devices SRAM at the given address.

public void WriteByteToSRAM(byte address, byte value)

Parameters

address byte

The address to write to.

value byte

The byte to be written into the device.

Remarks

Parameter address must be in the range 0 to 63.

Exceptions

ArgumentOutOfRangeException

Thrown when address falls outside of the addressable range for this device.