匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“I2C i2c-tools”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
i2c-tools
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
本文旨在提供一些有用的信息,这些信息对于从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 {{Redtext | 注意:如果寄存器处于只读模式,则写入可能会失败 }} ==自动增量设备== :即使不是I2C标准的一部分,通常也会在I2C设备上找到自动递增功能,尤其是那些处理大量寄存器的设备(通常是I2C RAM或EEPROM)。 :此类设备在每次读取或写入操作时自动递增一个内部地址指针,因此,在同一地址发出多个读取命令时,每次读取返回的值可能每次都不同。 :以下是STM32MP157C-EV1评估板上的WM8994音频编解码器器件的一些示例: :{{Redtext |首先启动音频播放以启动音频编解码器设备(请参阅“ 如何播放音频”) }} :读取WM8994软件复位"0x0000"寄存器地址数据 Board $> i2cget -y 0 0x1b 0x00 w 0x9489 Board $> i2cget -y 0 0x1b 0x00 w 0x0000 Board $> i2cget -y 0 0x1b 0x00 w 0x0060 Board $> i2cset -y 0 0x1b 0x00 0x00 Board $> i2cget -y 0 0x1b 0x00 w 0x9489 ==I2C 传输== Board $> i2ctransfer -f -y <i2cbus number> r<number of bytes>@<peripheral address> Board $> i2ctransfer -f -y <i2cbus number> w<number of bytes>@<peripheral address> <byte value 1> <byte value 2> ... <byte value n> Board $> i2ctransfer -f -y <i2cbus number> w<number of bytes to write>@<peripheral address> <byte value 1> <byte value 2> ... <byte value n> r<number of bytes to read> Example (bus 0, read 8 bytes at offset 0x64 from EEPROM at 0x50) Board $> i2ctransfer 0 w1@0x50 0x64 r8 "w1" for "write 1 byte" (the 0x64 offset), "r8" for "read 8 bytes" Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0) Board $> i2ctransfer 0 w17@0x50 0x42 0xff- "w17" for "write 17 bytes", first 0x42 byte for the offset, and 0xff- for the 16 subsequent bytes ("-" for auto value decrease starting from 0xff). See following chapter for 16 bits addressing devices handling. ==16位设备处理== The I2C standard protocol supports natively 7 bits of address (or 10 bits of address in extended mode) followed by 8 bits of data. However some I2C devices embed 16-bit data registers with internal 16-bit address space. Here is how the i2c-tool allows to drive such devices. To read a 16 bits value, add "w" for "word" at the end of command: Board $> i2cget -f -y <i2cbus number> <peripheral address> <address> w Please note that <address> is 8-bit wide, while the returned data is 16-bit wide. The interpretation of <address> is device dependent (One possible interpretation is that <address> drives the 8 MSB bits of the 16-bit address while the 8 LSB bits are set to 0). To write a 16 bits value specifying the 16 bits address, send both the address and the data as a set of bytes in a single "I2C block write" by adding "i" at the end of i2cset[4] command: Board $> i2cset -f -y <i2cbus number> <peripheral address> <MSB address> <LSB address> <MSB value> <LSB value> i =参考= <references /> [[Category:Linux_Operating_System]][[Category:Low_speed_interface]][[Category:I2C]]
该页面使用的模板:
模板:Redtext
(
查看源代码
)
返回至
i2c-tools
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志