Simple DS1621 temperature acquisition.

Dependents:   S3_DS1621

Revision:
3:d6310fd6df8e
Parent:
2:3160631567f2
--- a/ds1621.cpp	Mon Mar 07 08:12:27 2011 +0000
+++ b/ds1621.cpp	Mon Mar 21 16:51:22 2011 +0000
@@ -5,22 +5,18 @@
 ************************************************************/
 #include "ds1621.h"
 
-DS1621::DS1621(I2C* interface, uint8_t address, Serial* pc) {
+DS1621::DS1621(I2C* interface, uint8_t address) {
     i2c = interface;
-    dbx = pc;
-    if (dbx) dbx->printf("Constructor DS1621\n\r");
 }
 
-float DS1621::getTemp(uint8_t address) { // Return degrees C (-55 to +125)
-    if (dbx) dbx->printf("DS1621::getTemp DS1621 address=0x%X\n\r",address);
+float DS1621::read(uint8_t address) { // Return degrees C (-55 to +125)
+    if (dbx) printf("DS1621::read DS1621 address=0x%X\n\r",address);
     float temperature = 0.0;
     uint16_t temp16;
     char temp8[2];
     int8_t data;
     if (i2c) {
         address &= 0x0E;
-        data = 0xEE; // Start Convert T [EEh]
-        i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
         data = 0xAA; // Read Temperature [AAh]
         i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
         i2c->read(DS1621_Read|address, temp8 ,sizeof(temp8), false);
@@ -35,9 +31,17 @@
             temperature = ((float) temp16 / 2);
             temperature = -1.0 * temperature;
         }
-        if (dbx)  dbx->printf("DS1621::getTemp temp8[0]=0x%X, temp8[1]=0x%X, temp16=0x%X\n\r",temp8[0],temp8[1],temp16);
+        if (dbx) printf("DS1621::read temp8[0]=0x%X, temp8[1]=0x%X, temp16=0x%X\n\r",temp8[0],temp8[1],temp16);
     } else {
-       if (dbx)  dbx->printf("DS1621::getTemp interface I2C is not initialized\n\r");
+        if (dbx) printf("DS1621::read interface I2C is not initialized\n\r");
     }
     return temperature;
+}
+
+void DS1621::init(uint8_t address) {
+    if (dbx) printf("DS1621::init DS1621 address=0x%X\n\r",address);
+    address &= 0x0E;
+    char data;
+    data = 0xEE; // Start Convert T [EEh]
+    i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
 }
\ No newline at end of file