我的程序:利用I2C协议对加速度模块进行读写操作#include <stdio.h>#include <stdlib.h> 
#include <unistd.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <termios.h> 
#include <errnos.h> 
#include <sys/ioctl.h> 
#define ADDRESS  0x3A //加速度MMA7455的地址 
#define I2C_SLAVE 0x0703 
#define I2C_TENBIT 0x0704 
 
int mAIn() 
{ 
  int fd; 
  int uiRet; 
  char r_buf[2]; 
  r_buf[0]=0x00; 
  fd=open("/dev/i2c-1",O_RDWR); 
  if(fd<0) 
{ 
  perror("open i2c failed"); 
  return -1; 
  exit(1); 
} 
ioctl(fd,I2C_TENBIT,0); 
uiRet=ioctl(fd,I2C_SLAVE,ADDRESS>>1); 
if(uiRet<0) 
{ 
printf("setenv address faile ret:%x\n",uiRet); 
return -1; 
exit(0); 
} 
int a=write(fd,"0x06",1);//0x06是加速度模块的X轴寄存器的地址 
int b=read(fd,r_buf,1); 
perror("error");//测试用的,可以去掉 
printf("a is %d,b is $d \n",a,b); 
printf("data is %x\n",r_buf); 
close(fd); 
} 
運行出现问题:error:I/O error 
 
                    a is -1,b is -1 
                    data is be822984 
请问各位大神有没有知道原因的,急求!!!!!!!!!!!!!!!! 
 
 |