[Banana pi Accessories] BPI-RTC module and how to use it on banana pi


(bpi team) #1

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.

#2

What is the code ? …‘Lolcode’ , ‘Ook!’ , ‘Velato’, ‘Brainfuck’ ?

I test: root@osirisBpiM3:~ # nano code … root@osirisBpiM3:~ # chmod +x code

root@osirisBpiM3:~ # ./code ./code: line 1: unit: command not found ./code: line 3: {: command not found ./code: line 5: interface: command not found ./code: line 7: uses: command not found ./code: line 9: Classes,: command not found ./code: line 11: const: command not found ./code: line 13: DS3231_WriteAddress: command not found ./code: line 15: DS3231_ReadAddress: command not found ./code: line 17: DS3231_SECOND: command not found ./code: line 19: DS3231_MINUTE: command not found ./code: line 21: DS3231_HOUR: command not found ./code: line 23: DS3231_WEEK: command not found ./code: line 25: DS3231_DAY: command not found ./code: line 27: DS3231_MONTH: command not found ./code: line 29: DS3231_YEAR: command not found ./code: line 31: DS3231_SALARM1ECOND: command not found ./code: line 33: DS3231_ALARM1MINUTE: command not found ./code: line 35: DS3231_ALARM1HOUR: command not found ./code: line 37: DS3231_ALARM1WEEK: command not found ./code: line 39: DS3231_ALARM2MINUTE: command not found ./code: line 41: DS3231_ALARM2HOUR: command not found ./code: line 43: DS3231_ALARM2WEEK: command not found ./code: line 45: DS3231_CONTROL: command not found ./code: line 47: DS3231_STATUS: command not found ./code: line 49: BSY: command not found ./code: line 51: OSF: command not found ./code: line 53: DS3231_XTAL: command not found ./code: line 55: syntax error near unexpected token (' ./code: line 55: DS3231_TEMPERATUREH 0x11 //温度寄存器高字节(8位) ’

&&& :upside_down:

&& @sinovoip

I speak five languages ​​, but … Unfortunately I do not know Chinese . Would it be possible comments in the code … write in English ?

How can I set the alarm ? Can you write the simplest example in C ?

Thank you eW


(bpi team) #3

pleae check here:

https://bananapi.gitbooks.io/bpi-accessories/content/en/rtcmodule.html


(BlinkQ) #4

it is code like free pascal


#5

Sorry, I can’t compile - use ‘pure’ Debian, only console - have you this file compiled?