Difference between revisions of "Unit DS1307"

From Ultibo.org
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
----
 
----
 +
 +
'''Maxim DS1307 Real Time Clock Driver unit'''
  
 
The Maxim DS1307 is an I2C interface, battery backed real time clock chip with full BCD clock and calendar and 56 bytes of software accessible NVRAM. The chip supports 12 or 24 hour format and is widely used in low cost RTC devices available from a range of suppliers.
 
The Maxim DS1307 is an I2C interface, battery backed real time clock chip with full BCD clock and calendar and 56 bytes of software accessible NVRAM. The chip supports 12 or 24 hour format and is widely used in low cost RTC devices available from a range of suppliers.
Line 12: Line 14:
 
----
 
----
  
''To be documented''
+
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 specific constants''' <code> DS1307_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_RTC_DESCRIPTION = 'Maxim DS1307 Real Time Clock';</code>
 +
| Description of DS1307 device
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>DS1307_MIN_TIME = 125911584000000000;</code>
 +
| Time starts at 01/01/2000 00:00:00 (MM/DD/YY HH:MM:SS)
 +
|-
 +
| <code>DS1307_MAX_TIME = 157469183990000000;</code>
 +
| Time ends at 12/31/2099 23:59:59 (MM/DD/YY HH:MM:SS)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 chip''' <code> DS1307_CHIP_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_CHIP_DS1307 = 0;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS1337 = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS1338 = 2;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS1339 = 3;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS1340 = 4;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS1388 = 5;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_DS3231 = 6;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_M41T00 = 7;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_MCP794XX = 8;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_CHIP_RX8025 = 9;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 RTC register''' <code> DS1307_REG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_REG_SECONDS = $00;</code>
 +
| 00-59
 +
|-
 +
| <code>DS1307_REG_MINUTE = $01;</code>
 +
| 00-59
 +
|-
 +
| <code>DS1307_REG_HOUR = $02;</code>
 +
| 00-23 (or 1-12am,pm)
 +
|-
 +
| <code>DS1307_REG_WEEKDAY = $03;</code>
 +
| 01-07
 +
|-
 +
| <code>DS1307_REG_DAY = $04;</code>
 +
| 01-31
 +
|-
 +
| <code>DS1307_REG_MONTH = $05;</code>
 +
| 01-12
 +
|-
 +
| <code>DS1307_REG_YEAR = $06;</code>
 +
| 00-99
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 control and status register''' <code> DS1307_REG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_REG_CONTROL = $07;</code>
 +
| Also DS1338
 +
|-
 +
| <code>DS1337_REG_CONTROL = $0e;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1340_REG_CONTROL = $07;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1340_REG_FLAG = $09;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_STATUS = $0f;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1339_REG_ALARM1_SECONDS = $07;</code>
 +
| &nbsp;
 +
|-
 +
| <code>RX8025_REG_CONTROL1 = $0e;</code>
 +
| &nbsp;
 +
|-
 +
| <code>RX8025_REG_CONTROL2 = $0f;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 seconds register''' <code> DS1307_REG_SECONDS_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_REG_SECONDS_CH = $80;</code>
 +
| Clock Halt bit (1 to Disable/0 to Enable the clock)
 +
|-
 +
| <code>DS1340_REG_SECONDS_nEOSC = $80;</code>
 +
| &nbsp;
 +
|-
 +
| <code>MCP794XX_REG_SECONDS_ST = $80;</code>
 +
| Clock Stop Bit (1 to Enable/0 to Disable the clock)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 hour register''' <code> DS1307_REG_HOUR_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_REG_HOUR_12HR = $40;</code>
 +
| 12/24 hour bit (1 = 12 hour mode/0 = 24 hour mode)
 +
|-
 +
| <code>DS1307_REG_HOUR_PM = $20;</code>
 +
| AM/PM bit (1 = PM/0 = AM) (Only in 12 hour mode)
 +
|-
 +
| <code>DS1340_REG_HOUR_CENTURY_EN = $80;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1340_REG_HOUR_CENTURY = $40;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''MCP794XX weekday register''' <code> MCP794XX_REG_WEEKDAY_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>MCP794XX_REG_WEEKDAY_VBATEN = $08;</code>
 +
| Battery Backup Enabled (1 to Enable/0 to Disable)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1337 month register''' <code> DS1337_REG_MONTH_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1337_REG_MONTH_CENTURY = $80;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1307 control register''' <code> DS1307_REG_CONTROL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1307_REG_CONTROL_OUT = $80;</code>
 +
| Output Control (Output level of SQW/OUT pin when SQWE = 0)
 +
|-
 +
| <code>DS1338_REG_CONTROL_OSF = $20;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1307_REG_CONTROL_SQWE = $10;</code>
 +
| Square-Wave Enable (When set to 1, enables the oscillator output)
 +
|-
 +
| <code>DS1307_REG_CONTROL_RS1 = $02;</code>
 +
| Rate Select 1 (See datasheet for values)
 +
|-
 +
| <code>DS1307_REG_CONTROL_RS0 = $01;</code>
 +
| Rate Select 2 (See datasheet for values)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1337 control register''' <code> DS1337_REG_CONTROL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1337_REG_CONTROL_nEOSC = $80;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1339_REG_CONTROL_BBSQI = $20;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS3231_REG_CONTROL_BBSQW = $40;</code>
 +
