?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

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: lis3l02.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&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>lis3l02.c</h1><a href="lis3l02_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file lis3l02.c \brief ST LIS3L02 3-axis I2C Accelerometer Library. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'lis3l02.c'</span>
12 00005 <span class="comment">// Title : ST LIS3L02 3-axis I2C Accelerometer Library</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span>
14 00007 <span class="comment">// Created : 2004.10.23</span>
15 00008 <span class="comment">// Revised : 2004.12.14</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 &lt;avr/io.h&gt;</span>
30 00023 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</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="i2c_8h.html">i2c.h</a>"</span>
34 00027 <span class="preprocessor">#include "<a class="code" href="lis3l02_8h.html">lis3l02.h</a>"</span>
35 00028
36 00029 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>
37 00030 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
38 00031
39 00032 <span class="comment">// global variables</span>
40 00033
41 00034 <span class="comment">// Functions</span>
42 <a name="l00035"></a><a class="code" href="lis3l02_8h.html#a58">00035</a> u08 <a class="code" href="lis3l02_8c.html#a0">lis3l02Init</a>(<span class="keywordtype">void</span>)
43 00036 {
44 00037 <span class="comment">// reset LIS3L02 chip</span>
45 00038 <span class="keywordflow">return</span> <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>();
46 00039 }
47 00040
48 <a name="l00041"></a><a class="code" href="lis3l02_8h.html#a59">00041</a> u08 <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>(<span class="keywordtype">void</span>)
49 00042 {
50 00043 <span class="comment">// turn on device and enable X,Y,Z</span>
51 00044 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a7">LIS3L02_REG_CTRLREG1</a>,
52 00045 <a class="code" href="lis3l02_8h.html#a22">LIS3L02_CTRLREG1_XEN</a> |
53 00046 <a class="code" href="lis3l02_8h.html#a23">LIS3L02_CTRLREG1_YEN</a> |
54 00047 <a class="code" href="lis3l02_8h.html#a24">LIS3L02_CTRLREG1_ZEN</a> |
55 00048 <a class="code" href="lis3l02_8h.html#a28">LIS3L02_CTRLREG1_PD0</a>);
56 00049
57 00050 <span class="comment">// scale and justification options</span>
58 00051 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a8">LIS3L02_REG_CTRLREG2</a>,
59 00052 <a class="code" href="lis3l02_8h.html#a34">LIS3L02_CTRLREG2_BOOT</a> |
60 00053 <a class="code" href="lis3l02_8h.html#a30">LIS3L02_CTRLREG2_DAS</a> );
61 00054
62 00055 <span class="keywordflow">return</span> 0;
63 00056 }
64 00057
65 <a name="l00058"></a><a class="code" href="lis3l02_8h.html#a60">00058</a> u08 <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(u08 reg)
66 00059 {
67 00060 u08 data;
68 00061 u08 i2cStat;
69 00062
70 00063 <span class="comment">// set register</span>
71 00064 i2cStat = <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &amp;reg);
72 00065 <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)
73 00066 {
74 00067 rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);
75 00068 <span class="keywordflow">return</span> i2cStat;
76 00069 }
77 00070 <span class="comment">// read register</span>
78 00071 i2cStat = <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &amp;data);
79 00072
80 00073 <span class="comment">//rprintf("READ: Reg=0x%x Data=0x%x\r\n", reg, data);</span>
81 00074
82 00075 <span class="keywordflow">return</span> data;
83 00076 }
84 00077
85 <a name="l00078"></a><a class="code" href="lis3l02_8h.html#a61">00078</a> u08 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(u08 reg, u08 data)
86 00079 {
87 00080 u08 packet[2];
88 00081 u08 i2cStat;
89 00082
90 00083 <span class="comment">// prepare packet</span>
91 00084 packet[0] = reg;
92 00085 packet[1] = data;
93 00086 <span class="comment">// write register</span>
94 00087 i2cStat = <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 2, packet);
95 00088 <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)
96 00089 {
97 00090 rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);
98 00091 <span class="keywordflow">return</span> i2cStat;
99 00092 }
100 00093
101 00094 <span class="comment">//rprintf("WRITE: Reg=0x%x Data=0x%x\r\n", reg, data);</span>
102 00095
103 00096 <span class="keywordflow">return</span> (i2cStat == I2C_OK);
104 00097 }
105 00098
106 <a name="l00099"></a><a class="code" href="lis3l02_8h.html#a62">00099</a> s16 <a class="code" href="lis3l02_8c.html#a4">lis3l02GetAccel</a>(u08 chxyz)
107 00100 {
108 00101 s16 value;
109 00102
110 00103 value = <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a13">LIS3L02_REG_OUTXL</a> + (chxyz&lt;&lt;1));
111 00104 value |= <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a14">LIS3L02_REG_OUTXH</a> + (chxyz&lt;&lt;1))&lt;&lt;8;
112 00105
113 00106 <span class="keywordflow">return</span> value;
114 00107 }
115 00108
116 00109
117 00110
118 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;
119 <a href="http://www.doxygen.org/index.html">
120 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
121 </body>
122 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3