?lang_form?
?lang_select?
?lang_submit?
?lang_endform?
{HEADER END}
{FILE START}
library
?curdirlinks? - Rev 6
?prevdifflink? - Blame - ?getfile?
<!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: ads7870.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>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>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name : 'ads7870.c'</span>
00005 <span class="comment">// Title : TI ADS7870 12-bit 8ch A/D Converter Driver Library</span>
00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2005</span>
00007 <span class="comment">// Created : 2005.07.19</span>
00008 <span class="comment">// Revised : 2005.07.21</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/interrupt.h></span>
00024
00025 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
00026 <span class="preprocessor">#include "<a class="code" href="spi_8h.html">spi.h</a>"</span>
00027 <span class="preprocessor">#include "<a class="code" href="ads7870_8h.html">ads7870.h</a>"</span>
00028
00029 <span class="comment">// global variables</span>
00030
00031 <span class="comment">// Functions</span>
<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>)
00033 {
00034 <span class="comment">// initialize spi interface</span>
00035 spiInit();
00036 <span class="comment">// switch to f/4 bitrate</span>
00037 cbi(SPCR, SPR0);
00038 cbi(SPCR, SPR1);
00039 <span class="comment">//sbi(SPSR, SPI2X);</span>
00040
00041 <span class="comment">// setup chip select</span>
00042 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00043 sbi(ADS7870_CS_DDR, ADS7870_CS_PIN);
00044
00045 <span class="comment">// check ID register</span>
00046 <span class="keywordflow">if</span>(<a class="code" href="group__ads7870.html#ga4">ads7870ReadReg</a>(ADS7870_ID) != ADS7870_ID_VALUE)
00047 <span class="keywordflow">return</span> 0;
00048
00049 <span class="comment">// setup reference and buffer</span>
00050 <a class="code" href="group__ads7870.html#ga5">ads7870WriteReg</a>(ADS7870_REFOSC, ADS7870_REFOSC_OSCE | ADS7870_REFOSC_REFE | ADS7870_REFOSC_BUFE);
00051
00052 <span class="comment">// return success</span>
00053 <span class="keywordflow">return</span> 1;
00054 }
00055
<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)
00057 {
00058 <span class="comment">// set single-ended channel bit</span>
00059 channel |= ADS7870_CH_SINGLE_ENDED;
00060 <span class="comment">// do conversion</span>
00061 <span class="keywordflow">return</span> <a class="code" href="group__ads7870.html#ga3">ads7870ConvertRaw</a>(channel);
00062 }
00063
<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)
00065 {
00066 <span class="comment">// clear single-ended channel bit</span>
00067 channel &= ~ADS7870_CH_SINGLE_ENDED;
00068 <span class="comment">// do conversion</span>
00069 <span class="keywordflow">return</span> <a class="code" href="group__ads7870.html#ga3">ads7870ConvertRaw</a>(channel);
00070 }
00071
<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)
00073 {
00074 s16 result;
00075 <span class="comment">// assert chip select</span>
00076 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00077 <span class="comment">// start conversion</span>
00078 spiTransferByte(ADS7870_CONVERT | channel);
00079 <span class="comment">// wait for completion</span>
00080 <span class="keywordflow">while</span>( <a class="code" href="group__ads7870.html#ga4">ads7870ReadReg</a>(ADS7870_GAINMUX) & ADS7870_GAINMUX_CNVBSY);
00081 <span class="comment">// assert chip select</span>
00082 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00083 <span class="comment">// read result</span>
00084 spiTransferByte(ADS7870_REG_READ | ADS7870_REG_16BIT | ADS7870_RESULTHI);
00085 result = spiTransferByte(0x00)<<8;
00086 result |= spiTransferByte(0x00);
00087 <span class="comment">// release chip select</span>
00088 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00089 <span class="comment">// return result</span>
00090 <span class="keywordflow">return</span> result;
00091 }
00092
<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)
00094 {
00095 u08 data;
00096 <span class="comment">// assert chip select</span>
00097 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00098 <span class="comment">// issue reg read command</span>
00099 spiTransferByte(ADS7870_REG_READ | reg);
00100 <span class="comment">// read data</span>
00101 data = spiTransferByte(0x00);
00102 <span class="comment">// release chip select</span>
00103 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00104 <span class="comment">// return data</span>
00105 <span class="keywordflow">return</span> data;
00106 }
00107
<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)
00109 {
00110 <span class="comment">// assert chip select</span>
00111 cbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00112 <span class="comment">// issue reg write command</span>
00113 spiTransferByte(ADS7870_REG_WRITE | reg);
00114 <span class="comment">// write data</span>
00115 spiTransferByte(value);
00116 <span class="comment">// release chip select</span>
00117 sbi(ADS7870_CS_PORT, ADS7870_CS_PIN);
00118 }
00119
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 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>
|
{FILE END}
{FOOTER START}
Powered by WebSVN v2.8.3