Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
3 | <title>Procyon AVRlib: ds1631.c Source File</title> |
||
4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
5 | </head><body> |
||
6 | <!-- Generated by Doxygen 1.4.2 --> |
||
7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
8 | <h1>ds1631.c</h1><a href="ds1631_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file ds1631.c \brief Dallas DS1631 Temperature Sensor Driver Library. */</span> |
||
9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
10 | 00003 <span class="comment">//</span> |
||
11 | 00004 <span class="comment">// File Name : 'ds1631.c'</span> |
||
12 | 00005 <span class="comment">// Title : Dallas DS1631 Temperature Sensor Driver Library</span> |
||
13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span> |
||
14 | 00007 <span class="comment">// Created : 2004.02.10</span> |
||
15 | 00008 <span class="comment">// Revised : 2004.02.19</span> |
||
16 | 00009 <span class="comment">// Version : 0.1</span> |
||
17 | 00010 <span class="comment">// Target MCU : Atmel AVR Series</span> |
||
18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
19 | 00012 <span class="comment">//</span> |
||
20 | 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span> |
||
21 | 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span> |
||
22 | 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span> |
||
23 | 00016 <span class="comment">//</span> |
||
24 | 00017 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
25 | 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
26 | 00019 <span class="comment">//</span> |
||
27 | 00020 <span class="comment">//*****************************************************************************</span> |
||
28 | 00021 |
||
29 | 00022 <span class="preprocessor">#include <avr/io.h></span> |
||
30 | 00023 <span class="preprocessor">#include <avr/interrupt.h></span> |
||
31 | 00024 |
||
32 | 00025 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
33 | 00026 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span> |
||
34 | 00027 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span> |
||
35 | 00028 <span class="preprocessor">#include "<a class="code" href="ds1631_8h.html">ds1631.h</a>"</span> |
||
36 | 00029 |
||
37 | 00030 <span class="comment">// global variables</span> |
||
38 | 00031 |
||
39 | 00032 <span class="comment">// Functions</span> |
||
40 | <a name="l00033"></a><a class="code" href="ds1631_8h.html#a16">00033</a> u08 <a class="code" href="ds1631_8c.html#a0">ds1631Init</a>(u08 i2cAddr) |
||
41 | 00034 { |
||
42 | 00035 u08 chip_ok; |
||
43 | 00036 <span class="comment">// issue a reset</span> |
||
44 | 00037 <span class="keywordflow">if</span>(<a class="code" href="ds1631_8c.html#a1">ds1631Reset</a>(i2cAddr) == I2C_OK) |
||
45 | 00038 chip_ok = TRUE; |
||
46 | 00039 <span class="keywordflow">else</span> |
||
47 | 00040 chip_ok = FALSE; |
||
48 | 00041 <span class="comment">// set a default configuration</span> |
||
49 | 00042 <span class="comment">// (1-shot mode, T_OUT active high, and 12-bit conversion)</span> |
||
50 | 00043 <a class="code" href="ds1631_8c.html#a2">ds1631SetConfig</a>(i2cAddr, |
||
51 | 00044 DS1631_CONFIG_1SHOT | DS1631_CONFIG_POL | |
||
52 | 00045 DS1631_CONFIG_R0 | DS1631_CONFIG_R1); |
||
53 | 00046 <span class="keywordflow">return</span> chip_ok; |
||
54 | 00047 } |
||
55 | 00048 |
||
56 | <a name="l00049"></a><a class="code" href="ds1631_8h.html#a17">00049</a> u08 <a class="code" href="ds1631_8c.html#a1">ds1631Reset</a>(u08 i2cAddr) |
||
57 | 00050 { |
||
58 | 00051 u08 buffer[1]; |
||
59 | 00052 <span class="comment">// return the DS1631 to power-on reset defaults</span> |
||
60 | 00053 buffer[0] = <a class="code" href="ds1631_8h.html#a7">DS1631_CMD_SWPOR</a>; |
||
61 | 00054 <span class="keywordflow">return</span> <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer); |
||
62 | 00055 } |
||
63 | 00056 |
||
64 | <a name="l00057"></a><a class="code" href="ds1631_8h.html#a18">00057</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a2">ds1631SetConfig</a>(u08 i2cAddr, u08 config) |
||
65 | 00058 { |
||
66 | 00059 u08 buffer[2]; |
||
67 | 00060 <span class="comment">// write the DS1631 configuration byte</span> |
||
68 | 00061 buffer[0] = <a class="code" href="ds1631_8h.html#a6">DS1631_CMD_ACCESSCONFIG</a>; |
||
69 | 00062 buffer[1] = config; |
||
70 | 00063 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer); |
||
71 | 00064 } |
||
72 | 00065 |
||
73 | <a name="l00066"></a><a class="code" href="ds1631_8h.html#a19">00066</a> u08 <a class="code" href="ds1631_8c.html#a3">ds1631GetConfig</a>(u08 i2cAddr) |
||
74 | 00067 { |
||
75 | 00068 u08 buffer[1]; |
||
76 | 00069 <span class="comment">// write the DS1631 configuration byte</span> |
||
77 | 00070 buffer[0] = <a class="code" href="ds1631_8h.html#a6">DS1631_CMD_ACCESSCONFIG</a>; |
||
78 | 00071 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer); |
||
79 | 00072 <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer); |
||
80 | 00073 <span class="keywordflow">return</span> buffer[0]; |
||
81 | 00074 } |
||
82 | 00075 |
||
83 | <a name="l00076"></a><a class="code" href="ds1631_8h.html#a20">00076</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a4">ds1631StartConvert</a>(u08 i2cAddr) |
||
84 | 00077 { |
||
85 | 00078 u08 buffer[1]; |
||
86 | 00079 <span class="comment">// send the DS1631 Start Convert command</span> |
||
87 | 00080 buffer[0] = <a class="code" href="ds1631_8h.html#a1">DS1631_CMD_STARTCONV</a>; |
||
88 | 00081 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer); |
||
89 | 00082 } |
||
90 | 00083 |
||
91 | <a name="l00084"></a><a class="code" href="ds1631_8h.html#a21">00084</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a5">ds1631StopConvert</a>(u08 i2cAddr) |
||
92 | 00085 { |
||
93 | 00086 u08 buffer[1]; |
||
94 | 00087 <span class="comment">// send the DS1631 Stop Convert command</span> |
||
95 | 00088 buffer[0] = <a class="code" href="ds1631_8h.html#a2">DS1631_CMD_STOPCONV</a>; |
||
96 | 00089 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer); |
||
97 | 00090 } |
||
98 | 00091 |
||
99 | <a name="l00092"></a><a class="code" href="ds1631_8h.html#a22">00092</a> s16 <a class="code" href="ds1631_8c.html#a6">ds1631ReadTemp</a>(u08 i2cAddr) |
||
100 | 00093 { |
||
101 | 00094 <span class="comment">// read the Temperature register and return the result</span> |
||
102 | 00095 <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a3">DS1631_CMD_READTEMP</a>); |
||
103 | 00096 } |
||
104 | 00097 |
||
105 | <a name="l00098"></a><a class="code" href="ds1631_8h.html#a23">00098</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a7">ds1631SetTH</a>(u08 i2cAddr, s16 value) |
||
106 | 00099 { |
||
107 | 00100 <span class="comment">// write the TH register</span> |
||
108 | 00101 ds1631WriteTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a4">DS1631_CMD_ACCESSTH</a>, value); |
||
109 | 00102 } |
||
110 | 00103 |
||
111 | <a name="l00104"></a><a class="code" href="ds1631_8h.html#a24">00104</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a8">ds1631SetTL</a>(u08 i2cAddr, s16 value) |
||
112 | 00105 { |
||
113 | 00106 <span class="comment">// write the TL register</span> |
||
114 | 00107 ds1631WriteTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a5">DS1631_CMD_ACCESSTL</a>, value); |
||
115 | 00108 } |
||
116 | 00109 |
||
117 | <a name="l00110"></a><a class="code" href="ds1631_8h.html#a25">00110</a> s16 <a class="code" href="ds1631_8c.html#a9">ds1631GetTH</a>(u08 i2cAddr) |
||
118 | 00111 { |
||
119 | 00112 <span class="comment">// read the TH register and return the result</span> |
||
120 | 00113 <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a4">DS1631_CMD_ACCESSTH</a>); |
||
121 | 00114 } |
||
122 | 00115 |
||
123 | <a name="l00116"></a><a class="code" href="ds1631_8h.html#a26">00116</a> s16 <a class="code" href="ds1631_8c.html#a10">ds1631GetTL</a>(u08 i2cAddr) |
||
124 | 00117 { |
||
125 | 00118 <span class="comment">// read the TL register and return the result</span> |
||
126 | 00119 <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a5">DS1631_CMD_ACCESSTL</a>); |
||
127 | 00120 } |
||
128 | 00121 |
||
129 | 00122 |
||
130 | 00123 s16 ds1631ReadTempReg(u08 i2cAddr, u08 cmd) |
||
131 | 00124 { |
||
132 | 00125 u08 buffer[2]; |
||
133 | 00126 s16 T; |
||
134 | 00127 |
||
135 | 00128 <span class="comment">// read the temperature value from the requested register</span> |
||
136 | 00129 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &cmd); |
||
137 | 00130 <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer); |
||
138 | 00131 <span class="comment">// pack bytes</span> |
||
139 | 00132 T = (s16)((buffer[0]<<8) | buffer[1]); |
||
140 | 00133 <span class="comment">// return result</span> |
||
141 | 00134 <span class="keywordflow">return</span> T; |
||
142 | 00135 } |
||
143 | 00136 |
||
144 | 00137 <span class="keywordtype">void</span> ds1631WriteTempReg(u08 i2cAddr, u08 cmd, s16 value) |
||
145 | 00138 { |
||
146 | 00139 u08 buffer[3]; |
||
147 | 00140 |
||
148 | 00141 <span class="comment">// write the requested register with a temperature value</span> |
||
149 | 00142 buffer[0] = cmd; |
||
150 | 00143 buffer[1] = value>>8; |
||
151 | 00144 buffer[2] = value; |
||
152 | 00145 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 3, buffer); |
||
153 | 00146 } |
||
154 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by |
||
155 | <a href="http://www.doxygen.org/index.html"> |
||
156 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
157 | </body> |
||
158 | </html> |
Powered by WebSVN v2.8.3