i2c-测试工具
一、介绍
二、使用步骤
1. i2cdetect
root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdetect Error: No i2c-bus specified! Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST] i2cdetect -F I2CBUS i2cdetect -l I2CBUS is an integer or an I2C bus name If provided, FIRST and LAST limit the probing range. root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import warnings warnings.filterwarnings('ignore') import ssl ssl._create_default_https_context = ssl._create_unverified_context
2. i2cdetect -l
root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdetect -l i2c-3 i2c OMAP I2C adapter I2C adapter i2c-2 i2c OMAP I2C adapter I2C adapter i2c-0 i2c OMAP I2C adapter I2C adapter root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051#
2. i2cdump -f -y 3 0x51
用i2cdump查看器件所有寄存器的值,-y 后接的参数是挂在的I2C总线,0x51是I2C设备地址。
root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdump -f -y 3 0x51 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: 30 30 30 30 30 30 0a 30 30 30 30 30 30 30 30 30 000000?000000000 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051#
2. echo “123456789” > /sys/class/i2c-dev/i2c-3/device/3-0051/eeprom
root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# echo "123456789" > /sys/class/i2c-dev/i2c-3/device/3-0051/eeprom root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdump -f -y 3 0x51 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: 31 32 33 34 35 36 37 38 39 0a 30 30 30 30 30 30 123456789?000000 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051#
2. i2cget
i2cget 看单个寄存器地址, 以总线3上0x43 0x01这个寄存器为例 root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cget Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]] I2CBUS is an integer or an I2C bus name ADDRESS is an integer (0x03 - 0x77) MODE is one of: b (read byte data, default) w (read word data) c (write byte/read byte) Append p for SMBus PEC root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051#
2. i2cset
root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cset Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE] I2CBUS is an integer or an I2C bus name ADDRESS is an integer (0x03 - 0x77) MODE is one of: c (byte, no value) b (byte data, default) w (word data) i (I2C block data) s (SMBus block data) Append p for SMBus PEC root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cset -f -y 3 0x51 0x1 0xc root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdump -f -y 3 0x51 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: 31 0c 33 34 35 36 37 38 39 61 62 63 0a 30 30 30 1?3456789abc?000 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cset -f -y 3 0x51 0x1 0x11 root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051# i2cdump -f -y 3 0x51 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: 31 11 33 34 35 36 37 38 39 61 62 63 0a 30 30 30 1?3456789abc?000 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ root@AM57xx-Tronlong:/sys/class/i2c-dev/i2c-3/device/3-0051#