int i2cdev_ioctl_rdwr_example(void)
{
struct i2c_adapter *adap;
struct i2c_msg msg_info[2];
unsigned char buf_1[2];
unsigned char buf_2[2];
int res=0;
printk("allen: i2cdev_ioctl_rdwr_allen.\n");
adap = i2c_get_adapter(3); //minor number of i2c-3
if (!adap)
return -ENODEV;
msg_info[0].addr = 0x5c;
msg_info[0].flags = 0;
msg_info[0].len = 2;
msg_info[0].buf = buf_1;
buf_1[0] = 0x13;
buf_1[1] = 0x52;
msg_info[1].addr = 0x5c;
msg_info[1].flags = I2C_M_RD;
msg_info[1].len = 2;
msg_info[1].buf = buf_2;
memset(buf_2, 0, sizeof(buf_2));
res = i2c_transfer(adap, msg_info, 2);
printk("i2c_transfer: res:0x%X, reg:0x%02X%02X val:0x%02X%02X\n", res,
buf_1[0], buf_1[1], msg_info[1].buf[0], msg_info[1].buf[1]);
if (res != 2)
return -EFAULT;
if (msg_info[1].buf[1] & 0x4) {
printk("i2c_transfer:LINK UP");
res = 1;
}
else {
printk("i2c_transfer:LINK DOWN");
res = 0;
}
return res;
}
/ # i2cdetect -l
i2c-3 i2c Geni-I2C I2C adapter
i2c-6 i2c sde_dp_aux I2C adapter
i2c-4 i2c Geni-I2C I2C adapter
i2c-2 i2c Geni-I2C I2C adapter
i2c-0 i2c Geni-I2C I2C adapter
i2c-5 i2c Geni-I2C I2C adapter
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ #
/ # i2cdetect -r 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- 23 -- -- -- 27 -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- 4c UU -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --
/ #
/ #
/ #
/ # i2cdetect -r 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
/ # i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
/ #
/ # i2cdetect -r 3
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- 2b 2c -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- UU UU -- -- -- -- 5c -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
/ #
/ # i2cdetect -r 4
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-4 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: UU -- -- -- -- -- -- --
/ #
/ #
/ # i2cdetect -r 5
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-5 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
/ #
/ # i2cdetect -r 6
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-6 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
i2ctransfer -y 0 w3@0x2d 0xaa 0x56 0x00 //attach with smbus
i2ctransfer -y 0 w3@0x2d 0x99 0x36 0x00 //reboot
i2ctransfer -y 0 w3@0x2d 0xaa 0x55 0x00 //attach
i2ctransfer -y 0 w8@0x2d 0x00 0x00 0x04 0x01 0x01 0x41 0x1D 0x00
i2ctransfer -y 0 w3@0x2d 0x99 0x37 0x00
i2ctransfer -y 0 w5@0x2d 0x00 0x04 0x2e 0x01 0x56 r1
i2ctransfer -y 0 w5@0x2d 0x41 0x1D 0x01 0x88 0x00
i2ctransfer -y 0 w2@0x2d 0x41 0x1D r1
i2c tools
---------------------------------
/ # i2ctransfer 3 w4@0x5c 0x12 0x02 0x11 0x22
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will send the following messages to device file /dev/i2c-3:
msg 0: addr 0x5c, write, len 4, buf 0x12 0x02 0x11 0x22
Continue? [y/N] y
/ #
/ # i2ctransfer 3 w2@0x5c 0x12 0x02 r2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will send the following messages to device file /dev/i2c-3:
msg 0: addr 0x5c, write, len 2, buf 0x12 0x02
msg 1: addr 0x5c, read, len 2
Continue? [y/N] y
0x11 0x22
/ #
/ # i2ctransfer -V
i2ctransfer version 4.1+git
/ #
/ # i2ctransfer
Usage: i2ctransfer [-f] [-y] [-v] [-V] [-a] I2CBUS DESC [DATA] [DESC [DATA]]...
I2CBUS is an integer or an I2C bus name
DESC describes the transfer in the form: {r|w}LENGTH[@address]
1) read/write-flag 2) LENGTH (range 0-65535) 3) I2C address (use last one if omitted)
DATA are LENGTH bytes for a write message. They can be shortened by a suffix:
= (keep value constant until LENGTH)
+ (increase value by 1 until LENGTH)
- (decrease value by 1 until LENGTH)
p (use pseudo random generator until LENGTH with value as seed)
Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):
# i2ctransfer 0 w1@0x50 0x64 r8
Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):
# i2ctransfer 0 w17@0x50 0x42 0xff-
linux i2c
最新推荐文章于 2024-07-22 20:58:50 发布