|
发表于 2016-9-6 09:46:24
只看该作者
板凳
我用下面的func去讀i2c1的device reg內容,
static int get_i2c_register(int file,
unsigned char addr,
unsigned char reg,
unsigned char *val) {
unsigned char inbuf, outbuf = 0x01;
struct i2c_rdwr_ioctl_data packets;
struct i2c_msg messages[2];
/*
* In order to read a register, we first do a "dummy write" by writing
* 0 bytes to the register we want to read from. This is similar to
* the packet in set_i2c_register, except it's 1 byte rather than 2.
*/
outbuf = reg;
messages[0].addr = addr;
messages[0].flags = 0;
messages[0].len = sizeof(outbuf);
messages[0].buf = &outbuf;
/* The data will get returned in this structure */
messages[1].addr = addr;
messages[1].flags = I2C_M_RD/* | I2C_M_NOSTART*/;
messages[1].len = sizeof(inbuf);
messages[1].buf = &inbuf;
/* Send the request to the kernel and get the result back */
packets.msgs = messages;
packets.nmsgs = 2;
if(ioctl(file, I2C_RDWR, &packets) < 0) {
perror("Unable to send data");
return 1;
}
*val = inbuf;
return 0;
}
就會印
<4>[15811.846689] rockchip_i2c 20056000.i2c: Warning: addr[0x0008] msg[0].scl_rate( = 3037725Khz) is too high!
或是
<4>[ 463.032272] rockchip_i2c 20056000.i2c: Warning: addr[0x0008] msg[0].scl_rate( = 0Khz) is too low!
==========================分隔線===============================
但是, 用 read 就不會印訊息
if (read(i2c1_fd, &dat, 1) != 1)
{
/* ERROR HANDLING: i2c transaction failed */
printf("%s %d FAIL @ i2c-1 read\n", __func__, __LINE__);
}
請教大神, 何解?? |
|