4 #if USE_FLOAT // defined in ds1621.h
5 static float temperature
6 signed char counter, slope;
10 static char temperature[10];
14 ReadDS1621(char address) {
15 int id=DS1621_ID + (address<<1);
18 //fprintf (stderr, "I2C bus busy, retrying.\n");
21 i2cTransmitBuffer[0]=0xac; // access config command
22 i2cTransmitBuffer[1]=0x09; // mode (8=continuous, 9=one-shot)
23 if (I2CSend(id, 2)) return -999;
25 i2cTransmitBuffer[0]=0xee; // start conversion command
26 if (I2CSend(id, 1)) return -999;
29 i2cTransmitBuffer[0]=0xac; // access config command
30 if (I2CSendReceive(id, 1, 1)) return -999;
31 } while ((i2cReceiveBuffer[0]&0x80)==0); // wait for conversion done
34 // if we did not do this, sdcc thinks i2cReceiveBuffer[0] is still in r3
35 i2cReceiveBuffer[0]=0;
37 i2cTransmitBuffer[0]=0xaa; // read temperature command
40 if (I2CSendReceive(id, 1, 2)) return -999;
41 sprintf (temperature, "% 3bd.%c", i2cReceiveBuffer[0],
42 i2cReceiveBuffer[1]?'5':'0');
45 if (I2CSendReceive(id, 1, 1)) return -999;
46 temperature=i2cReceiveBuffer[0];
47 i2cTransmitBuffer[0]=0xa8; // read counter command
48 if (I2CSendReceive(id, 1, 1)) return -999;
49 counter=i2cReceiveBuffer[0];
51 i2cTransmitBuffer[0]=0xa9; // read slope command
52 if (I2CSendReceive(id, 1, 1)) return -999;
53 slope=i2cReceiveBuffer[0];
55 temperature=(int)temperature - 0.25 +
56 ((float)slope-(float)counter)/(float)slope;