2017-02-28 113 views
0

我的船上我有一个I2C器件,设置一些寄存器。内核驱动程序I2C开发

g_I2cDevFd = open("/dev/" UMAP_DEVNAME_I2C, O_RDWR, 0); 
if (g_I2cDevFd < 0) 
{ 
    HI_FATAL_I2C("open I2C err.\n"); 
    HI_I2C_UNLOCK(); 
    return HI_ERR_I2C_OPEN_ERR; 
} 

我该怎么做?

最好的问候

+2

这个问题是在审查队列。你应该说明内核版本。 – jww

+0

Linux的67年3月4日的版本。 – 7758521

回答

0

你的问题不是很清楚。但对于Linux操作系统I2C通信,请参考以下链接Interfacing_with_I2C_Devices

  • 在定义UMAP_DEVNAME_I2C本身请使用您的设备路径。即,#define UMAP_DEVNAME_I2C "/dev/your_i2c_device"
  • 或者使用sprintf如果你不能编辑UMAP_DEVNAME_I2C

    char buff[100] = {0}; // size you can change according to your requirement 
    
    sprintf(buff,"/dev/%s",UMAP_DEVNAME_I2C); 
    g_I2cDevFd = open(buff, O_RDWR, 0); 
    /* Error check for open here*/ 
    
    int addr = 0xFF;   // 0xFF is Invalid, Give I2C address of your device 
    if (ioctl(g_I2cDevFd, I2C_SLAVE, addr) < 0) { 
        printf("Failed to acquire bus access and/or talk to slave.\n"); 
        /* ERROR HANDLING; you can check errno to see what went wrong */ 
        exit(1); 
    } 
    
    /* Write or Read*/ 
    
+0

感谢U.I要控制I2C的设备在用户空间。你能提供关于i2c问题的更多信息吗?我是一个新手。 – 7758521

+0

@ 7758521检查更新的答案 – jjb

+0

是的,它的工作,thx,请参考链接[Interfacing_with_I2C_Devices](http://elinux.org/Interfacing_with_I2C_Devices) – 7758521