“I2C i2c-tools”的版本间的差异
来自百问网嵌入式Linux wiki
第1行: | 第1行: | ||
− | [[Category:Linux_Operating_System]] | + | 本文旨在提供一些有用的信息,这些信息对于从Linux®工具:I2C工具开始很有用。 |
− | + | =简介= | |
− | + | :i2c-tools是一个完整的用户空间软件包,位于I2C子系统之上。它提供: | |
+ | ::Tools:一组I2C程序,无需编写任何代码即可轻松调试I2C外设 | ||
+ | ::libi2c:用于开发应用程序的库。 | ||
+ | =工具列表= | ||
+ | *i2cdetect<ref name="i2cdetect">https://www.mankier.com/8/i2cdetect</ref> | ||
+ | *i2cdump<ref name="i2cdump">https://www.mankier.com/8/i2cdump</ref> | ||
+ | *i2cget <ref name="i2cget">https://www.mankier.com/8/i2cget</ref> | ||
+ | *i2cset <ref name="i2cset">https://www.mankier.com/8/i2cset</ref> | ||
+ | *i2ctransfer <ref name="i2ctransfer">https://www.mankier.com/8/i2ctransfer</ref> | ||
+ | |||
+ | =安装= | ||
+ | |||
+ | =开始使用= | ||
+ | ==设备检测== | ||
+ | :查看哪些外设连接到特定的I2C总线可能非常有帮助。 | ||
+ | :检查所有实例化的I2C适配器: | ||
+ | Board $> i2cdetect -l | ||
+ | :如果实例化了I2C适配器,将显示以下返回: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | i2c-0 i2c ST I2C(0xAAAAAAA) I2C adapter | ||
+ | i2c-1 i2c ST I2C(0xBBBBBBB) I2C adapter | ||
+ | i2c-2 i2c ST I2C(0xCCCCCCC) I2C adapter | ||
+ | i2c-3 i2c ST I2C(0xDDDDDDD) I2C adapter | ||
+ | i2c-4 i2c ST I2C(0xEEEEEEE) I2C adapter | ||
+ | i2c-5 i2c ST I2C(0xFFFFFFF) I2C adapter | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | :获取在特定I2C总线上检测到的外围设备的列表: | ||
+ | Board $> i2cdetect -y <i2cbus number> | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | Board $> i2cdetect -y 3 | ||
+ | 0 1 2 3 4 5 6 7 8 9 a b c d e f | ||
+ | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 40: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- | ||
+ | 50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 70: -- -- -- -- -- -- -- -- | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | :UU- >探测被跳过,因为驱动程序当前正在使用该地址。这强烈表明该地址处有一个设备被驱动程序探测到。 | ||
+ | :有关i2cdetect<ref name="i2cdetect"/>的更多信息 | ||
+ | ==读寄存器== | ||
+ | :从外设读取所有寄存器: | ||
+ | Board $> i2cdump -f -y <i2cbus number> <peripheral address> | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | Board $> i2cdump -f -y 0 0x5f | ||
+ | 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: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bc ...............? | ||
+ | 10: 3f 00 87 33 96 be ec a1 9e b2 fe 00 e8 01 80 82 ?.?3???????.???? | ||
+ | 20: 00 00 00 00 00 00 00 00 51 f2 ae 00 10 f3 c6 00 ........Q??.???. | ||
+ | 30: 41 92 a0 0e 00 c4 ee ff 32 03 bf d3 ff ff d0 02 A???.??.2???..?? | ||
+ | 40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ | ||
+ | 50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ | ||
+ | 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 bc ...............? | ||
+ | 90: 3f 00 87 33 96 be ec a1 9e b2 fe 00 e8 01 80 82 ?.?3???????.???? | ||
+ | a0: 00 00 00 00 00 00 00 00 51 f2 ae 00 10 f3 c6 00 ........Q??.???. | ||
+ | b0: 41 92 a0 0e 00 c4 ee ff 32 03 bf d3 ff ff d0 02 A???.??.2???..?? | ||
+ | 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 ................ | ||
+ | </syntaxhighlight> | ||
+ | :有关i2cdump <ref name="i2cdump "/>的更多信息。 | ||
+ | :要直接读取一个寄存器,请使用i2cget<ref name="i2cget"/>: | ||
+ | Board $> i2cget -f -y <i2cbus number> <peripheral address> | ||
+ | :示例:读取I2c总线0上地址为0x5f的外设寄存器0x0f数据 | ||
+ | Board $> i2cset -f -y 0 0x5f 0x0f 0xac | ||
+ | |||
+ | ==写寄存器== | ||
+ | :要直接写寄存器,请使用i2cset<ref name="i2cset"/> | ||
+ | Board $> i2cset -f -y <i2cbus number> <peripheral address> <value> | ||
+ | |||
+ | :示例:将0xac写入外围设备的寄存器0x0f的总线0的地址0x5f上: | ||
+ | Board $> i2cset -f -y 0 0x5f 0x0f 0xac | ||
+ | |||
+ | |||
+ | |||
+ | =参考= | ||
+ | <references /> | ||
+ | |||
+ | [[Category:Linux_Operating_System]][[Category:Low_speed_interface]][[Category:I2C]] |
2019年12月10日 (二) 17:27的版本
本文旨在提供一些有用的信息,这些信息对于从Linux®工具:I2C工具开始很有用。
简介
- i2c-tools是一个完整的用户空间软件包,位于I2C子系统之上。它提供:
- Tools:一组I2C程序,无需编写任何代码即可轻松调试I2C外设
- libi2c:用于开发应用程序的库。
安装
开始使用
设备检测
- 查看哪些外设连接到特定的I2C总线可能非常有帮助。
- 检查所有实例化的I2C适配器:
Board $> i2cdetect -l
- 如果实例化了I2C适配器,将显示以下返回:
i2c-0 i2c ST I2C(0xAAAAAAA) I2C adapter
i2c-1 i2c ST I2C(0xBBBBBBB) I2C adapter
i2c-2 i2c ST I2C(0xCCCCCCC) I2C adapter
i2c-3 i2c ST I2C(0xDDDDDDD) I2C adapter
i2c-4 i2c ST I2C(0xEEEEEEE) I2C adapter
i2c-5 i2c ST I2C(0xFFFFFFF) I2C adapter
- 获取在特定I2C总线上检测到的外围设备的列表:
Board $> i2cdetect -y <i2cbus number>
Board $> i2cdetect -y 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
- UU- >探测被跳过,因为驱动程序当前正在使用该地址。这强烈表明该地址处有一个设备被驱动程序探测到。
- 有关i2cdetect[1]的更多信息
读寄存器
- 从外设读取所有寄存器:
Board $> i2cdump -f -y <i2cbus number> <peripheral address>
Board $> i2cdump -f -y 0 0x5f
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: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bc ...............?
10: 3f 00 87 33 96 be ec a1 9e b2 fe 00 e8 01 80 82 ?.?3???????.????
20: 00 00 00 00 00 00 00 00 51 f2 ae 00 10 f3 c6 00 ........Q??.???.
30: 41 92 a0 0e 00 c4 ee ff 32 03 bf d3 ff ff d0 02 A???.??.2???..??
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
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 bc ...............?
90: 3f 00 87 33 96 be ec a1 9e b2 fe 00 e8 01 80 82 ?.?3???????.????
a0: 00 00 00 00 00 00 00 00 51 f2 ae 00 10 f3 c6 00 ........Q??.???.
b0: 41 92 a0 0e 00 c4 ee ff 32 03 bf d3 ff ff d0 02 A???.??.2???..??
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 ................
Board $> i2cget -f -y <i2cbus number> <peripheral address>
- 示例:读取I2c总线0上地址为0x5f的外设寄存器0x0f数据
Board $> i2cset -f -y 0 0x5f 0x0f 0xac
写寄存器
- 要直接写寄存器,请使用i2cset[4]
Board $> i2cset -f -y <i2cbus number> <peripheral address> <value>
- 示例:将0xac写入外围设备的寄存器0x0f的总线0的地址0x5f上:
Board $> i2cset -f -y 0 0x5f 0x0f 0xac