00001 /* 00002 00003 Copyright (c) 2010, Embedded Adventures, www.embeddedadventures.com 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 - Neither the name of Embedded Adventures nor the names of its contributors 00017 may be used to endorse or promote products derived from this software 00018 without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00030 THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 Contact us at admin@embeddedadventures.com 00033 00034 */ 00039 #include "tmp75.h" 00040 #include "pic_serial.h" 00041 00042 uns8 tmp75_read(uns8 addr, uns8 pointer) { 00043 uns8 data; 00044 00045 i2c_start(); 00046 i2c_send_byte(0x90 + addr); // w=0, write pointer 00047 00048 i2c_send_byte(pointer); // includes reading ack 00049 00050 i2c_start(); 00051 i2c_send_byte(0x90 + addr + 1); // read 00052 00053 data = i2c_receive_byte(); 00054 00055 00056 i2c_stop(); 00057 00058 return data; 00059 } 00060 00061 uns8 tmp75_write(uns8 addr, uns8 pointer, uns8 data) { 00062 00063 i2c_start(); 00064 i2c_send_byte(0x90 + addr); 00065 i2c_send_byte(pointer); 00066 00067 i2c_send_byte(data); 00068 00069 i2c_stop(); 00070 } 00071 00072 00073 uns16 tmp75_read_16bit(uns8 addr, uns8 pointer) { 00074 uns16 data; 00075 00076 i2c_start(); 00077 i2c_send_byte(0x90 + addr); // LSB=0 == write 00078 i2c_send_byte(pointer); 00079 00080 i2c_start(); 00081 i2c_send_byte(0x90 + addr + 1); // LSB=0 == read 00082 data = i2c_receive_byte(); 00083 00084 i2c_send_ack(); 00085 00086 data = data << 8 | i2c_receive_byte(); // reuse local variable 00087 00088 i2c_send_ack(); 00089 00090 i2c_stop(); 00091 } 00092 00093 void tmp75_setup() { 00094 i2c_setup(); 00095 } 00096 00097 void tmp75_set_config(uns8 addr, uns8 config) 00098 { 00099 tmp75_write(addr, TMP75_CONFIG_REGISTER, config); 00100 } 00101 00102 uns8 tmp75_get_config(uns8 addr) 00103 { 00104 return tmp75_read(addr, TMP75_CONFIG_REGISTER); 00105 } 00106 00107 void tmp75_convert_temp(uns8 addr) { 00109 // i2c_start(); 00110 // i2c_send_byte(0x90 + addr); 00111 // i2c_send_byte(ds1631_start_convert); 00112 // i2c_stop(); 00113 } 00114 00115 uns16 tmp75_get_temp(uns8 addr) 00116 { 00117 return tmp75_read_16bit(addr, TMP75_TEMP_REGISTER); 00118 00119 }