版权声明:转载请说明出处 https://blog.csdn.net/qq_33166886/article/details/83895387
该函数读16位数据,高位在前,低位在后
static int read_reg(const struct i2c_client *client, unsigned int *buf , unsigned char address)
{
struct i2c_msg msg[2];
int ret;
unsigned char date1[2];
msg[0].addr = client->addr;
msg[0].buf = &address;
msg[0].len = 1;
msg[0].flags = 0;
msg[1].addr = client->addr;
msg[1].buf = date1;
msg[1].len = 2;
msg[1].flags = I2C_M_RD;
ret = i2c_transfer(client->adapter, msg, 2);
if (ret > 0)
{
printk(KERN_INFO "date1 : %d date1 :%d\n",date1[0],date1[1]);
*buf = (date1[0] << 8) | (date1[1]);
return 1;
}
else
return -EIO;
---------------------
作者:Mr.Wang_H
来源:CSDN
原文:https://blog.csdn.net/qq_33166886/article/details/83892644
版权声明:本文为博主原创文章,转载请附上博文链接!