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/interrupt.h>
00024
00025 #include "global.h"
00026 #include "i2c.h"
00027 #include "ads7828.h"
00028
00029
00030 u08 Ads7282RefMode;
00031
00032
00033 u08 ads7828Init(u08 i2cAddr)
00034 {
00035 u08 channel = 0x80;
00036
00037
00038 ads7828SetReference(0);
00039
00040
00041
00042
00043 return (i2cMasterSendNI(i2cAddr, 1, &channel) == I2C_OK);
00044 }
00045
00046 u16 ads7828Convert(u08 i2cAddr, u08 channel)
00047 {
00048
00049
00050
00051
00052
00053 channel = (((channel>>1) | (channel&0x01)<<2)<<4) | ADS7828_CMD_SD;
00054
00055 return ads7828ConvertRaw(i2cAddr, channel);
00056 }
00057
00058 u16 ads7828ConvertDiff(u08 i2cAddr, u08 channel)
00059 {
00060
00061 channel = (channel&0x07)<<4;
00062
00063 return ads7828ConvertRaw(i2cAddr, channel);
00064 }
00065
00066 u16 ads7828ConvertRaw(u08 i2cAddr, u08 channel)
00067 {
00068 u08 buffer[2];
00069
00070 channel &= 0xF0;
00071 channel |= Ads7282RefMode;
00072
00073 i2cMasterSendNI(i2cAddr, 1, &channel);
00074
00075 i2cMasterReceiveNI(i2cAddr, 2, buffer);
00076
00077 return ((buffer[0]<<8) | buffer[1]);
00078 }
00079
00080 void ads7828SetReference(u08 ref)
00081 {
00082 if(ref)
00083 {
00084
00085 Ads7282RefMode = ADS7828_CMD_PDMODE2;
00086 }
00087 else
00088 {
00089
00090 Ads7282RefMode = ADS7828_CMD_PDMODE0;
00091 }
00092 }