Skip to content

Class: RTCPi

Andrew Dorey edited this page Feb 27, 2020 · 2 revisions

RTCPi

This class contains methods for use with the RTC Pi, RTC Pi Plus and RTC Pi Zero from https://www.abelectronics.co.uk/p/70/rtc-pi

Methods:

Connect() 

Connect to the I2C device
Parameters: none
Returns: null

IsConnected() 

Check if the device is connected
Parameters: none
Returns: boolean

Dispose() 

Dispose of the active I2C device
Parameters: none
Returns: null

ReadMemory(byte address, byte length)

Read from the memory on the DS1307. Memory range is 0x08 to 0x3F.
Parameters: address - First memory address where the values with be read.
length - Number of bytes to read from memory.
Returns: byte[] - Byte array containing read memory values.

WriteMemory(byte address, byte[] values)

Write to the SRAM memory on the DS1307. Memory range is 0x08 to 0x3F.
Parameters: address - First memory address where the values with be written. values - Byte array containing values to be written to memory. Array length can not exceed the memory space available. Returns: null

Parameters

DateTime Date { get; set; }

Set or get the date and time from the RTC.
Takes a DateTime variable.
Returns: DateTime

byte Frequency { get; set; }

Get or set the frequency of the output pin square-wave.
Options are: 1 = 1Hz, 2 = 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz

bool Output { get; set; }

Enable or disable the square-wave output on the SQW pin.
Set output as true of false. Gets output state as true or false.

Usage

To use the RTC Pi library in your code you must first import the library dll:

using ABElectronicsUK;

Next you must initialise the rtc class:

ABElectronicsUK.RTCPi rtc = new ABElectronicsUK.RTCPi();

Next we need to connect to the device and wait for the connection

rtc.Connect();

while (!rtc.IsConnected)
{
}

You can set the date and time from the RTC chip to be the 25th December 2015 at 6 AM with:

DateTime newdate = new DateTime(2015, 12, 25, 06, 00, 00);
rtc.Date = newdate;

You can read the date and time from the RTC chip with:

DateTime value = rtc.Date;
Clone this wiki locally