code to access the AT30TSE75x temperature and E-prom device

Dependents:   AT30TSE752TST AT30TSE752TST2

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Thu Mar 30 21:54:21 2017 +0000
Parent:
5:c783703a9e28
Commit message:
corrected negative temperature calculation

Changed in this revision

AT30TSE75x.cpp Show annotated file Show diff for this revision Revisions of this file
AT30TSE75x.h Show annotated file Show diff for this revision Revisions of this file
--- a/AT30TSE75x.cpp	Thu Mar 30 18:19:22 2017 +0000
+++ b/AT30TSE75x.cpp	Thu Mar 30 21:54:21 2017 +0000
@@ -11,7 +11,7 @@
 */
 
 
-#define VERSION_AT30TSE75x_SRC  "0.91"  
+#define VERSION_AT30TSE75x_SRC  "0.95"  
 
 #define RegisterLocDownEnable 0 // set this to one to enable permanent NV register locking , never tested with 1 
 
@@ -82,14 +82,14 @@
 uint16_t  AT30TSE75x::set_temperature(float temperature ) {
     uint16_t td;
     uint16_t  sign= 0x8000;
-    if ( temperature  < 0)   temperature = -temperature;
-    else sign=0;
+    if ( temperature  < 0)  { temperature *= -1; }
+    else { sign=0; }
     // this function is only used to calculate limits so we don't care
     // about resolution settings, all is 12 bits
     temperature=temperature *16;
     td=(int)temperature;
+    if (sign){ td = ~td; td=td+1;}
     td= td<<4;
-    if (sign){ td = ~td; td=td+1;}
     td=td|sign;
     return td;    
         
@@ -99,12 +99,13 @@
 float  AT30TSE75x::convert_temperature( uint16_t datain) {
     uint16_t data=datain;
     float temperature;    
-    int8_t sign = 1;
+    float sign = 1;
  
     /* Check if negative and clear sign bit. */
     if (data & (1 << 15)) {
         sign *= -1;
-        data &= ~(1 << 15);
+        data = ~data;
+        data +=1;
     }
  
     /* Convert to temperature. */
@@ -155,7 +156,7 @@
 }     
 
 
-void AT30TSE75x::set_TlowLimitRegister(int &error ,  float temperture, int Nonvolatile) {
+void AT30TSE75x::set_TLowLimitRegister(int &error ,  float temperture, int Nonvolatile) {
     uint8_t reg = TLowReg ;
     if ( Nonvolatile) reg = TLowRegNV;
     set_LimitRegister(error ,reg ,  temperture,  Nonvolatile);
@@ -172,9 +173,9 @@
     if(  CregNV.RegisterLock) { error=44; return; }
     buffer[0]= reg;
     uint16_t td=set_temperature(temperature);
-    uint16_t td_low= td & 0x0F;
+    uint16_t td_low= td & 0xFF;
     buffer[2] = (uint8_t) td_low;
-    td = td >> 8; td= td & 0x0F;
+    td = td >> 8; td= td & 0xFF;
     buffer[1] = (uint8_t) td;
     locerr=_i2c->write(Taddr,(char *)buffer,3,false);
     buffer[0]=  TReg;
--- a/AT30TSE75x.h	Thu Mar 30 18:19:22 2017 +0000
+++ b/AT30TSE75x.h	Thu Mar 30 21:54:21 2017 +0000
@@ -9,7 +9,7 @@
 #include "I2CInterface.h" 
 
 
-#define VERSION_AT30TSE75x_HDR "0.90"
+#define VERSION_AT30TSE75x_HDR "0.95"
 
 /** AT30TSE75x class.
  *  Used for interfacing with a AT30TSE75x temperature sensor and ee-prom  
@@ -23,7 +23,9 @@
  *                  read /write ee-prom 
  *  version 0.86 : added ee-prom write protect mode tested  ( un-protect not tested)
  *  version 0.90 : added all set and get functions for reading the config register(s)
- *                  most of the functions are not tested .                
+ *                  most of the functions are not tested . 
+ *  version 0.95 : found error in set temperature limit registers , corrected set and get limit register 
+ *                  function calls               
  *  this code is only tested with the AT30TSE752  version ( 2 KBit version) 
  *  v 
  *  processor board  for the testing : FRDM-KL25Z 
@@ -131,7 +133,7 @@
     //                          if Nonvolatile=1 and the permanentlock bit is set error will be 43 
     //@param temperature   the temperature to be set in the register 
     //@param Nonvolatile   set the Nonvolataile register if set to none zero 
-    void set_TlowLimitRegister(int &error ,  float temperture, int Nonvolatile=0) ;
+    void set_TLowLimitRegister(int &error ,  float temperture, int Nonvolatile=0) ;
     void set_THighLimitRegister(int &error ,  float temperture, int Nonvolatile=0) ;
     float get_THighLimitRegister(int &error ,   int Nonvolatile=0) ;
     float get_TLowLimitRegister(int &error ,  int Nonvolatile=0) ;