?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: ads7870.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>ads7870.c</h1><a href="ads7870_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file ads7870.c \brief TI ADS7870 12-bit 8ch A/D Converter Driver Library. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'ads7870.c'</span>
12 00005 <span class="comment">// Title : TI ADS7870 12-bit 8ch A/D Converter Driver Library</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2005</span>
14 00007 <span class="comment">// Created : 2005.07.19</span>
15 00008 <span class="comment">// Revised : 2005.07.21</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="spi_8h.html">spi.h</a>"</span>
34 00027 <span class="preprocessor">#include "<a class="code" href="ads7870_8h.html">ads7870.h</a>"</span>
35 00028
36 00029 <span class="comment">// global variables</span>
37 00030
38 00031 <span class="comment">// Functions</span>
39 <a name="l00032"></a><a class="code" href="group__ads7870.html#ga0">00032</a> u08 <a class="code" href="group__ads7870.html#ga0">ads7870Init</a>(<span class="keywordtype">void</span>)
40 00033 {
41 00034 <span class="comment">// initialize spi interface</span>
42 00035 spiInit();
43 00036 <span class="comment">// switch to f/4 bitrate</span>
44 00037 cbi(SPCR, SPR0);
45 00038 cbi(SPCR, SPR1);
46 00039 <span class="comment">//sbi(SPSR, SPI2X);</span>
47 00040
48 00041 <span class="comment">// setup chip select</span>
49 00042 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
50 00043 sbi(ADS7870_CS_DDR, ADS7870_CS_PIN);
51 00044
52 00045 <span class="comment">// check ID register</span>
53 00046 <span class="keywordflow">if</span>(<a class="code" href="group__ads7870.html#ga4">ads7870ReadReg</a>(ADS7870_ID) != ADS7870_ID_VALUE)
54 00047 <span class="keywordflow">return</span> 0;
55 00048
56 00049 <span class="comment">// setup reference and buffer</span>
57 00050 <a class="code" href="group__ads7870.html#ga5">ads7870WriteReg</a>(ADS7870_REFOSC, ADS7870_REFOSC_OSCE | ADS7870_REFOSC_REFE | ADS7870_REFOSC_BUFE);
58 00051
59 00052 <span class="comment">// return success</span>
60 00053 <span class="keywordflow">return</span> 1;
61 00054 }
62 00055
63 <a name="l00056"></a><a class="code" href="group__ads7870.html#ga1">00056</a> s16 <a class="code" href="group__ads7870.html#ga1">ads7870Convert</a>(u08 channel)
64 00057 {
65 00058 <span class="comment">// set single-ended channel bit</span>
66 00059 channel |= ADS7870_CH_SINGLE_ENDED;
67 00060 <span class="comment">// do conversion</span>
68 00061 <span class="keywordflow">return</span> <a class="code" href="group__ads7870.html#ga3">ads7870ConvertRaw</a>(channel);
69 00062 }
70 00063
71 <a name="l00064"></a><a class="code" href="group__ads7870.html#ga2">00064</a> s16 <a class="code" href="group__ads7870.html#ga2">ads7870ConvertDiff</a>(u08 channel)
72 00065 {
73 00066 <span class="comment">// clear single-ended channel bit</span>
74 00067 channel &amp;= ~ADS7870_CH_SINGLE_ENDED;
75 00068 <span class="comment">// do conversion</span>
76 00069 <span class="keywordflow">return</span> <a class="code" href="group__ads7870.html#ga3">ads7870ConvertRaw</a>(channel);
77 00070 }
78 00071
79 <a name="l00072"></a><a class="code" href="group__ads7870.html#ga3">00072</a> s16 <a class="code" href="group__ads7870.html#ga3">ads7870ConvertRaw</a>(u08 channel)
80 00073 {
81 00074 s16 result;
82 00075 <span class="comment">// assert chip select</span>
83 00076 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
84 00077 <span class="comment">// start conversion</span>
85 00078 spiTransferByte(ADS7870_CONVERT | channel);
86 00079 <span class="comment">// wait for completion</span>
87 00080 <span class="keywordflow">while</span>( <a class="code" href="group__ads7870.html#ga4">ads7870ReadReg</a>(ADS7870_GAINMUX) &amp; ADS7870_GAINMUX_CNVBSY);
88 00081 <span class="comment">// assert chip select</span>
89 00082 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
90 00083 <span class="comment">// read result</span>
91 00084 spiTransferByte(ADS7870_REG_READ | ADS7870_REG_16BIT | ADS7870_RESULTHI);
92 00085 result = spiTransferByte(0x00)&lt;&lt;8;
93 00086 result |= spiTransferByte(0x00);
94 00087 <span class="comment">// release chip select</span>
95 00088 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
96 00089 <span class="comment">// return result</span>
97 00090 <span class="keywordflow">return</span> result;
98 00091 }
99 00092
100 <a name="l00093"></a><a class="code" href="group__ads7870.html#ga4">00093</a> u08 <a class="code" href="group__ads7870.html#ga4">ads7870ReadReg</a>(u08 reg)
101 00094 {
102 00095 u08 data;
103 00096 <span class="comment">// assert chip select</span>
104 00097 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
105 00098 <span class="comment">// issue reg read command</span>
106 00099 spiTransferByte(ADS7870_REG_READ | reg);
107 00100 <span class="comment">// read data</span>
108 00101 data = spiTransferByte(0x00);
109 00102 <span class="comment">// release chip select</span>
110 00103 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
111 00104 <span class="comment">// return data</span>
112 00105 <span class="keywordflow">return</span> data;
113 00106 }
114 00107
115 <a name="l00108"></a><a class="code" href="group__ads7870.html#ga5">00108</a> <span class="keywordtype">void</span> <a class="code" href="group__ads7870.html#ga5">ads7870WriteReg</a>(u08 reg, u08 value)
116 00109 {
117 00110 <span class="comment">// assert chip select</span>
118 00111 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
119 00112 <span class="comment">// issue reg write command</span>
120 00113 spiTransferByte(ADS7870_REG_WRITE | reg);
121 00114 <span class="comment">// write data</span>
122 00115 spiTransferByte(value);
123 00116 <span class="comment">// release chip select</span>
124 00117 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
125 00118 }
126 00119
127 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
128 <a href="http://www.doxygen.org/index.html">
129 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
130 </body>
131 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3