| same as BBSQI
 +
|-
 +
| <code>DS1337_REG_CONTROL_RS2 = $10;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_CONTROL_RS1 = $08;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_CONTROL_INTCN = $04;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_CONTROL_A2IE = $02;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_CONTROL_A1IE = $01;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1340 control register''' <code> DS1340_REG_CONTROL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1340_REG_CONTROL_OUT = $80;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>DS1340_REG_CONTROL_FT = $40;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1340_REG_CONTROL_CALIB_SIGN = $20;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1340_REG_CONTROL_M_CALIBRATION = $1f;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1340 flag register''' <code> DS1340_REG_FLAG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1340_REG_FLAG_OSF = $80;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''DS1337 status register''' <code> DS1337_REG_STATUS_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>DS1337_REG_STATUS_OSF = $80;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>DS1337_REG_STATUS_A2I = $02;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DS1337_REG_STATUS_A1I = $01;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''RX8025 control1 register''' <code> RX8025_REG_CONTROL1_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>RX8025_REG_CONTROL1_2412 = $20;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''RX8025 control2 register''' <code> RX8025_REG_CONTROL2_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>RX8025_REG_CONTROL2_PON = $10;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>RX8025_REG_CONTROL2_VDET = $40;</code>
 +
| &nbsp;
 +
|-
 +
| <code>RX8025_REG_CONTROL2_XST = $20;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===
 
----
 
----
  
''To be documented''
+
 
 +
'''DS1307 RTC time'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PDS1307RTCTime = ^TDS1307RTCTime;</code>
 +
 
 +
<code>TDS1307RTCTime = array[0..6] of Byte;</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| &nbsp;
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''DS1307 RTC device'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PDS1307RTCDevice = ^TDS1307RTCDevice;</code>
 +
 
 +
<code>TDS1307RTCDevice = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''RTC Properties''
 +
|-
 +
| <code>RTC:TRTCDevice;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''DS1307 Properties''
 +
|-
 +
| <code>I2C:PI2CDevice;</code>
 +
| The I2C device this RTC is connected to
 +
|-
 +
| <code>Address:Word;</code>
 +
| The I2C address of the device
 +
|-
 +
| <code>Chip:LongWord;</code>
 +
| The chip type (eg DS1307_CHIP_DS1307)
 +
|-
 +
| <code>RTCReg:Byte;</code>
 +
| The register offset for the RTC
 +
|-
 +
| <code>NVRAMReg:Byte;</code>
 +
| The register offset for the NVRAM
 +
|-
 +
| <code>NVRAMSize:Byte;</code>
 +
| The NVRAM size
 +
|-
 +
| <code>ControlReg:Byte;</code>
 +
| The control register offset
 +
|-
 +
|colspan="2"|''Statistics Properties''
 +
|-
 +
| <code>ReadCount:LongWord;</code>
 +
| Number of direct RTC/NVRAM/Control reads to the device
 +
|-
 +
| <code>WriteCount:LongWord;</code>
 +
| Number of direct RTC/NVRAM/Control writes to the device
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
 
----
 
----
  
''To be documented''
+
''None defined''
  
 
=== Function declarations ===
 
=== Function declarations ===
 
----
 
----
  
''To be documented''
 
  
 +
