Main Page   Modules   Data Structures   File List   Data Fields   Globals  

ads7828.c

Go to the documentation of this file.
00001 /*! \file ads7828.c \brief TI ADS7828 12-bit 8ch A/D Converter Driver Library. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'ads7828.c'
00005 // Title        : TI ADS7828 12-bit 8ch A/D Converter Driver Library
00006 // Author       : Pascal Stang - Copyright (C) 2004
00007 // Created      : 2004.02.10
00008 // Revised      : 2004.02.19
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 #include <avr/io.h>
00023 #include <avr/signal.h>
00024 #include <avr/interrupt.h>
00025 
00026 #include "global.h"
00027 #include "i2c.h"
00028 #include "ads7828.h"
00029 
00030 // global variables
00031 u08 Ads7282RefMode;
00032 
00033 // Functions
00034 u08 ads7828Init(u08 i2cAddr)
00035 {
00036     u08 channel = 0x80;
00037 
00038     // setup default A/D voltage reference
00039     ads7828SetReference(0);
00040 
00041     // issue a convserion to test chip presence
00042     // return TRUE if chip detected
00043     // return FALSE if chip does not respond
00044     return (i2cMasterSendNI(i2cAddr, 1, &channel) == I2C_OK);
00045 }
00046 
00047 u16 ads7828Convert(u08 i2cAddr, u08 channel)
00048 {
00049     u08 buffer[2];
00050     // combine channel and reference bits
00051     channel &= 0xF0;
00052     channel |= Ads7282RefMode;
00053     // start conversion on requested channel
00054     i2cMasterSendNI(i2cAddr, 1, &channel);
00055     // retrieve conversion result
00056     i2cMasterReceiveNI(i2cAddr, 2, buffer);
00057     // pack bytes and return result
00058     return ((buffer[0]<<8) | buffer[1]);
00059 }
00060 
00061 void ads7828SetReference(u08 ref)
00062 {
00063     if(ref)
00064     {
00065         // use internal reference
00066         Ads7282RefMode = ADS7828_CMD_PDMODE2;
00067     }
00068     else
00069     {
00070         // use external reference
00071         Ads7282RefMode = ADS7828_CMD_PDMODE0;
00072     }
00073 }

Generated on Sun Feb 22 19:12:30 2004 for Procyon AVRlib by doxygen1.3-rc2