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