打印

应用程序调用i2c驱动

[复制链接]
2088|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huifly520|  楼主 | 2008-7-17 22:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用的是2.4.27 里面I2C 设备 ds1307,在 /documention/i2c/dev-interface 

文件中,是这样告诉我们调用设备的:

if ((file = open(filename,O_RDWR)) < 0) {
    /* ERROR HANDLING; you can check errno to see what went wrong */
    exit(1);
  }

When you have opened the device, you must specify with what device
address you want to communicate:
  int addr = 0x40; /* The I2C address */
  if (ioctl(file,I2C_SLAVE,addr) < 0) {
    /* ERROR HANDLING; you can check errno to see what went wrong */
    exit(1);
  }
即先open(filename,O_RDWR)  再(ioctl(file,I2C_SLAVE,addr) 这里 addr 是从设备地址.

这种方法确实不行.  在 网上一篇**<<i2c源代码情景分析(beta2)>> 说

需要说明的是,在Documentation/i2c/dev-interface一文中的通过I2C_SLAVE命令来指明待访问的设备地址的说法是不正确的,而必须增加一个额外的命令用于指明设备地址:(增加的部分如加粗所示)

      switch ( cmd ) {

       case I2C_TMP_DEVICE_ADDR:

              /* Make sure the addr is used by one device */

              if (-EBUSY == i2c_check_addr(client->adapter,arg)){

#ifdef DEBUG

                     printk(KERN_INFO "set tmp i2c_client.addr to 0x%2x ", arg);

#endif

                     client->addr = arg;

                     return 0;

              }else{

#ifdef DEBUG

                     printk(KERN_INFO "No device on adapter(%s) has the addr of 0x%2x ", 

client->adapter->name, arg);

#endif

                     return -EINVAL;

              }

 

       case I2C_SLAVE:

       case I2C_SLAVE_FORCE:

              if ((arg > 0x3ff) || 

                  (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))

                     return -EINVAL;

              if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg))

                     return -EBUSY;

              client->addr = arg;

              return 0;

这部分代码我是在i2c-dev.c 中修改的, 然后再重新编译内核. 这里的I2C_TMP_DEVICE_ADDR  我是随便define 的一个数. 我只 insmod ds1307.o   结果依然是no .  any one  can tell me some suggestions??

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

12

帖子

0

粉丝