how to use it:
it can use on raspberry pi and banana pi .
1:Product Specification:
2:Produce Overview: The RTC module is specifically designed for BananaPi. It communicated with BananaPi through I2C bus. There is a Maxim DS3231 and 0.2uF SuperCapacitor on the board to keep the real time for a long time after the BananaPi has power off.
3:Produce Features: Use Maxim DS3231 chip 0.2uF Super Capacitor Can be operated by a shell 4:Port: Banana Pi connection port
5: conncet on BPI
6 ,code :
unit Uit_DS3231;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, TWI;
const
DS3231_WriteAddress 0xD0 //器件写地址
DS3231_ReadAddress 0xD1 //器件读地址
DS3231_SECOND 0x00 //秒
DS3231_MINUTE 0x01 //分
DS3231_HOUR 0x02 //时
DS3231_WEEK 0x03 //星期
DS3231_DAY 0x04 //日
DS3231_MONTH 0x05 //月
DS3231_YEAR 0x06 //年
DS3231_SALARM1ECOND 0x07 //秒
DS3231_ALARM1MINUTE 0x08 //分
DS3231_ALARM1HOUR 0x09 //时
DS3231_ALARM1WEEK 0x0A //星期/日
DS3231_ALARM2MINUTE 0x0b //分
DS3231_ALARM2HOUR 0x0c //时
DS3231_ALARM2WEEK 0x0d //星期/日
DS3231_CONTROL 0x0e //控制寄存器
DS3231_STATUS 0x0f //状态寄存器
BSY 2 //忙
OSF 7 //振荡器停止标志
DS3231_XTAL 0x10 //晶体老化寄存器
DS3231_TEMPERATUREH 0x11 //温度寄存器高字节(8位)
DS3231_TEMPERATUREL 0x12 //温度寄存器低字节(高2位)
type
TDS3231 = class
private
class var FInstance: TDS3231;
class function GetInstance: TDS3231; static;
public
class procedure Release;
class property Instance: TDS3231 read GetInstance;
private
FTWI0: TTWI;
constructor Create;
destructor Destroy; override;
public
function GetByte(Addr, Reg: Byte): Byte;
end;
implementation
const TDS3231ADDR = $34;
class function TDS3231.GetInstance: TDS3231;
begin
if FInstance = nil then FInstance:= TDS3231.Create;
Result:= FInstance;
end;
class procedure TDS3231.Release;
begin
FreeAndNil(FInstance);
end;
(******************************************************************************)
constructor TDS3231.Create;
begin
inherited Create;
FTWI0:= TTWI.Create(TWI_0);
end;
destructor TDS3231.Destroy;
begin
FTWI0.Free;
inherited Destroy;
end;
function TDS3231.GetByte(Addr, Reg: Byte): Byte;
begin
FTWI0.Read(TDS3231ADDR, Reg, Result);
end;
end.