'''Initialization functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure DS1307Init;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''DS1307 RTC functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307RTCStart(RTC:PRTCDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of RTCDeviceStart API for DS1307 RTC</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use RTCDeviceStart instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307RTCStop(RTC:PRTCDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of RTCDeviceStop API for DS1307 RTC</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use RTCDeviceStop instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307RTCGetTime(RTC:PRTCDevice):Int64;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of RTCDeviceGetTime API for DS1307 RTC</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use RTCDeviceGetTime instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307RTCSetTime(RTC:PRTCDevice; const Time:Int64):Int64;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of RTCDeviceSetTime API for DS1307 RTC</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use RTCDeviceSetTime instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''DS1307 helper functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307ReadRTC(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307WriteRTC(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307ReadNVRAM(RTC:PRTCDevice; Offset:Byte; Buffer:Pointer; Size:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307WriteNVRAM(RTC:PRTCDevice; Offset:Byte; Buffer:Pointer; Size:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307ReadControl(RTC:PRTCDevice; var Control:Byte):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307WriteControl(RTC:PRTCDevice; Control:Byte):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307DefaultRTCTime(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307FileTimeToRTCTime(RTC:PRTCDevice; const FileTime:Int64; Buffer:Pointer; Size:LongWord):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function DS1307RTCTimeToFileTime(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord; var FileTime:Int64):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
Return to [[Unit_Reference|Unit Reference]]
 
Return to [[Unit_Reference|Unit Reference]]

Latest revision as of 04:11, 24 April 2018

Return to Unit Reference


Description


Maxim DS1307 Real Time Clock Driver unit

The Maxim DS1307 is an I2C interface, battery backed real time clock chip with full BCD clock and calendar and 56 bytes of software accessible NVRAM. The chip supports 12 or 24 hour format and is widely used in low cost RTC devices available from a range of suppliers.

This driver extends the real time clock API to include functions for directly reading and writing the NVRAM which could be used for storing device specific information and configuration or for non volatile storage of keys, passwords or tokens.

Constants



DS1307 specific constants DS1307_*
DS1307_RTC_DESCRIPTION = 'Maxim DS1307 Real Time Clock'; Description of DS1307 device
 
DS1307_MIN_TIME = 125911584000000000; Time starts at 01/01/2000 00:00:00 (MM/DD/YY HH:MM:SS)
DS1307_MAX_TIME = 157469183990000000; Time ends at 12/31/2099 23:59:59 (MM/DD/YY HH:MM:SS)


DS1307 chip DS1307_CHIP_*
DS1307_CHIP_DS1307 = 0;  
DS1307_CHIP_DS1337 = 1;  
DS1307_CHIP_DS1338 = 2;  
DS1307_CHIP_DS1339 = 3;  
DS1307_CHIP_DS1340 = 4;  
DS1307_CHIP_DS1388 = 5;  
DS1307_CHIP_DS3231 = 6;  
DS1307_CHIP_M41T00 = 7;  
DS1307_CHIP_MCP794XX = 8;  
DS1307_CHIP_RX8025 = 9;  


DS1307 RTC register DS1307_REG_*
DS1307_REG_SECONDS = $00; 00-59
DS1307_REG_MINUTE = $01; 00-59
DS1307_REG_HOUR = $02; 00-23 (or 1-12am,pm)
DS1307_REG_WEEKDAY = $03; 01-07
DS1307_REG_DAY = $04; 01-31
DS1307_REG_MONTH = $05; 01-12
DS1307_REG_YEAR = $06; 00-99


DS1307 control and status register DS1307_REG_*
DS1307_REG_CONTROL = $07; Also DS1338
DS1337_REG_CONTROL = $0e;  
DS1340_REG_CONTROL = $07;  
DS1340_REG_FLAG = $09;  
DS1337_REG_STATUS = $0f;  
DS1339_REG_ALARM1_SECONDS = $07;  
RX8025_REG_CONTROL1 = $0e;  
RX8025_REG_CONTROL2 = $0f;  


DS1307 seconds register DS1307_REG_SECONDS_*
DS1307_REG_SECONDS_CH = $80; Clock Halt bit (1 to Disable/0 to Enable the clock)
DS1340_REG_SECONDS_nEOSC = $80;  
MCP794XX_REG_SECONDS_ST = $80; Clock Stop Bit (1 to Enable/0 to Disable the clock)


DS1307 hour register DS1307_REG_HOUR_*
DS1307_REG_HOUR_12HR = $40; 12/24 hour bit (1 = 12 hour mode/0 = 24 hour mode)
DS1307_REG_HOUR_PM = $20; AM/PM bit (1 = PM/0 = AM) (Only in 12 hour mode)
DS1340_REG_HOUR_CENTURY_EN = $80;  
DS1340_REG_HOUR_CENTURY = $40;  


MCP794XX weekday register MCP794XX_REG_WEEKDAY_*
MCP794XX_REG_WEEKDAY_VBATEN = $08; Battery Backup Enabled (1 to Enable/0 to Disable)


DS1337 month register DS1337_REG_MONTH_*
DS1337_REG_MONTH_CENTURY = $80;  


DS1307 control register DS1307_REG_CONTROL_*
DS1307_REG_CONTROL_OUT = $80; Output Control (Output level of SQW/OUT pin when SQWE = 0)
DS1338_REG_CONTROL_OSF = $20;  
DS1307_REG_CONTROL_SQWE = $10; Square-Wave Enable (When set to 1, enables the oscillator output)
DS1307_REG_CONTROL_RS1 = $02; Rate Select 1 (See datasheet for values)
DS1307_REG_CONTROL_RS0 = $01; Rate Select 2 (See datasheet for values)


DS1337 control register DS1337_REG_CONTROL_*
DS1337_REG_CONTROL_nEOSC = $80;  
DS1339_REG_CONTROL_BBSQI = $20;  
DS3231_REG_CONTROL_BBSQW = $40; same as BBSQI
DS1337_REG_CONTROL_RS2 = $10;  
DS1337_REG_CONTROL_RS1 = $08;  
DS1337_REG_CONTROL_INTCN = $04;  
DS1337_REG_CONTROL_A2IE = $02;  
DS1337_REG_CONTROL_A1IE = $01;  


DS1340 control register DS1340_REG_CONTROL_*
DS1340_REG_CONTROL_OUT = $80;  
DS1340_REG_CONTROL_FT = $40;  
DS1340_REG_CONTROL_CALIB_SIGN = $20;  
DS1340_REG_CONTROL_M_CALIBRATION = $1f;  


DS1340 flag register DS1340_REG_FLAG_*
DS1340_REG_FLAG_OSF = $80;  


DS1337 status register DS1337_REG_STATUS_*
DS1337_REG_STATUS_OSF = $80;  
DS1337_REG_STATUS_A2I = $02;  
DS1337_REG_STATUS_A1I = $01;  


RX8025 control1 register RX8025_REG_CONTROL1_*
RX8025_REG_CONTROL1_2412 = $20;  


RX8025 control2 register RX8025_REG_CONTROL2_*
RX8025_REG_CONTROL2_PON = $10;  
RX8025_REG_CONTROL2_VDET = $40;  
RX8025_REG_CONTROL2_XST = $20;  


Type definitions



DS1307 RTC time

PDS1307RTCTime = ^TDS1307RTCTime;

TDS1307RTCTime = array[0..6] of Byte;

   

DS1307 RTC device

PDS1307RTCDevice = ^TDS1307RTCDevice;

TDS1307RTCDevice = record

RTC Properties
RTC:TRTCDevice;  
DS1307 Properties
I2C:PI2CDevice; The I2C device this RTC is connected to
Address:Word; The I2C address of the device
Chip:LongWord; The chip type (eg DS1307_CHIP_DS1307)
RTCReg:Byte; The register offset for the RTC
NVRAMReg:Byte; The register offset for the NVRAM
NVRAMSize:Byte; The NVRAM size
ControlReg:Byte; The control register offset
Statistics Properties
ReadCount:LongWord; Number of direct RTC/NVRAM/Control reads to the device
WriteCount:LongWord; Number of direct RTC/NVRAM/Control writes to the device


Public variables


None defined

Function declarations



Initialization functions

procedure DS1307Init;
Description: To be documented
Note None documented


DS1307 RTC functions

function DS1307RTCStart(RTC:PRTCDevice):LongWord;
Description: Implementation of RTCDeviceStart API for DS1307 RTC
Note Not intended to be called directly by applications, use RTCDeviceStart instead.


function DS1307RTCStop(RTC:PRTCDevice):LongWord;
Description: Implementation of RTCDeviceStop API for DS1307 RTC
Note Not intended to be called directly by applications, use RTCDeviceStop instead.


function DS1307RTCGetTime(RTC:PRTCDevice):Int64;
Description: Implementation of RTCDeviceGetTime API for DS1307 RTC
Note Not intended to be called directly by applications, use RTCDeviceGetTime instead.


function DS1307RTCSetTime(RTC:PRTCDevice; const Time:Int64):Int64;
Description: Implementation of RTCDeviceSetTime API for DS1307 RTC
Note Not intended to be called directly by applications, use RTCDeviceSetTime instead.


DS1307 helper functions

function DS1307ReadRTC(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):LongWord;
Description: To be documented
Note None documented


function DS1307WriteRTC(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):LongWord;
Description: To be documented
Note None documented


function DS1307ReadNVRAM(RTC:PRTCDevice; Offset:Byte; Buffer:Pointer; Size:LongWord):LongWord;
Description: To be documented
Note None documented


function DS1307WriteNVRAM(RTC:PRTCDevice; Offset:Byte; Buffer:Pointer; Size:LongWord):LongWord;
Description: To be documented
Note None documented


function DS1307ReadControl(RTC:PRTCDevice; var Control:Byte):LongWord;
Description: To be documented
Note None documented


function DS1307WriteControl(RTC:PRTCDevice; Control:Byte):LongWord;
Description: To be documented
Note None documented


function DS1307DefaultRTCTime(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord):Boolean;
Description: To be documented
Note None documented


function DS1307FileTimeToRTCTime(RTC:PRTCDevice; const FileTime:Int64; Buffer:Pointer; Size:LongWord):Boolean;
Description: To be documented
Note None documented


function DS1307RTCTimeToFileTime(RTC:PRTCDevice; Buffer:Pointer; Size:LongWord; var FileTime:Int64):Boolean;
Description: To be documented
Note None documented


Return to Unit Reference