内核驱动程序i2c Develop

时间:2017-02-28 03:10:48

标签: linux-device-driver 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;
}

我该怎么做?

最好的问候

1 个答案:

答案 0 :(得分:0)

你的问题不是很清楚。但对于Linux Os中的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*/