Dependencies: ChaNFSSD mbed BMP085 SHT2x
AD7994.cpp
00001 /* 00002 * Copyright (c) 2011 Toshihisa T 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 */ 00005 00006 #include "mbed.h" 00007 #include "AD7994.h" 00008 00009 #define AD7994ADDR (0x44) 00010 00011 AD7994::AD7994(PinName p_sda, PinName p_scl) : i2c(p_sda, p_scl) 00012 { 00013 memset(ch_val,0,sizeof(ch_val)); 00014 } 00015 00016 void AD7994::Start() 00017 { 00018 char cmd_set[] = { 0x02,0x38 }; 00019 char cmd_tim[] = { 0x03,0x01 }; 00020 i2c.write(AD7994ADDR,cmd_set,sizeof(cmd_set)); 00021 i2c.write(AD7994ADDR,cmd_tim,sizeof(cmd_tim)); 00022 } 00023 00024 unsigned short AD7994::getVal() 00025 { 00026 char cmd[] = { 0x00 }; 00027 char buf[2]; 00028 unsigned short res = 0; 00029 i2c.write(AD7994ADDR,cmd,sizeof(cmd)); 00030 i2c.read(AD7994ADDR,buf,sizeof(buf)); 00031 res = buf[0]; 00032 res = (res << 8) | buf[1]; 00033 return res; 00034 } 00035 00036 void AD7994::update() 00037 { 00038 int i; 00039 unsigned short res; 00040 unsigned short idx; 00041 for(i=0;i<4;i++){ 00042 res = getVal(); 00043 idx = (res >> 12) & 0x03; 00044 ch_val[idx] = res & 0x0FFF; 00045 } 00046 } 00047 00048 unsigned short AD7994::readChn(int chnNo) 00049 { 00050 return ch_val[chnNo]; 00051 }
Generated on Thu Jul 14 2022 16:50:44 by 1.7.2