读写16位地址寄存器时,直接使用i2cget失败。后来发现需要使用i2ctransfter工具,
而我拿到的i2c-tools工具,并没有i2ctransfer可执行程序。只能自己编译。
用来检测I2C总线上连接的设备。
示例:
遇到的错误: permission denied (需要root权限)
遇到的错误: Remote I/O error (设备无法进行I2C通信,可能是没有上电,如设备没有打开)
用来dump出某个I2C总线上连接的某个设备(用I2C地址标识)的一系列寄存器的数据。
示例:
用来获取某个I2C总线上连接的某个设备(用I2C地址标识)的某个寄存器的数据。
示例:
用来设置某个I2C总线上连接的某个设备(用I2C地址标识)的某个寄存器的数据。
示例:
i2ctransfter程序的使用方式如下:
i2ctransfer -f -y 1 w2@0x36 0x50 0x81 r3
1: i2c-1
w2: @后面共有2+1个数字 (或者说 后面要读写的寄存器有2个值)
0x36: i2c device address
0x50+0x81: register address (16bit)
r3: 读出从0x5081开始的3个连续值
下图是读取7位设备从地址为0x36(对应的8位地址位0x6c)寄存器0x0100, 0x3409,
0x340c, 0x3425的示例:
由于代码编译主机只配置了交叉编译环境,没有Linux下的gcc,直接编译,生成的程序似乎不是可用的执行程序,在设备上执行时,提示“not executable: 64-bit ELF file”。有网友提示要编译成static的方式,我尝试后,发现还是会报告上面的错误。
我觉得可能还是需要在编译主机上,指定合适的GCC编译环境,生成linux环境或者交叉编译环境对应的可执行程序。
需要:
(1)下载i2c-tools源代码
(2)放到android项目工程中,添加对应的Android.mk
(3)source + lunch, 配置好编译环境
(4)mmm的方式编译i2c-tools目录
(5) push可执行程序到设备
将编译生成的out/target/x/目录/system/bin/下的i2cget, i2ctransfer等可执行程序push
到设备端的/system/bin/目录。
文件下载路径:
Index of /pub/software/utils/i2c-tools/ (kernel.org)
https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/
直接下载压缩包,或者通过git clone的方式下载(更推荐):
git clone git://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git
可以将代码放在Android项目源代码的external目录下进行编译。 记得先删除Makefile文件
(建议 先将i2c-tools目录下的Makefile剪切,备份保存,然后再创建Android.mk文件)
- LOCAL_PATH:= $(call my-dir)
-
- ################### i2c-tools #########################
- include $(CLEAR_VARS)
-
- LOCAL_MODULE := i2c-tools
-
- LOCAL_SRC_FILES := \
- tools/i2cbusses.c \
- tools/util.c \
- lib/smbus.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- #LOCAL_CFLAGS := -g -Wall -Werror -Wno-unused-parameter
- include $(BUILD_STATIC_LIBRARY)
-
- ################### i2cdetect #########################
- include $(CLEAR_VARS)
-
-
- LOCAL_MODULE:=i2cdetect
-
- LOCAL_SRC_FILES:= \
- tools/i2cdetect.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- LOCAL_SHARED_LIBRARIES:= \
- libc
- LOCAL_STATIC_LIBRARIES := \
- i2c-tools
-
- LOCAL_CPPFLAGS += -DANDROID
-
- include $(BUILD_EXECUTABLE)
-
- #################### i2cget ###########################
- include $(CLEAR_VARS)
-
-
- LOCAL_MODULE:=i2cget
-
- LOCAL_SRC_FILES:= \
- tools/i2cget.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- LOCAL_SHARED_LIBRARIES:= \
- libc
- LOCAL_STATIC_LIBRARIES := \
- i2c-tools
-
- LOCAL_CPPFLAGS += -DANDROID
-
- include $(BUILD_EXECUTABLE)
-
- ##################### i2cset ##########################
- include $(CLEAR_VARS)
-
- LOCAL_MODULE:=i2cset
-
- LOCAL_SRC_FILES:= \
- tools/i2cset.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- LOCAL_SHARED_LIBRARIES:= \
- libc
- LOCAL_STATIC_LIBRARIES := \
- i2c-tools
-
- LOCAL_CPPFLAGS += -DANDROID
-
- include $(BUILD_EXECUTABLE)
-
- ##################### i2cdump #########################
- include $(CLEAR_VARS)
-
-
- LOCAL_MODULE:=i2cdump
-
- LOCAL_SRC_FILES:= \
- tools/i2cdump.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- LOCAL_SHARED_LIBRARIES:= \
- libc
- LOCAL_STATIC_LIBRARIES := \
- i2c-tools
-
- LOCAL_CPPFLAGS += -DANDROID
-
- include $(BUILD_EXECUTABLE)
-
- ################### i2ctransfer #######################
- include $(CLEAR_VARS)
-
- LOCAL_MODULE:=i2ctransfer
-
- LOCAL_SRC_FILES:= \
- tools/i2ctransfer.c
-
- LOCAL_C_INCLUDES += \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
- LOCAL_SHARED_LIBRARIES:= \
- libc
- LOCAL_STATIC_LIBRARIES := \
- i2c-tools
-
- LOCAL_CPPFLAGS += -DANDROID
-
- include $(BUILD_EXECUTABLE)
附上几个有关的链接:
(52条消息) Android 平台下使用 i2c-tools_简单并快乐着的博客-CSDN博客
(52条消息) i2c-tools工具_Linux驱动专栏的博客-CSDN博客_i2ctool工具
[Android] i2c-toos 在 Android 上使用 - LeeAaron - 博客园 (cnblogs.com)
(51条消息) 手把手教你使用 i2c-tools_嵌入式Linux系统开发的博客-CSDN博客_i2c-tools
sh: ./i2c_test: not executable: 64-bit ELF file No such file or directory 相关链接:
https://blog.csdn.net/baiyifei2016/article/details/125055949
https://blog.csdn.net/u012830148/article/details/88425984
c - Android not executable: 64-bit ELF file - Stack Overflow