1. 程式人生 > >I2c驅動i2c_master_send()和i2c_master_recv()用法

I2c驅動i2c_master_send()和i2c_master_recv()用法

struct i2c_client *client
unsigned char buf[2] = {0};
int ret;

buf[0]=0x30;//暫存器地址
buf[1]=0x05;//設定的值

//設定暫存器
ret = i2c_master_send(client, buf, 2);
if(ret < 0)
    printk(KERN_ERR "Write data failed\n");

//讀取暫存器
ret = i2c_master_recv(client, buf, 1);
if(ret < 0)
    printk(KERN_ERR "Read data failed\n");