upgrade ds1621 to report fp temp's
[fw/sdcc] / device / examples / ds390 / i2c390 / pcf8591.c
1 #include "i2clole.h"
2 #include "pcf8591.h"
3
4 #if 0 || FIND_OPERATOR_PRECEDING_INCONSISTANCY
5 #undef PCF8591_ID
6 #define PCF8591_ID 0x90;
7 #endif
8
9 unsigned char ReadPCF8591(char address, char channel) {
10   
11   unsigned char id=PCF8591_ID+address<<1;
12   
13   while (!I2CReset()) {
14     //fprintf (stderr, "I2C bus busy, retrying.\n");
15   }
16   
17   // set output enable, no autoincrement
18   i2cTransmitBuffer[0]=channel&0x03+0x40;
19
20   // read 2 bytes, since the first one is the old value
21   if (I2CSendReceive(id, 1, 2))
22     return 0;
23
24   return i2cReceiveBuffer[1];
25 }
26