i2c 读写
在I2C设备读取,必须是在同一个周期内。
一个例子,可以同时读出两个值
int read_register_double_value(int reg_addr, unsigned char *value_h, unsigned char *value_l) { struct i2c_rdwr_ioctrl_data io_data = {0}; struct i2c_msg msg[2] = {{0}}; unsigned char data = 0; unsigned char out[2] = {0}; data = red_addr; msg[0].addr = i2c_addr; msg[0].len=1; msg[0].buf = &data; msg[0].addr = i2c_addr; msg[0].flags = I2C_M_RD; msg[0].len = 2; msg[0].buf = &out[0] io_data.nmsg2 = 2; io_data,msgs = &msg[0]; ret = ioctrl(devide_id, I2C_RDWR, &io_data); *value_h = out[0]; *value_l = out[1]; }
在uboot中调试i2c,很实用。
i2c dev 0//悬着i2c设备总线
i2c probe 56 //查看地址56是否是i2c设备
i2c md 56 0 1 //向设备中写数据
。。。