4 read the data on the 8 line port of an i2c bus PCF8574
5 ------------------------------------------------------
7 1) set the i2c address of the PCF8574
8 2) send data 255 to turn off all 8 lines - make them inputs
9 3) read the data on the 8 port lines as a byte
10 usage :- type (without the < >)
11 <PCF8574_address_read_4> <space> <i2c_bus_address_of_PCF8574_as_decimal>
17 #include <sys/ioctl.h>
18 #include <linux/i2c.h>
22 int address; /* i2c bus address of the PCF8574 */
23 int byte; /* the 8 bit byte that represents the data present on the 8 wire port */
25 int main(int argc, char** argv)
27 if (argc != 2) /* report error if we are not getting just 1 input after the program name */
29 printf("Error. usage: %s i2c_chip_address\n", argv[0]);
32 address = atoi(argv[1]); /* address is the first number after the program name */
34 i2c = open("/dev/i2c/0",O_RDWR); /* open the i2c-bus number 0 */
36 ioctl(i2c,I2C_SLAVE, address); /* set the address of the chip we will talk to */
39 write(i2c,buf,1); /* we send 255 to make all lines go off, ready for input data */
41 read(i2c,buf,1); /* now buf(0) contains the byte of data on the 8 port lines*/
45 printf("BYTE = %d \n", byte);
46 /* BYTE value is 0-256)*/