重庆生活网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 生活 重庆
查看: 1407|回复: 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
请问各位大神有没有知道原因的,急求!!!!!!!!!!!!!!!!

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-2 21:56 , Processed in 0.140625 second(s), 17 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

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