Linux下i2c-tools使用

  • i2c-tools介绍

I2C-tools 是一组用于 Linux 系统的实用工具,用于与 I2C(Inter-Integrated Circuit)总线设备进行通信、调试和管理。I2C 是一种串行通信协议,用于连接和控制微控制器、传感器、外设等设备。

在实际使用中,调试Linux内核外设使用比较多,对于一些i2c的device,进行调试会有很大帮助,这里将介绍一些主要的使用方法。

  • i2c-tools的安装

下载地址: https://www.kernel.org/pub/software/utils/i2c-tools/

编译安装既可

  • 查看I2C总线数目

evk_8mq:/ # i2cdetect -l

i2c-1   i2c             30a30000.i2c                            I2C Adapter

i2c-2   i2c             30a40000.i2c                            I2C Adapter

i2c-0   i2c             30a20000.i2c                            I2C Adapter

  • 查看i2c-1总线下的设备【使用最多】

扫描 I2C 设备:使用 i2cdetect 命令进行扫描。例如:

sudo i2cdetect -y <bus_number>

<bus_number> 是 I2C 总线的编号,通常是 0 或 1。

i2cdetect -y 1 

evk_8mq:/ # i2cdetect -y 0

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          — — — — — UU — — — — — — —

10: — — — — — — — — — — — — — — — —

20: — — UU — — — — — — — — — — — — —

30: — — — — — — — — — — — — — — — —

40: — — — — — — — — — — — — — — — —

50: — — — — — — — — — — — — — — — —

60: — — UU — — — — — — — — UU — — — —

70: — — — — — — — —

 

  • I2C 写地址相关数据

sudo i2cset -y <bus_number> <device_address> <register_address> <value>

<value> 是要写入的值。

sudo i2ctransfer -f -y 1 w3@0x36 0x50 0x81 0x01

 

  • I2C 读相关数据

读取 I2C 设备寄存器:使用 i2cget 命令。

sudo i2cget -y <bus_number> <device_address> <register_address>

<device_address> 是设备的地址,

<register_address> 是要读取的寄存器地址

I2Cget -y -f 0 0x22 0x01

0x22: 设备I2C地址

0x01:地址

 

posted @ 2023-07-21 14:51  zalebool  阅读(266)  评论(0编辑  收藏  举报