1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/DS3232RTC_8cpp_source.html
Rhys Weatherley a108e5742e Update docs
2012-06-13 15:23:00 +10:00

523 lines
58 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>ArduinoLibs: DS3232RTC.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">ArduinoLibs</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li id="searchli">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<div class="title">DS3232RTC.cpp</div> </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00005"></a>00005 <span class="comment"> * copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00006"></a>00006 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
<a name="l00007"></a>00007 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00008"></a>00008 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00009"></a>00009 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included</span>
<a name="l00012"></a>00012 <span class="comment"> * in all copies or substantial portions of the Software.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
<a name="l00015"></a>00015 <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
<a name="l00019"></a>00019 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;DS3232RTC.h&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;../I2C/I2CMaster.h&quot;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#if defined(ARDUINO) &amp;&amp; ARDUINO &gt;= 100</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#include &lt;Arduino.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#else</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include &lt;WProgram.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00059"></a>00059 <span class="comment">// I2C address of the RTC chip (7-bit).</span>
<a name="l00060"></a>00060 <span class="preprocessor">#define DS3232_I2C_ADDRESS 0x68</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span>
<a name="l00062"></a>00062 <span class="comment">// Registers.</span>
<a name="l00063"></a>00063 <span class="preprocessor">#define DS3232_SECOND 0x00</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_MINUTE 0x01</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_HOUR 0x02</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_DAY_OF_WEEK 0x03</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_DATE 0x04</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_MONTH 0x05</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_YEAR 0x06</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM1_SEC 0x07</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM1_MIN 0x08</span>
<a name="l00072"></a>00072 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM1_HOUR 0x09</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM1_DAY 0x0A</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM2_MIN 0x0B</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM2_HOUR 0x0C</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM2_DAY 0x0D</span>
<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CONTROL 0x0E</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_STATUS 0x0F</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_AGING_OFFSET 0x10</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_TEMP_MSB 0x11</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_TEMP_LSB 0x12</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_RESERVED 0x13</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_NVRAM 0x14</span>
<a name="l00084"></a>00084 <span class="preprocessor"></span>
<a name="l00085"></a>00085 <span class="comment">// Bits in the DS3232_CONTROL register.</span>
<a name="l00086"></a>00086 <span class="preprocessor">#define DS3232_EOSC 0x80</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_BBSQW 0x40</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CONV 0x20</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_RS_1HZ 0x00</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_RS_1024HZ 0x08</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_RS_4096HZ 0x10</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_RS_8192HZ 0x18</span>
<a name="l00093"></a>00093 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_INTCN 0x04</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_A2IE 0x02</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_A1IE 0x01</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span>
<a name="l00097"></a>00097 <span class="comment">// Bits in the DS3232_STATUS register.</span>
<a name="l00098"></a>00098 <span class="preprocessor">#define DS3232_OSF 0x80</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_BB32KHZ 0x40</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CRATE_64 0x00</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CRATE_128 0x10</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CRATE_256 0x20</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_CRATE_512 0x30</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_EN32KHZ 0x08</span>
<a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_BSY 0x04</span>
<a name="l00106"></a>00106 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_A2F 0x02</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_A1F 0x01</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span>
<a name="l00109"></a>00109 <span class="comment">// Alarm storage at the end of the RTC&#39;s NVRAM.</span>
<a name="l00110"></a>00110 <span class="preprocessor">#define DS3232_ALARM_SIZE 3</span>
<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARMS (256 - RTC::ALARM_COUNT * DS3232_ALARM_SIZE - 1)</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM_MAGIC 255</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span>
<a name="l00126"></a><a class="code" href="classDS3232RTC.html#aa959454ae01b11c48d6ec7ec192b4ccb">00126</a> <a class="code" href="classDS3232RTC.html#aa959454ae01b11c48d6ec7ec192b4ccb" title="Attaches to a realtime clock slave device on bus.">DS3232RTC::DS3232RTC</a>(<a class="code" href="classI2CMaster.html" title="Abstract base class for I2C master implementations.">I2CMaster</a> &amp;bus, uint8_t oneHzPin)
<a name="l00127"></a>00127 : _bus(&amp;bus)
<a name="l00128"></a>00128 , _oneHzPin(oneHzPin)
<a name="l00129"></a>00129 , prevOneHz(false)
<a name="l00130"></a>00130 , _isRealTime(true)
<a name="l00131"></a>00131 , alarmInterrupts(false)
<a name="l00132"></a>00132 {
<a name="l00133"></a>00133 <span class="comment">// Probe the device and configure it for our use.</span>
<a name="l00134"></a>00134 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00135"></a>00135 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_CONTROL);
<a name="l00136"></a>00136 <span class="keywordflow">if</span> (_bus-&gt;<a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS3232_I2C_ADDRESS, 1)) {
<a name="l00137"></a>00137 uint8_t value = _bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>() &amp; DS3232_CONV;
<a name="l00138"></a>00138 <span class="keywordflow">if</span> (oneHzPin != 255)
<a name="l00139"></a>00139 value |= DS3232_BBSQW | DS3232_RS_1HZ;
<a name="l00140"></a>00140 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00141"></a>00141 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_CONTROL);
<a name="l00142"></a>00142 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);
<a name="l00143"></a>00143 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_CRATE_64);
<a name="l00144"></a>00144 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00145"></a>00145 } <span class="keywordflow">else</span> {
<a name="l00146"></a>00146 <span class="comment">// Did not get an acknowledgement from the RTC chip.</span>
<a name="l00147"></a>00147 _isRealTime = <span class="keyword">false</span>;
<a name="l00148"></a>00148 }
<a name="l00149"></a>00149
<a name="l00150"></a>00150 <span class="comment">// Configure the 1 Hz square wave pin if required.</span>
<a name="l00151"></a>00151 <span class="keywordflow">if</span> (oneHzPin != 255 &amp;&amp; _isRealTime) {
<a name="l00152"></a>00152 pinMode(oneHzPin, INPUT);
<a name="l00153"></a>00153 digitalWrite(oneHzPin, HIGH);
<a name="l00154"></a>00154 }
<a name="l00155"></a>00155
<a name="l00156"></a>00156 <span class="comment">// Initialize the alarms in the RTC chip&#39;s NVRAM.</span>
<a name="l00157"></a>00157 <span class="keywordflow">if</span> (_isRealTime)
<a name="l00158"></a>00158 initAlarms();
<a name="l00159"></a>00159 }
<a name="l00160"></a>00160
<a name="l00166"></a><a class="code" href="classDS3232RTC.html#a619ffee1bc013c9ddf4ae415115798bc">00166</a> <span class="keywordtype">bool</span> <a class="code" href="classDS3232RTC.html#a619ffee1bc013c9ddf4ae415115798bc" title="Returns true if the realtime clock has updated since the last call to this function.">DS3232RTC::hasUpdates</a>()
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168 <span class="comment">// If not using a 1 Hz pin or there is no RTC chip available,</span>
<a name="l00169"></a>00169 <span class="comment">// then assume that there is an update available.</span>
<a name="l00170"></a>00170 <span class="keywordflow">if</span> (_oneHzPin == 255 || !_isRealTime)
<a name="l00171"></a>00171 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00172"></a>00172
<a name="l00173"></a>00173 <span class="comment">// The DS3232 updates the internal registers on the falling edge of the</span>
<a name="l00174"></a>00174 <span class="comment">// 1 Hz clock. The values should be ready to read on the rising edge.</span>
<a name="l00175"></a>00175 <span class="keywordtype">bool</span> value = digitalRead(_oneHzPin);
<a name="l00176"></a>00176 <span class="keywordflow">if</span> (value &amp;&amp; !prevOneHz) {
<a name="l00177"></a>00177 prevOneHz = value;
<a name="l00178"></a>00178 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00179"></a>00179 } <span class="keywordflow">else</span> {
<a name="l00180"></a>00180 prevOneHz = value;
<a name="l00181"></a>00181 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184
<a name="l00185"></a>00185 <span class="keyword">inline</span> uint8_t fromBCD(uint8_t value)
<a name="l00186"></a>00186 {
<a name="l00187"></a>00187 <span class="keywordflow">return</span> (value &gt;&gt; 4) * 10 + (value &amp; 0x0F);
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189
<a name="l00190"></a>00190 <span class="keyword">inline</span> uint8_t fromHourBCD(uint8_t value)
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192 <span class="keywordflow">if</span> ((value &amp; 0x40) != 0) {
<a name="l00193"></a>00193 <span class="comment">// 12-hour mode.</span>
<a name="l00194"></a>00194 uint8_t result = ((value &gt;&gt; 4) &amp; 0x01) * 10 + (value &amp; 0x0F);
<a name="l00195"></a>00195 <span class="keywordflow">if</span> ((value &amp; 0x20) != 0)
<a name="l00196"></a>00196 <span class="keywordflow">return</span> (result == 12) ? 12 : (result + 12); <span class="comment">// PM</span>
<a name="l00197"></a>00197 <span class="keywordflow">else</span>
<a name="l00198"></a>00198 <span class="keywordflow">return</span> (result == 12) ? 0 : result; <span class="comment">// AM</span>
<a name="l00199"></a>00199 } <span class="keywordflow">else</span> {
<a name="l00200"></a>00200 <span class="comment">// 24-hour mode.</span>
<a name="l00201"></a>00201 <span class="keywordflow">return</span> fromBCD(value);
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204
<a name="l00205"></a><a class="code" href="classDS3232RTC.html#af89e68c68f1c4b7e94286f800b5b2747">00205</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#af89e68c68f1c4b7e94286f800b5b2747" title="Reads the current time from the realtime clock into value.">DS3232RTC::readTime</a>(<a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00208"></a>00208 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00209"></a>00209 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_SECOND);
<a name="l00210"></a>00210 <span class="keywordflow">if</span> (_bus-&gt;<a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS3232_I2C_ADDRESS, 3)) {
<a name="l00211"></a>00211 value-&gt;<a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00212"></a>00212 value-&gt;<a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00213"></a>00213 value-&gt;<a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = fromHourBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00214"></a>00214 } <span class="keywordflow">else</span> {
<a name="l00215"></a>00215 <span class="comment">// RTC chip is not responding.</span>
<a name="l00216"></a>00216 value-&gt;<a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = 0;
<a name="l00217"></a>00217 value-&gt;<a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = 0;
<a name="l00218"></a>00218 value-&gt;<a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = 0;
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 } <span class="keywordflow">else</span> {
<a name="l00221"></a>00221 <a class="code" href="classDS3232RTC.html#af89e68c68f1c4b7e94286f800b5b2747" title="Reads the current time from the realtime clock into value.">RTC::readTime</a>(value);
<a name="l00222"></a>00222 }
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224
<a name="l00225"></a><a class="code" href="classDS3232RTC.html#ab03358e3b5996e38d766e2f9f6ab62ca">00225</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#ab03358e3b5996e38d766e2f9f6ab62ca" title="Reads the current date from the realtime clock into value.">DS3232RTC::readDate</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227 <span class="keywordflow">if</span> (!_isRealTime) {
<a name="l00228"></a>00228 <a class="code" href="classDS3232RTC.html#ab03358e3b5996e38d766e2f9f6ab62ca" title="Reads the current date from the realtime clock into value.">RTC::readDate</a>(value);
<a name="l00229"></a>00229 <span class="keywordflow">return</span>;
<a name="l00230"></a>00230 }
<a name="l00231"></a>00231 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00232"></a>00232 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_DATE);
<a name="l00233"></a>00233 <span class="keywordflow">if</span> (_bus-&gt;<a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS3232_I2C_ADDRESS, 3)) {
<a name="l00234"></a>00234 value-&gt;<a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00235"></a>00235 value-&gt;<a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>() &amp; 0x7F); <span class="comment">// Strip century bit.</span>
<a name="l00236"></a>00236 value-&gt;<a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>()) + 2000;
<a name="l00237"></a>00237 } <span class="keywordflow">else</span> {
<a name="l00238"></a>00238 <span class="comment">// RTC chip is not responding.</span>
<a name="l00239"></a>00239 value-&gt;<a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;
<a name="l00240"></a>00240 value-&gt;<a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;
<a name="l00241"></a>00241 value-&gt;<a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244
<a name="l00245"></a>00245 <span class="keyword">inline</span> uint8_t toBCD(uint8_t value)
<a name="l00246"></a>00246 {
<a name="l00247"></a>00247 <span class="keywordflow">return</span> ((value / 10) &lt;&lt; 4) + (value % 10);
<a name="l00248"></a>00248 }
<a name="l00249"></a>00249
<a name="l00250"></a><a class="code" href="classDS3232RTC.html#ab0ca13a8b80da856b37fc53b84e27c78">00250</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#ab0ca13a8b80da856b37fc53b84e27c78" title="Updates the time in the realtime clock to match value.">DS3232RTC::writeTime</a>(<span class="keyword">const</span> <a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
<a name="l00251"></a>00251 {
<a name="l00252"></a>00252 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00253"></a>00253 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00254"></a>00254 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_SECOND);
<a name="l00255"></a>00255 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a>));
<a name="l00256"></a>00256 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a>));
<a name="l00257"></a>00257 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a>)); <span class="comment">// Changes mode to 24-hour clock.</span>
<a name="l00258"></a>00258 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00259"></a>00259 } <span class="keywordflow">else</span> {
<a name="l00260"></a>00260 <a class="code" href="classDS3232RTC.html#ab0ca13a8b80da856b37fc53b84e27c78" title="Updates the time in the realtime clock to match value.">RTC::writeTime</a>(value);
<a name="l00261"></a>00261 }
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263
<a name="l00264"></a><a class="code" href="classDS3232RTC.html#a31c004a90c724979d8267c31f2dbf5ed">00264</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a31c004a90c724979d8267c31f2dbf5ed" title="Updates the date in the realtime clock to match value.">DS3232RTC::writeDate</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
<a name="l00265"></a>00265 {
<a name="l00266"></a>00266 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00267"></a>00267 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00268"></a>00268 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_DATE);
<a name="l00269"></a>00269 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>));
<a name="l00270"></a>00270 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>));
<a name="l00271"></a>00271 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> % 100));
<a name="l00272"></a>00272 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00273"></a>00273 } <span class="keywordflow">else</span> {
<a name="l00274"></a>00274 <a class="code" href="classDS3232RTC.html#a31c004a90c724979d8267c31f2dbf5ed" title="Updates the date in the realtime clock to match value.">RTC::writeDate</a>(value);
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277
<a name="l00278"></a><a class="code" href="classDS3232RTC.html#a09c7073c687dcbbc423baf48074c7873">00278</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a09c7073c687dcbbc423baf48074c7873" title="Reads the details of the alarm with index alarmNum into value.">DS3232RTC::readAlarm</a>(uint8_t alarmNum, <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00281"></a>00281 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00282"></a>00282 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_ALARMS + alarmNum * DS3232_ALARM_SIZE);
<a name="l00283"></a>00283 <span class="keywordflow">if</span> (_bus-&gt;<a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS3232_I2C_ADDRESS, 3)) {
<a name="l00284"></a>00284 value-&gt;<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00285"></a>00285 value-&gt;<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = fromBCD(_bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
<a name="l00286"></a>00286 value-&gt;<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = _bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
<a name="l00287"></a>00287 } <span class="keywordflow">else</span> {
<a name="l00288"></a>00288 <span class="comment">// RTC chip is not responding.</span>
<a name="l00289"></a>00289 value-&gt;<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 0;
<a name="l00290"></a>00290 value-&gt;<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;
<a name="l00291"></a>00291 value-&gt;<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;
<a name="l00292"></a>00292 }
<a name="l00293"></a>00293 } <span class="keywordflow">else</span> {
<a name="l00294"></a>00294 <a class="code" href="classDS3232RTC.html#a09c7073c687dcbbc423baf48074c7873" title="Reads the details of the alarm with index alarmNum into value.">RTC::readAlarm</a>(alarmNum, value);
<a name="l00295"></a>00295 }
<a name="l00296"></a>00296 }
<a name="l00297"></a>00297
<a name="l00298"></a><a class="code" href="classDS3232RTC.html#a8b0a65e0ac479aec8fad6ca3147dbe75">00298</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a8b0a65e0ac479aec8fad6ca3147dbe75" title="Updates the details of the alarm with index alarmNum from value.">DS3232RTC::writeAlarm</a>(uint8_t alarmNum, <span class="keyword">const</span> <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
<a name="l00299"></a>00299 {
<a name="l00300"></a>00300 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00301"></a>00301 <span class="comment">// Write the alarm details to NVRAM.</span>
<a name="l00302"></a>00302 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00303"></a>00303 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_ALARMS + alarmNum * DS3232_ALARM_SIZE);
<a name="l00304"></a>00304 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a>));
<a name="l00305"></a>00305 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a>));
<a name="l00306"></a>00306 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value-&gt;<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a>);
<a name="l00307"></a>00307 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00308"></a>00308
<a name="l00309"></a>00309 <span class="comment">// Keep the DS3232&#39;s built-in alarms in sync with the first two alarms.</span>
<a name="l00310"></a>00310 <span class="keywordflow">if</span> (alarmNum == 0) {
<a name="l00311"></a>00311 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00312"></a>00312 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_ALARM1_SEC);
<a name="l00313"></a>00313 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0);
<a name="l00314"></a>00314 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a>));
<a name="l00315"></a>00315 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a>));
<a name="l00316"></a>00316 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0x81); <span class="comment">// Match hours, mins, secs; day = 1</span>
<a name="l00317"></a>00317 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00318"></a>00318 <span class="keywordflow">if</span> (alarmInterrupts)
<a name="l00319"></a>00319 updateAlarmInterrupts();
<a name="l00320"></a>00320 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (alarmNum == 1) {
<a name="l00321"></a>00321 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00322"></a>00322 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_ALARM2_MIN);
<a name="l00323"></a>00323 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a>));
<a name="l00324"></a>00324 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-&gt;<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a>));
<a name="l00325"></a>00325 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0x81); <span class="comment">// Match hours, mins; day = 1</span>
<a name="l00326"></a>00326 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00327"></a>00327 <span class="keywordflow">if</span> (alarmInterrupts)
<a name="l00328"></a>00328 updateAlarmInterrupts();
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330 } <span class="keywordflow">else</span> {
<a name="l00331"></a>00331 <a class="code" href="classDS3232RTC.html#a8b0a65e0ac479aec8fad6ca3147dbe75" title="Updates the details of the alarm with index alarmNum from value.">RTC::writeAlarm</a>(alarmNum, value);
<a name="l00332"></a>00332 }
<a name="l00333"></a>00333 }
<a name="l00334"></a>00334
<a name="l00335"></a><a class="code" href="classDS3232RTC.html#a1319fe936dcb7e9d6bdf200b77a94f8e">00335</a> <span class="keywordtype">int</span> <a class="code" href="classDS3232RTC.html#a1319fe936dcb7e9d6bdf200b77a94f8e" title="Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings...">DS3232RTC::byteCount</a>()<span class="keyword"> const</span>
<a name="l00336"></a>00336 <span class="keyword"></span>{
<a name="l00337"></a>00337 <span class="keywordflow">return</span> DS3232_ALARMS - DS3232_NVRAM;
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339
<a name="l00340"></a><a class="code" href="classDS3232RTC.html#a5ba83a3ef7d65d45c2f3241afdd8fef7">00340</a> uint8_t <a class="code" href="classDS3232RTC.html#a5ba83a3ef7d65d45c2f3241afdd8fef7" title="Reads the byte at offset within the realtime clock&#39;s non-volatile memory.">DS3232RTC::readByte</a>(uint8_t offset)
<a name="l00341"></a>00341 {
<a name="l00342"></a>00342 <span class="keywordflow">if</span> (_isRealTime)
<a name="l00343"></a>00343 <span class="keywordflow">return</span> readRegister(DS3232_NVRAM + offset);
<a name="l00344"></a>00344 <span class="keywordflow">else</span>
<a name="l00345"></a>00345 <span class="keywordflow">return</span> <a class="code" href="classDS3232RTC.html#a5ba83a3ef7d65d45c2f3241afdd8fef7" title="Reads the byte at offset within the realtime clock&#39;s non-volatile memory.">RTC::readByte</a>(offset);
<a name="l00346"></a>00346 }
<a name="l00347"></a>00347
<a name="l00348"></a><a class="code" href="classDS3232RTC.html#a9acebf12c5cecdd6d84e0ff9ed41765a">00348</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a9acebf12c5cecdd6d84e0ff9ed41765a" title="Writes value to offset within the realtime clock&#39;s non-volatile memory.">DS3232RTC::writeByte</a>(uint8_t offset, uint8_t value)
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350 <span class="keywordflow">if</span> (_isRealTime)
<a name="l00351"></a>00351 writeRegister(DS3232_NVRAM + offset, value);
<a name="l00352"></a>00352 <span class="keywordflow">else</span>
<a name="l00353"></a>00353 <a class="code" href="classDS3232RTC.html#a9acebf12c5cecdd6d84e0ff9ed41765a" title="Writes value to offset within the realtime clock&#39;s non-volatile memory.">RTC::writeByte</a>(offset, value);
<a name="l00354"></a>00354 }
<a name="l00355"></a>00355
<a name="l00356"></a><a class="code" href="classDS3232RTC.html#a0faf40c25ab019a326a60f301c2bb41b">00356</a> <span class="keywordtype">int</span> <a class="code" href="classDS3232RTC.html#a0faf40c25ab019a326a60f301c2bb41b" title="Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius...">DS3232RTC::readTemperature</a>()
<a name="l00357"></a>00357 {
<a name="l00358"></a>00358 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00359"></a>00359 <span class="keywordflow">return</span> (((<span class="keywordtype">int</span>)(<span class="keywordtype">signed</span> <span class="keywordtype">char</span>)readRegister(DS3232_TEMP_MSB)) &lt;&lt; 2) |
<a name="l00360"></a>00360 (readRegister(DS3232_TEMP_LSB) &gt;&gt; 6);
<a name="l00361"></a>00361 } <span class="keywordflow">else</span> {
<a name="l00362"></a>00362 <span class="keywordflow">return</span> <a class="code" href="classRTC.html#a9ed5480b362a83f1f45c4d3bcf7c3bf8" title="Value that is returned from readTemperature() if the realtime clock chip cannot determine the tempera...">NO_TEMPERATURE</a>;
<a name="l00363"></a>00363 }
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365
<a name="l00380"></a><a class="code" href="classDS3232RTC.html#ab91e79271a1f8e75b07bddbb04445dc9">00380</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#ab91e79271a1f8e75b07bddbb04445dc9" title="Enables the generation of interrupts for alarms 0 and 1.">DS3232RTC::enableAlarmInterrupts</a>()
<a name="l00381"></a>00381 {
<a name="l00382"></a>00382 <span class="keywordflow">if</span> (_oneHzPin == 255 &amp;&amp; _isRealTime) {
<a name="l00383"></a>00383 updateAlarmInterrupts();
<a name="l00384"></a>00384 alarmInterrupts = <span class="keyword">true</span>;
<a name="l00385"></a>00385 }
<a name="l00386"></a>00386 }
<a name="l00387"></a>00387
<a name="l00393"></a><a class="code" href="classDS3232RTC.html#a225b8c62d617aa1b7be7d20e8a033be9">00393</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a225b8c62d617aa1b7be7d20e8a033be9" title="Disables the generation of interrupts for alarms 0 and 1.">DS3232RTC::disableAlarmInterrupts</a>()
<a name="l00394"></a>00394 {
<a name="l00395"></a>00395 <span class="keywordflow">if</span> (alarmInterrupts) {
<a name="l00396"></a>00396 uint8_t value = readRegister(DS3232_CONTROL);
<a name="l00397"></a>00397 value &amp;= ~(DS3232_INTCN | DS3232_A2IE | DS3232_A1IE);
<a name="l00398"></a>00398 writeRegister(DS3232_CONTROL, value);
<a name="l00399"></a>00399 alarmInterrupts = <span class="keyword">false</span>;
<a name="l00400"></a>00400 }
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402
<a name="l00416"></a><a class="code" href="classDS3232RTC.html#a79649f100a4562b9c1ba7c69e85cbca3">00416</a> <span class="keywordtype">int</span> <a class="code" href="classDS3232RTC.html#a79649f100a4562b9c1ba7c69e85cbca3" title="Determines which of alarms 0 or 1 have fired since the last call.">DS3232RTC::firedAlarm</a>()
<a name="l00417"></a>00417 {
<a name="l00418"></a>00418 <span class="keywordflow">if</span> (!_isRealTime)
<a name="l00419"></a>00419 <span class="keywordflow">return</span> -1;
<a name="l00420"></a>00420 uint8_t value = readRegister(DS3232_STATUS);
<a name="l00421"></a>00421 <span class="keywordtype">int</span> alarm;
<a name="l00422"></a>00422 <span class="keywordflow">if</span> (value &amp; DS3232_A1F) {
<a name="l00423"></a>00423 <span class="keywordflow">if</span> (value &amp; DS3232_A2F)
<a name="l00424"></a>00424 alarm = 2;
<a name="l00425"></a>00425 <span class="keywordflow">else</span>
<a name="l00426"></a>00426 alarm = 0;
<a name="l00427"></a>00427 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (value &amp; DS3232_A2F) {
<a name="l00428"></a>00428 alarm = 1;
<a name="l00429"></a>00429 } <span class="keywordflow">else</span> {
<a name="l00430"></a>00430 alarm = -1;
<a name="l00431"></a>00431 }
<a name="l00432"></a>00432 <span class="keywordflow">if</span> (alarm != -1) {
<a name="l00433"></a>00433 value &amp;= ~(DS3232_A1F | DS3232_A2F);
<a name="l00434"></a>00434 writeRegister(DS3232_STATUS, value);
<a name="l00435"></a>00435 }
<a name="l00436"></a>00436 <span class="keywordflow">return</span> alarm;
<a name="l00437"></a>00437 }
<a name="l00438"></a>00438
<a name="l00444"></a><a class="code" href="classDS3232RTC.html#a3966de6f4241d86f198a8b9dd5e7e59a">00444</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#a3966de6f4241d86f198a8b9dd5e7e59a" title="Enables the 32 kHz output on the DS3232 chip.">DS3232RTC::enable32kHzOutput</a>()
<a name="l00445"></a>00445 {
<a name="l00446"></a>00446 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00447"></a>00447 uint8_t value = readRegister(DS3232_STATUS);
<a name="l00448"></a>00448 value |= DS3232_BB32KHZ | DS3232_EN32KHZ;
<a name="l00449"></a>00449 writeRegister(DS3232_STATUS, value);
<a name="l00450"></a>00450 }
<a name="l00451"></a>00451 }
<a name="l00452"></a>00452
<a name="l00458"></a><a class="code" href="classDS3232RTC.html#ada732bae42fc2833e59ae293aa27ddcb">00458</a> <span class="keywordtype">void</span> <a class="code" href="classDS3232RTC.html#ada732bae42fc2833e59ae293aa27ddcb" title="Disables the 32 kHz output on the DS3232 chip.">DS3232RTC::disable32kHzOutput</a>()
<a name="l00459"></a>00459 {
<a name="l00460"></a>00460 <span class="keywordflow">if</span> (_isRealTime) {
<a name="l00461"></a>00461 uint8_t value = readRegister(DS3232_STATUS);
<a name="l00462"></a>00462 value &amp;= ~(DS3232_BB32KHZ | DS3232_EN32KHZ);
<a name="l00463"></a>00463 writeRegister(DS3232_STATUS, value);
<a name="l00464"></a>00464 }
<a name="l00465"></a>00465 }
<a name="l00466"></a>00466
<a name="l00467"></a>00467 <span class="keywordtype">void</span> DS3232RTC::initAlarms()
<a name="l00468"></a>00468 {
<a name="l00469"></a>00469 uint8_t value = readRegister(DS3232_ALARM_MAGIC);
<a name="l00470"></a>00470 <span class="keywordflow">if</span> (value != (0xB0 + <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>)) {
<a name="l00471"></a>00471 <span class="comment">// This is the first time we have used this clock chip,</span>
<a name="l00472"></a>00472 <span class="comment">// so initialize all alarms to their default state.</span>
<a name="l00473"></a>00473 <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> alarm;
<a name="l00474"></a>00474 alarm.<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 6; <span class="comment">// Default to 6am for alarms.</span>
<a name="l00475"></a>00475 alarm.<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;
<a name="l00476"></a>00476 alarm.<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;
<a name="l00477"></a>00477 <span class="keywordflow">for</span> (uint8_t index = 0; index &lt; <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>; ++index)
<a name="l00478"></a>00478 <a class="code" href="classDS3232RTC.html#a8b0a65e0ac479aec8fad6ca3147dbe75" title="Updates the details of the alarm with index alarmNum from value.">writeAlarm</a>(index, &amp;alarm);
<a name="l00479"></a>00479 writeRegister(DS3232_ALARM_MAGIC, 0xB0 + ALARM_COUNT);
<a name="l00480"></a>00480
<a name="l00481"></a>00481 <span class="comment">// Also clear the rest of NVRAM so that it is in a known state.</span>
<a name="l00482"></a>00482 <span class="comment">// Otherwise we&#39;ll have whatever garbage was present at power-on.</span>
<a name="l00483"></a>00483 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00484"></a>00484 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS3232_NVRAM);
<a name="l00485"></a>00485 <span class="keywordflow">for</span> (uint8_t index = DS3232_NVRAM; index &lt; DS3232_ALARMS; ++index)
<a name="l00486"></a>00486 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0);
<a name="l00487"></a>00487 _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00488"></a>00488 }
<a name="l00489"></a>00489 }
<a name="l00490"></a>00490
<a name="l00491"></a>00491 uint8_t DS3232RTC::readRegister(uint8_t reg)
<a name="l00492"></a>00492 {
<a name="l00493"></a>00493 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00494"></a>00494 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);
<a name="l00495"></a>00495 <span class="keywordflow">if</span> (!_bus-&gt;<a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS3232_I2C_ADDRESS, 1))
<a name="l00496"></a>00496 <span class="keywordflow">return</span> 0; <span class="comment">// RTC chip is not responding.</span>
<a name="l00497"></a>00497 <span class="keywordflow">return</span> _bus-&gt;<a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
<a name="l00498"></a>00498 }
<a name="l00499"></a>00499
<a name="l00500"></a>00500 <span class="keywordtype">bool</span> DS3232RTC::writeRegister(uint8_t reg, uint8_t value)
<a name="l00501"></a>00501 {
<a name="l00502"></a>00502 _bus-&gt;<a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS3232_I2C_ADDRESS);
<a name="l00503"></a>00503 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);
<a name="l00504"></a>00504 _bus-&gt;<a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);
<a name="l00505"></a>00505 <span class="keywordflow">return</span> _bus-&gt;<a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
<a name="l00506"></a>00506 }
<a name="l00507"></a>00507
<a name="l00508"></a>00508 <span class="preprocessor">#define DS3232_ALARM1_FLAGS (DS3232_ALARMS + 2)</span>
<a name="l00509"></a>00509 <span class="preprocessor"></span><span class="preprocessor">#define DS3232_ALARM2_FLAGS (DS3232_ALARMS + DS3232_ALARM_SIZE + 2)</span>
<a name="l00510"></a>00510 <span class="preprocessor"></span>
<a name="l00511"></a>00511 <span class="keywordtype">void</span> DS3232RTC::updateAlarmInterrupts()
<a name="l00512"></a>00512 {
<a name="l00513"></a>00513 <span class="keywordtype">bool</span> alarm1Enabled = ((readRegister(DS3232_ALARM1_FLAGS) &amp; 0x01) != 0);
<a name="l00514"></a>00514 <span class="keywordtype">bool</span> alarm2Enabled = ((readRegister(DS3232_ALARM2_FLAGS) &amp; 0x01) != 0);
<a name="l00515"></a>00515 uint8_t value = readRegister(DS3232_CONTROL);
<a name="l00516"></a>00516 value |= DS3232_INTCN;
<a name="l00517"></a>00517 <span class="keywordflow">if</span> (alarm1Enabled)
<a name="l00518"></a>00518 value |= DS3232_A1IE;
<a name="l00519"></a>00519 <span class="keywordflow">else</span>
<a name="l00520"></a>00520 value &amp;= ~DS3232_A1IE;
<a name="l00521"></a>00521 <span class="keywordflow">if</span> (alarm2Enabled)
<a name="l00522"></a>00522 value |= DS3232_A2IE;
<a name="l00523"></a>00523 <span class="keywordflow">else</span>
<a name="l00524"></a>00524 value &amp;= ~DS3232_A2IE;
<a name="l00525"></a>00525 writeRegister(DS3232_CONTROL, value);
<a name="l00526"></a>00526 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Jun 13 2012 15:22:29 for ArduinoLibs by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>