5 float ReadDS1621(char address) {
7 signed char counter, slope;
9 int id=DS1621_ID + (address<<1);
12 //fprintf (stderr, "I2C bus busy, retrying.\n");
15 i2cTransmitBuffer[0]=0xac; // access config command
16 i2cTransmitBuffer[1]=0x09; // mode (8=continuous, 9=one-shot)
17 if (I2CSend(id, 2)) return -999;
19 i2cTransmitBuffer[0]=0xee; // start conversion command
20 if (I2CSend(id, 1)) return -999;
23 i2cTransmitBuffer[0]=0xac; // access config command
24 if (I2CSendReceive(id, 1, 1)) return -999;
25 } while ((i2cReceiveBuffer[0]&0x80)==0); // wait for conversion done
27 i2cTransmitBuffer[0]=0xaa; // read temperature command
29 if (I2CSendReceive(id, 1, 1)) return -999;
30 temperature=i2cReceiveBuffer[0];
31 i2cTransmitBuffer[0]=0xa8; // read counter command
32 if (I2CSendReceive(id, 1, 1)) return -999;
33 counter=i2cReceiveBuffer[0];
35 i2cTransmitBuffer[0]=0xa9; // read slope command
36 if (I2CSendReceive(id, 1, 1)) return -999;
37 slope=i2cReceiveBuffer[0];
39 temperature=temperature - 0.25 +
40 ((float)slope-(float)counter)/(float)slope;