//利用i2c总线进行通信,从设备地址是0x30
//头文件
#include <stdio.h>
#include <linux/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <errno.h>
#define I2C_RETRIES 0x0701
#define I2C_TIMEOUT 0x0702
//I2C_RDWR指令在i2cdev_ioctl函数中,会调用内核中的i2cdev_ioctl_rdrw函数
#define I2C_RDWR 0x0707
/*********定义struct i2c_rdwr_ioctl_data和struct i2c_msg,要和内核一致*******/
struct i2c_msg
{
unsigned short addr; //slave addr,需要右移1bit
unsigned short flags;//读写操作标志位
#define I2C_M_TEN 0x0010
#define I2C_M_RD 0x0001
unsigned short len;//读写的长度
unsigned char *buf;//读写的缓冲区
};
struct i2c_rdwr_ioctl_data
{
struct i2c_msg *msgs;
int nmsgs;
/* nmsgs这个数量决定了有多少开始信号,对于“单开始时序”&#