This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

why does the pcf8574 have no response?

Other Parts Discussed in Thread: PCF8574

Dear All:

I have written a sample code to operate pcf8574 using the pcf8574tlib, but whatever do I press the button, the value get from function pcf8574t_getdat  is the same,but the return value is successful. The following is my code:

#include <stdio.h>
#include "/home/userfordm355/dvsdk_1_30_00_23/demos/utils/include/pcf8574tlib.h"
int main()
{
 unsigned char buf[2];
 if(pcf8574t_init(0x20)!=I2C_FAILURE)
 {
  printf("pcf8574 is initiliazed Successful! \n"); 
 }

 if(pcf8574t_getdat(buf)==I2C_SUCCESS)
 {
  printf("pcf574 getdata Successful,value is %x!\n",buf[0]);   
 }
 
 pcf8574t_exit();

 
 return 0;
}

Can anybody tell my why?

thanks!

  • I am not familiar with 'pcf8574 ' device or familiar with the pcf8574t_init ot pcf8574t_getdat functions; are these functions you wrote? 

    it appears this is an i2c device and it also appears you are trying to possibly do 12c accesses from application space as opposed to kernel space.  In such scenerio, you would typically first open i2c device and set your i2c device i2c address,  then you would use the handle to talk to you i2c device.  Code snippet would look as follows

       fd = open(I2C_DEVICE, O_RDWR);

        if (fd < 0) {
            __E("Error while opening i2c device %s\n", I2C_DEVICE);
            return fd;
        }

        if (ioctl(fd, I2C_SLAVE, I2C_DEV_ADDR) == -1) {
            __E("Failed to set I2C_SLAVE %#x\n", I2C_DEV_ADDR);
            return -1;
        }