当前位置: 首页 > java >正文

i2c-tools使用的介绍及示例(i2cdetect,i2cdump, i2cget、i2cset、i2ctransfer)

I2C工具集

linux驱动开发时经常会与i2c设备打交道,开发调试12c设备的时进行遇到各种各种问题,在介绍鸿蒙的i2c驱动时需要用到这个工具集,没找到合适的文章,所以把以前总结的这个工具说明发上来了,记不清具体的根文件系统版本了,仅供参考吧。

下面介绍l2C-tools的使用帮助和应用示例,包括以下几个工具

  • i2cdetect查询12C bus上的设备
  • i2cdump 用于查看对应bus上的所有寄存器
  • i2cget用于读取对应bus上寄存器
  • i2cset用于设置寄存器
  • i2ctransfer用于读写多字节寄存器地址。

i2cdetect

i2cdetect -h
i2cdetect: invalid option -- 'h'
BusyBox v1.29.3 (2023-06-08 18:47:57 CST) multi-call binary.Usage: i2cdetect -l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]Detect I2C chips-l	List installed buses 列出总线-F BUS#	List functionalities on this bus 列总线功能-y	Disable interactive mode 关闭交互模式-a	Force scanning of non-regular addresses 强制扫描非常规地址-q	Use smbus quick write commands for probing (default)使用smbus快速写入命令进行探测-r	Use smbus read byte commands for probing 使用smbus读取字节命令进行探测FIRST and LAST limit probing range
  • 列出总线
sudo i2cdetect -l
  • 列出总线功能(假设总线号为3)
sudo i2cdetect -F 3
  • 扫描总线上设备地址
sudo i2cdetect -y -a 3

i2cdump

Usage: i2cdump [-fy] [-r FIRST-LAST] BUS ADDR [MODE]Examine I2C registersI2CBUS	I2C bus numberADDRESS	0x03-0x77
MODE is:b	Byte (default)w	WordW	Word on even register addressesi	I2C blocks	SMBus blockc	Consecutive byteAppend p for SMBus PEC-f	Force access 强行进入-y	Disable interactive mode 关闭交互模式-r	Limit the number of registers being accessed 限制访问的寄存器数量
  • 显示I2C 3号总线上0x5f设备的寄存器值。MODE为byte,可省略。
sudo i2cdump -f -y 3 0x5f b
sysadm@SCT230A:~$ sudo ./i2cdump -f -y 4 0x5f b0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 96 02 50 00 00 00 00 00 00 00 00 00 00 00 00 00    ??P.............
10: 00 79 79 79 00 00 00 00 00 00 00 00 00 00 00 00    .yyy............
20: 00 79 79 79 00 00 00 00 00 00 00 00 00 00 00 00    .yyy............
30: 00 79 79 79 00 00 00 00 00 00 00 00 00 00 00 00    .yyy............
40: 00 79 79 79 00 00 00 00 00 00 00 00 00 00 00 00    .yyy............
50: 00 79 79 79 00 00 00 00 00 00 00 00 00 00 00 00    .yyy............
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................

i2cget

Usage: i2cget [-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]Read from I2C/SMBus chip registersI2CBUS	I2C bus numberADDRESS	0x03-0x77
MODE is:b	Read byte data (default)w	Read word datac	Write byte/read byteAppend p for SMBus PEC-f	Force access强行进入-y	Disable interactive mode 关闭交互模式
  • 读3号总线上设备(0x5f)寄存器地址为1的值
sudo i2cget -fy 3 0x5f 1 b

i2cset

BusyBox v1.29.3 (2023-06-08 18:47:57 CST) multi-call binary.Usage: i2cset [-fy] [-m MASK] BUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]Set I2C registersI2CBUS	I2C bus numberADDRESS	0x03-0x77
MODE is:c	Byte, no valueb	Byte data (default)w	Word datai	I2C block datas	SMBus block dataAppend p for SMBus PEC-f	Force access-y	Disable interactive mode-r	Read back and compare the result-m MASK	Mask specifying which bits to write

设置3号总线上设备(0x5f)寄存器地址0x10的值为1

i2cset -f -y 3 0x5f 0x10 0x1

i2ctransfer

sage: i2ctransfer [-f] [-y] [-v] [-V] [-a] I2CBUS DESC [DATA] [DESC [DATA]]...I2CBUS is an integer or an I2C bus nameDESC describes the transfer in the form: {r|w}LENGTH[@address]1) read/write-flag 2) LENGTH (range 0-65535) 3) I2C address (use last one if omitted)DATA are LENGTH bytes for a write message. They can be shortened by a suffix:= (keep value constant until LENGTH)+ (increase value by 1 until LENGTH)- (decrease value by 1 until LENGTH)p (use pseudo random generator until LENGTH with value as seed)Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):# i2ctransfer 0 w1@0x50 0x64 r8
Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):# i2ctransfer 0 w17@0x50 0x42 0xff-
sudo i2ctransfer -f -y 3 w1@0x5f 0x64 r8

读寄存器(0x2102)的两个字节的值

sudo i2ctransfer -f -y 4 w2@0x5f 0x21 0x02 r2

在寄存器(0x5013)中写入0x03的值

sudo i2ctransfer -f -y 4 w3@0x5f 0x50 0x13 0x03
http://www.xdnf.cn/news/9426.html

相关文章:

  • 解决微信小程序中 Flex 布局下 margin-right 不生效的问题
  • 通用大数据可视化展示平台模板 – 免费HTML源码
  • 聊聊JVM怎么调优?(实战总结)
  • 【Doris基础】Apache Doris中FE和BE的职责详解
  • 端午节互动网站
  • 学习threejs,超炫银河黑洞效果模拟
  • 【Halcon】 affine_trans_image 算子详解
  • vue组件和插件的区别
  • Kafka KRaft + SSL + SASL/PLAIN 部署文档
  • 【剑指offer】链表 系列
  • 万字详解RTR RTSP SDP RTCP
  • DeepSeek R1模型已完成小版本试升级
  • Unity屏幕适配——背景适配
  • leetcode 3372. 连接两棵树后最大目标节点数目 I
  • P8-大模型微调
  • Day05
  • Vuer开源程序 是一个轻量级的可视化工具包,用于与动态 3D 和机器人数据进行交互。它支持 VR 和 AR,可以在移动设备上运行。
  • Ethan的日记5/28
  • leetcode0670. 最大交换-medium
  • 让 Deepseek GPS测速
  • 电脑革命家测试版:硬件检测,6MB 轻量无广告 清理垃圾 + 禁用系统更新
  • Oracle Linux 9 安装 EMCC 13.5:避坑细节与实战经验汇总!
  • GO——内存逃逸分析
  • Flutter、React Native、Unity 下的 iOS 性能与调试实践:兼容性挑战与应对策略(含 KeyMob 工具经验)
  • 云服务器是什么,和服务器有什么区别?
  • 系统赛数据库的一些记录
  • 【华为开发者空间 x DeepSeek】服务器运行Ollama并在本地调用
  • flutter简单自定义跟随手指滑动的横向指示器
  • Django数据库连接报错 django.db.utils.NotSupportedError: MySQL 8 or later is required
  • 代码输出题:异步事件循环