Imported Upstream version 2.9.0
[debian/cc1111] / device / examples / ds390 / i2c390 / pcf8591.c
1 #include <tinibios.h>
2
3 #include "pcf8591.h"
4
5 unsigned char ReadPCF8591(char address, char channel) {
6   
7   unsigned char id=PCF8591_ID+(address<<1);
8   
9   while (!I2CReset()) {
10     //fprintf (stderr, "I2C bus busy, retrying.\n");
11   }
12   
13   // set output enable, no autoincrement
14   i2cTransmitBuffer[0]=(channel&0x03)+0x40;
15
16   // read 2 bytes, since the first one is the old value
17   if (I2CSendReceive(id, 1, 2))
18     return 0;
19
20   return i2cReceiveBuffer[1];
21 }
22