我用的是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??
|