📄 lis3l02_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: lis3l02.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><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><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>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'lis3l02.c'</span>00005 <span class="comment">// Title : ST LIS3L02 3-axis I2C Accelerometer Library</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created : 2004.10.23</span>00008 <span class="comment">// Revised : 2004.12.14</span>00009 <span class="comment">// Version : 0.1</span>00010 <span class="comment">// Target MCU : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#include <avr/io.h></span>00023 <span class="preprocessor">#include <avr/signal.h></span>00024 <span class="preprocessor">#include <avr/interrupt.h></span>00025 00026 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00027 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="lis3l02_8h.html">lis3l02.h</a>"</span>00029 00030 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00031 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00032 00033 <span class="comment">// global variables</span>00034 00035 <span class="comment">// Functions</span><a name="l00036"></a><a class="code" href="lis3l02_8h.html#a58">00036</a> u08 <a class="code" href="lis3l02_8c.html#a0">lis3l02Init</a>(<span class="keywordtype">void</span>)00037 {00038 <span class="comment">// reset LIS3L02 chip</span>00039 <span class="keywordflow">return</span> <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>();00040 }00041 <a name="l00042"></a><a class="code" href="lis3l02_8h.html#a59">00042</a> u08 <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>(<span class="keywordtype">void</span>)00043 {00044 <span class="comment">// turn on device and enable X,Y,Z</span>00045 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a7">LIS3L02_REG_CTRLREG1</a>,00046 <a class="code" href="lis3l02_8h.html#a22">LIS3L02_CTRLREG1_XEN</a> |00047 <a class="code" href="lis3l02_8h.html#a23">LIS3L02_CTRLREG1_YEN</a> |00048 <a class="code" href="lis3l02_8h.html#a24">LIS3L02_CTRLREG1_ZEN</a> |00049 <a class="code" href="lis3l02_8h.html#a28">LIS3L02_CTRLREG1_PD0</a>);00050 00051 <span class="comment">// scale and justification options</span>00052 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a8">LIS3L02_REG_CTRLREG2</a>,00053 <a class="code" href="lis3l02_8h.html#a34">LIS3L02_CTRLREG2_BOOT</a> | 00054 <a class="code" href="lis3l02_8h.html#a30">LIS3L02_CTRLREG2_DAS</a> );00055 00056 <span class="keywordflow">return</span> 0;00057 }00058 <a name="l00059"></a><a class="code" href="lis3l02_8h.html#a60">00059</a> u08 <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(u08 reg)00060 {00061 u08 data;00062 u08 i2cStat;00063 00064 <span class="comment">// set register</span>00065 i2cStat = <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &reg);00066 <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)00067 {00068 rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);00069 <span class="keywordflow">return</span> i2cStat;00070 }00071 <span class="comment">// read register</span>00072 i2cStat = <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &data);00073 00074 <span class="comment">//rprintf("READ: Reg=0x%x Data=0x%x\r\n", reg, data);</span>00075 00076 <span class="keywordflow">return</span> data;00077 }00078 <a name="l00079"></a><a class="code" href="lis3l02_8h.html#a61">00079</a> u08 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(u08 reg, u08 data)00080 {00081 u08 packet[2];00082 u08 i2cStat;00083 00084 <span class="comment">// prepare packet</span>00085 packet[0] = reg;00086 packet[1] = data;00087 <span class="comment">// write register</span>00088 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);00089 <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)00090 {00091 rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);00092 <span class="keywordflow">return</span> i2cStat;00093 }00094 00095 <span class="comment">//rprintf("WRITE: Reg=0x%x Data=0x%x\r\n", reg, data);</span>00096 00097 <span class="keywordflow">return</span> (i2cStat == I2C_OK);00098 }00099 <a name="l00100"></a><a class="code" href="lis3l02_8h.html#a62">00100</a> s16 <a class="code" href="lis3l02_8c.html#a4">lis3l02GetAccel</a>(u08 chxyz)00101 {00102 s16 value;00103 00104 value = <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a13">LIS3L02_REG_OUTXL</a> + (chxyz<<1));00105 value |= <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a14">LIS3L02_REG_OUTXH</a> + (chxyz<<1))<<8;00106 00107 <span class="keywordflow">return</span> value;00108 }00109 00110 00111 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:54 2005 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -