【问题标题】:Kernel driver i2c Develop内核驱动 i2c 开发
【发布时间】:2017-07-18 21:03:42
【问题描述】:

在我的板上,我有一个 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;
}

我该怎么做?

最好的问候

【问题讨论】:

  • 此问题在审核队列中。您可能应该说明内核版本。
  • Linux-3.4.67 版本。

标签: linux-device-driver i2c


【解决方案1】:

你的问题不是很清楚。但是对于Linux Os中的I2C通信,请参考这个链接Interfacing_with_I2C_Devices

  • 请在定义UMAP_DEVNAME_I2C 时使用您的设备路径。即#define UMAP_DEVNAME_I2C "/dev/your_i2c_device"
  • 如果您无法编辑UMAP_DEVNAME_I2C,则使用sprintf,即,

    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*/  
    

【讨论】:

  • 感谢U.我想在用户空间控制i2c的设备。您能否提供有关 i2c 问题的更多信息。我是新手。
  • 是的,它成功了,谢谢,参考链接Interfacing_with_I2C_Devices
猜你喜欢
  • 2016-04-23
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 2017-05-04
相关资源
最近更新 更多