00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00031 u08 Ads7282RefMode;
00032
00033
00034 u08 ads7828Init(u08 i2cAddr)
00035 {
00036 u08 channel = 0x80;
00037
00038
00039 ads7828SetReference(0);
00040
00041
00042
00043
00044 return (i2cMasterSendNI(i2cAddr, 1, &channel) == I2C_OK);
00045 }
00046
00047 u16 ads7828Convert(u08 i2cAddr, u08 channel)
00048 {
00049
00050
00051
00052
00053
00054 channel = (((channel>>1) | (channel&0x01)<<2)<<4) | ADS7828_CMD_SD;
00055
00056 return ads7828ConvertRaw(i2cAddr, channel);
00057 }
00058
00059 u16 ads7828ConvertDiff(u08 i2cAddr, u08 channel)
00060 {
00061
00062 channel = (channel&0x07)<<4;
00063
00064 return ads7828ConvertRaw(i2cAddr, channel);
00065 }
00066
00067 u16 ads7828ConvertRaw(u08 i2cAddr, u08 channel)
00068 {
00069 u08 buffer[2];
00070
00071 channel &= 0xF0;
00072 channel |= Ads7282RefMode;
00073
00074 i2cMasterSendNI(i2cAddr, 1, &channel);
00075
00076 i2cMasterReceiveNI(i2cAddr, 2, buffer);
00077
00078 return ((buffer[0]<<8) | buffer[1]);
00079 }
00080
00081 void ads7828SetReference(u08 ref)
00082 {
00083 if(ref)
00084 {
00085
00086 Ads7282RefMode = ADS7828_CMD_PDMODE2;
00087 }
00088 else
00089 {
00090
00091 Ads7282RefMode = ADS7828_CMD_PDMODE0;
00092 }
00093 }