⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2c_8h-source.html

📁 ATMEL的AVR单片机库文件
💻 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: i2c.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><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="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>i2c.h</h1><a href="i2c_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file i2c.h \brief I2C interface using AVR Two-Wire Interface (TWI) hardware. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'i2c.h'</span>00005 <span class="comment">// Title        : I2C interface using AVR Two-Wire Interface (TWI) hardware</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002-2003</span>00007 <span class="comment">// Created      : 2002.06.25</span>00008 <span class="comment">// Revised      : 2003.03.03</span>00009 <span class="comment">// Version      : 0.9</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">// This code is distributed under the GNU Public License</span>00014 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#ifndef I2C_H</span>00019 <span class="preprocessor"></span><span class="preprocessor">#define I2C_H</span>00020 <span class="preprocessor"></span>00021 <span class="preprocessor">#include &lt;avr/twi.h&gt;</span>00022 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00023 00024 <span class="comment">// include project-specific configuration</span>00025 <span class="preprocessor">#include "<a class="code" href="i2cconf_8h.html">i2cconf.h</a>"</span>00026 00027 <span class="comment">// defines and constants</span>00028 <span class="preprocessor">#define TWCR_CMD_MASK       0x0F</span>00029 <span class="preprocessor"></span><span class="preprocessor">#define TWSR_STATUS_MASK    0xF8</span>00030 <span class="preprocessor"></span>00031 <span class="comment">// return values</span>00032 <span class="preprocessor">#define I2C_OK              0x00</span>00033 <span class="preprocessor"></span><span class="preprocessor">#define I2C_ERROR_NODEV     0x01</span>00034 <span class="preprocessor"></span>00035 <span class="comment">// types</span>00036 <span class="keyword">typedef</span> <span class="keyword">enum</span>00037 {00038     I2C_IDLE = 0, I2C_BUSY = 1,00039     I2C_MASTER_TX = 2, I2C_MASTER_RX = 3,00040     I2C_SLAVE_TX = 4, I2C_SLAVE_RX = 500041 } eI2cStateType;00042 00043 <span class="comment">// functions</span>00044 <span class="comment"></span>00045 <span class="comment">//! Initialize I2C (TWI) interface</span>00046 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a10">i2cInit</a>(<span class="keywordtype">void</span>);00047 <span class="comment"></span>00048 <span class="comment">//! Set the I2C transaction bitrate (in KHz)</span>00049 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a11">i2cSetBitrate</a>(u16 bitrateKHz);00050 00051 <span class="comment">// I2C setup and configurations commands</span><span class="comment"></span>00052 <span class="comment">//! Set the local (AVR processor's) I2C device address</span>00053 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a12">i2cSetLocalDeviceAddr</a>(u08 deviceAddr, u08 genCallEn);00054 <span class="comment"></span>00055 <span class="comment">//! Set the user function which handles receiving (incoming) data as a slave</span>00056 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a13">i2cSetSlaveReceiveHandler</a>(<span class="keywordtype">void</span> (*i2cSlaveRx_func)(u08 receiveDataLength, u08* recieveData));<span class="comment"></span>00057 <span class="comment">//! Set the user function which handles transmitting (outgoing) data as a slave</span>00058 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a14">i2cSetSlaveTransmitHandler</a>(u08 (*i2cSlaveTx_func)(u08 transmitDataLengthMax, u08* transmitData));00059 00060 <span class="comment">// Low-level I2C transaction commands </span><span class="comment"></span>00061 <span class="comment">//! Send an I2C start condition in Master mode</span>00062 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a15">i2cSendStart</a>(<span class="keywordtype">void</span>);<span class="comment"></span>00063 <span class="comment">//! Send an I2C stop condition in Master mode</span>00064 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a16">i2cSendStop</a>(<span class="keywordtype">void</span>);<span class="comment"></span>00065 <span class="comment">//! Wait for current I2C operation to complete</span>00066 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a17">i2cWaitForComplete</a>(<span class="keywordtype">void</span>);<span class="comment"></span>00067 <span class="comment">//! Send an (address|R/W) combination or a data byte over I2C</span>00068 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a18">i2cSendByte</a>(u08 data);<span class="comment"></span>00069 <span class="comment">//! Receive a data byte over I2C  </span>00070 <span class="comment"></span><span class="comment">// ackFlag = TRUE if recevied data should be ACK'ed</span>00071 <span class="comment">// ackFlag = FALSE if recevied data should be NACK'ed</span>00072 <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a19">i2cReceiveByte</a>(u08 ackFlag);<span class="comment"></span>00073 <span class="comment">//! Pick up the data that was received with i2cReceiveByte()</span>00074 <span class="comment"></span>u08 <a class="code" href="i2c_8c.html#a20">i2cGetReceivedByte</a>(<span class="keywordtype">void</span>);<span class="comment"></span>00075 <span class="comment">//! Get current I2c bus status from TWSR</span>00076 <span class="comment"></span>u08 <a class="code" href="i2c_8c.html#a21">i2cGetStatus</a>(<span class="keywordtype">void</span>);00077 00078 <span class="comment">// high-level I2C transaction commands</span>00079 <span class="comment"></span>00080 <span class="comment">//! send I2C data to a device on the bus</span>00081 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a22">i2cMasterSend</a>(u08 deviceAddr, u08 length, u08 *data);<span class="comment"></span>00082 <span class="comment">//! receive I2C data from a device on the bus</span>00083 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a23">i2cMasterReceive</a>(u08 deviceAddr, u08 length, u08* data);00084 <span class="comment"></span>00085 <span class="comment">//! send I2C data to a device on the bus (non-interrupt based)</span>00086 <span class="comment"></span>u08 <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(u08 deviceAddr, u08 length, u08* data);<span class="comment"></span>00087 <span class="comment">//! receive I2C data from a device on the bus (non-interrupt based)</span>00088 <span class="comment"></span>u08 <a class="code" href="i2c_8h.html#a25">i2cMasterReceiveNI</a>(u08 deviceAddr, u08 length, u08 *data);00089 <span class="comment"></span>00090 <span class="comment">//! Get the current high-level state of the I2C interface</span>00091 <span class="comment"></span>eI2cStateType <a class="code" href="i2c_8c.html#a27">i2cGetState</a>(<span class="keywordtype">void</span>);00092 00093 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -