code to access the AT30TSE75x temperature and E-prom device
Dependents: AT30TSE752TST AT30TSE752TST2
Diff: AT30TSE75x.cpp
- Revision:
- 6:cc295531021e
- Parent:
- 5:c783703a9e28
diff -r c783703a9e28 -r cc295531021e AT30TSE75x.cpp --- 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;