重庆生活网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 生活 重庆
查看: 1355|回复: 0

ARM Linux菜鸟求助,急急急!!!

[复制链接]
发表于 2020-3-25 21:01:01 | 显示全部楼层 |阅读模式
我的程序:利用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
请问各位大神有没有知道原因的,急求!!!!!!!!!!!!!!!!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|联系我们|重庆生活网

GMT+8, 2024-3-29 14:56 , Processed in 0.171875 second(s), 18 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表