Project

General

Profile

Statistics
| Revision:

root / trunk / docs / libdragonfly / group__i2c.html @ 1067

History | View | Annotate | Download (10.6 KB)

1 87 bcoltin
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 241 bcoltin
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 87 bcoltin
<title>libdragonfly: I2C</title>
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
5
<link href="tabs.css" rel="stylesheet" type="text/css">
6
</head><body>
7 948 justin
<!-- Generated by Doxygen 1.5.3 -->
8 869 justin
<div class="tabs">
9
  <ul>
10
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
11
    <li><a href="modules.html"><span>Modules</span></a></li>
12
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
13
    <li><a href="files.html"><span>Files</span></a></li>
14
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
15
  </ul>
16 241 bcoltin
</div>
17 87 bcoltin
<h1>I2C</h1>Provides Inter-Interconnected-Communications (I2C).
18
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
19
<tr><td></td></tr>
20
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
21
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gaf685692265ff486494774a12f58cb12"></a><!-- doxytag: member="i2c::I2C_BIT_RATE_DIVIDER" ref="gaf685692265ff486494774a12f58cb12" args="" -->
22
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__i2c.html#gaf685692265ff486494774a12f58cb12">I2C_BIT_RATE_DIVIDER</a>&nbsp;&nbsp;&nbsp;0x0C</td></tr>
23
24
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set bit rate 12 = 100kbit/s (max speed setting is 10 for an 8 MHz clock). It is a divider, so the lower the number the faster the speed. <br></td></tr>
25
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
26
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gbf590d5cb743d0202ca44be4b3e4865d"></a><!-- doxytag: member="i2c::RING_BUFFER_NEW" ref="gbf590d5cb743d0202ca44be4b3e4865d" args="(i2c_buffer, 128, char, i2c_write_buff, i2c_addr_buff)" -->
27
&nbsp;</td><td class="memItemRight" valign="bottom"><b>RING_BUFFER_NEW</b> (i2c_buffer, 128, char, i2c_write_buff, i2c_addr_buff)</td></tr>
28
29
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__i2c.html#g28bd4994859c49763a282579c4c772a1">i2c_init</a> (char addr, <a class="el" href="i2c_8h.html#3e550321eadebd4a697a3016e6ee918b">fun_mrecv_t</a> master_recv, <a class="el" href="i2c_8h.html#e1453fbad57354c82d465c704edeead5">fun_srecv_t</a> slave_recv, <a class="el" href="i2c_8h.html#4b946a38c2f1c58d838f59c6099feba1">fun_send_t</a> slave_send)</td></tr>
30
31
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes the i2c module.  <a href="#g28bd4994859c49763a282579c4c772a1"></a><br></td></tr>
32
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__i2c.html#g15f534819e0f3405c4e05769af1f1e19">i2c_send</a> (char dest, char *data, size_t bytes)</td></tr>
33
34
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sends a byte array over I2C as a master.  <a href="#g15f534819e0f3405c4e05769af1f1e19"></a><br></td></tr>
35
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__i2c.html#gf5d4ed96f03670ca300298019b7f2f72">i2c_request</a> (char dest)</td></tr>
36
37
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Send a master request to the destination.  <a href="#gf5d4ed96f03670ca300298019b7f2f72"></a><br></td></tr>
38
</table>
39
<hr><a name="_details"></a><h2>Detailed Description</h2>
40
Provides Inter-Interconnected-Communications (I2C).
41
<p>
42
Initiates I2C functions on an ATMega128 which has a fully hardware Two Wire Interface (TWI) module. Any Atmel chip with this hardware should be able to use the software.<p>
43
This code will operate in a multi-master enviornment and can be either a slave or a master at any time (as long as they are not one or the other at the moment. You can queue up multiple transmission modes in the buffer up to the buffer size. The buffer is implemented as a ring buffer.<p>
44
It is implemented using callback functions. Whenever you want to send a packet you can call the built in send function (as a master) and it will send an array of bytes. Master recieve and slave send/receive are all handled by the call back functions. It is up to the end user to create functions that will handle the receiving of packets. Their functions will be called with every byte recieved so you must either buffer the inputs or handle each one separately.<p>
45
On errors we will simply flush the entire buffer.<p>
46
For information on how I2C operates, read the wikipedia article <a href="http://en.wikipedia.org/wiki/I2c">http://en.wikipedia.org/wiki/I2c</a> for a good explanation of how it works. <hr><h2>Function Documentation</h2>
47 241 bcoltin
<a class="anchor" name="g28bd4994859c49763a282579c4c772a1"></a><!-- doxytag: member="i2c.c::i2c_init" ref="g28bd4994859c49763a282579c4c772a1" args="(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send)" -->
48
<div class="memitem">
49
<div class="memproto">
50
      <table class="memname">
51 87 bcoltin
        <tr>
52 241 bcoltin
          <td class="memname">int i2c_init           </td>
53
          <td>(</td>
54
          <td class="paramtype">char&nbsp;</td>
55
          <td class="paramname"> <em>addr</em>, </td>
56 87 bcoltin
        </tr>
57
        <tr>
58 241 bcoltin
          <td class="paramkey"></td>
59
          <td></td>
60
          <td class="paramtype"><a class="el" href="i2c_8h.html#3e550321eadebd4a697a3016e6ee918b">fun_mrecv_t</a>&nbsp;</td>
61
          <td class="paramname"> <em>master_recv</em>, </td>
62 87 bcoltin
        </tr>
63
        <tr>
64 241 bcoltin
          <td class="paramkey"></td>
65
          <td></td>
66
          <td class="paramtype"><a class="el" href="i2c_8h.html#e1453fbad57354c82d465c704edeead5">fun_srecv_t</a>&nbsp;</td>
67
          <td class="paramname"> <em>slave_recv</em>, </td>
68 87 bcoltin
        </tr>
69
        <tr>
70 241 bcoltin
          <td class="paramkey"></td>
71
          <td></td>
72
          <td class="paramtype"><a class="el" href="i2c_8h.html#4b946a38c2f1c58d838f59c6099feba1">fun_send_t</a>&nbsp;</td>
73
          <td class="paramname"> <em>slave_send</em></td><td>&nbsp;</td>
74 87 bcoltin
        </tr>
75
        <tr>
76 241 bcoltin
          <td></td>
77
          <td>)</td>
78
          <td></td><td></td><td width="100%"></td>
79 87 bcoltin
        </tr>
80
      </table>
81 241 bcoltin
</div>
82
<div class="memdoc">
83 87 bcoltin
84
<p>
85
Initializes the i2c module.
86
<p>
87
Initializes the I2C module to start listening on the i2c lines. If the callback functions are not set to null they will be called when that transmission mode is called. The address is your address that you will listen to when you are not the master.<p>
88
<dl compact><dt><b>Parameters:</b></dt><dd>
89
  <table border="0" cellspacing="2" cellpadding="0">
90
    <tr><td valign="top"></td><td valign="top"><em>addr</em>&nbsp;</td><td>Your address on the I2C bus. </td></tr>
91
    <tr><td valign="top"></td><td valign="top"><em>master_recv</em>&nbsp;</td><td>The address of the function to call when you receive a byte when you are a master. </td></tr>
92
    <tr><td valign="top"></td><td valign="top"><em>slave_recv</em>&nbsp;</td><td>The address of the function to call when you are a slave you receive data from the master </td></tr>
93 241 bcoltin
    <tr><td valign="top"></td><td valign="top"><em>slave_send</em>&nbsp;</td><td>The address of the function to call when you are a slave and the master requests data from you.</td></tr>
94 87 bcoltin
  </table>
95
</dl>
96 241 bcoltin
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 for success, nonzero for failure </dd></dl>
97
98
</div>
99
</div><p>
100
<a class="anchor" name="gf5d4ed96f03670ca300298019b7f2f72"></a><!-- doxytag: member="i2c.c::i2c_request" ref="gf5d4ed96f03670ca300298019b7f2f72" args="(char dest)" -->
101
<div class="memitem">
102
<div class="memproto">
103
      <table class="memname">
104 87 bcoltin
        <tr>
105 241 bcoltin
          <td class="memname">int i2c_request           </td>
106
          <td>(</td>
107
          <td class="paramtype">char&nbsp;</td>
108
          <td class="paramname"> <em>dest</em>          </td>
109
          <td>&nbsp;)&nbsp;</td>
110
          <td width="100%"></td>
111 87 bcoltin
        </tr>
112
      </table>
113 241 bcoltin
</div>
114
<div class="memdoc">
115 87 bcoltin
116
<p>
117
Send a master request to the destination.
118
<p>
119
Sends a request of data from the target address and calls the callback function to handle data as it comes in. This function will not work if the slave has not informationt to send or has nothing implemented to send it.<p>
120
<dl compact><dt><b>Parameters:</b></dt><dd>
121
  <table border="0" cellspacing="2" cellpadding="0">
122 241 bcoltin
    <tr><td valign="top"></td><td valign="top"><em>dest</em>&nbsp;</td><td>The destination that we want to receive information from.</td></tr>
123 87 bcoltin
  </table>
124
</dl>
125 241 bcoltin
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 for success, nonzero for failure </dd></dl>
126
127
</div>
128
</div><p>
129
<a class="anchor" name="g15f534819e0f3405c4e05769af1f1e19"></a><!-- doxytag: member="i2c.c::i2c_send" ref="g15f534819e0f3405c4e05769af1f1e19" args="(char dest, char *data, size_t bytes)" -->
130
<div class="memitem">
131
<div class="memproto">
132
      <table class="memname">
133 87 bcoltin
        <tr>
134 241 bcoltin
          <td class="memname">int i2c_send           </td>
135
          <td>(</td>
136
          <td class="paramtype">char&nbsp;</td>
137
          <td class="paramname"> <em>dest</em>, </td>
138 87 bcoltin
        </tr>
139
        <tr>
140 241 bcoltin
          <td class="paramkey"></td>
141
          <td></td>
142
          <td class="paramtype">char *&nbsp;</td>
143
          <td class="paramname"> <em>data</em>, </td>
144 87 bcoltin
        </tr>
145
        <tr>
146 241 bcoltin
          <td class="paramkey"></td>
147
          <td></td>
148
          <td class="paramtype">size_t&nbsp;</td>
149
          <td class="paramname"> <em>bytes</em></td><td>&nbsp;</td>
150 87 bcoltin
        </tr>
151
        <tr>
152 241 bcoltin
          <td></td>
153
          <td>)</td>
154
          <td></td><td></td><td width="100%"></td>
155 87 bcoltin
        </tr>
156
      </table>
157 241 bcoltin
</div>
158
<div class="memdoc">
159 87 bcoltin
160
<p>
161
Sends a byte array over I2C as a master.
162
<p>
163
Will perform a send over I2C to the destination from data for the ammount of bytes that bytes is.<p>
164
<dl compact><dt><b>Parameters:</b></dt><dd>
165
  <table border="0" cellspacing="2" cellpadding="0">
166
    <tr><td valign="top"></td><td valign="top"><em>dest</em>&nbsp;</td><td>Destination address of the data on the I2C bus. </td></tr>
167
    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>The pointer to the byte array of data </td></tr>
168 241 bcoltin
    <tr><td valign="top"></td><td valign="top"><em>bytes</em>&nbsp;</td><td>The amount of bytes long that the byte array is. This is how many bytes from the array that the function will send.</td></tr>
169 87 bcoltin
  </table>
170
</dl>
171 241 bcoltin
<dl class="return" compact><dt><b>Returns:</b></dt><dd>zero for success, nonzero for failure </dd></dl>
172
173
</div>
174
</div><p>
175 948 justin
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Nov 5 19:59:43 2008 for libdragonfly by&nbsp;
176 87 bcoltin
<a href="http://www.doxygen.org/index.html">
177 948 justin
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
178 87 bcoltin
</body>
179
</html>