i2cset 使用说明

NAME

i2cset - set I2C registers

SYNOPSIS

i2cset [-f] [-y] [-m mask] [-r] [-ai2cbus chip-address data-address [value] ... [mode]
i2cset -V

DESCRIPTION

i2cset is a small helper program to set registers visible through the I2C bus.

OPTIONS

-V

Display the version and exit.

-f

Force access to the device even if it is already busy. By default, i2cset will refuse to access a device which is already under the control of a kernel driver. Using this flag is dangerous, it can seriously confuse the kernel driver in question. It can also cause i2cset to silently write to the wrong register. So use at your own risk and only if you know what you're doing.

-y

Disable interactive mode. By default, i2cset will wait for a confirmation from the user before messing with the I2C bus. When this flag is used, it will perform the operation directly. This is mainly meant to be used in scripts.

-m mask

The mask parameter, if specified, describes which bits of value will be actually written to data-address. Bits set to 1 in the mask are taken from value, while bits set to 0 will be read from data-address and thus preserved by the operation. Please note that this parameter assumes that the read and write operations for the specified mode are symmetrical for the device you are accessing. This may or may not be the case, as neither I2C nor SMBus guarantees this.

-r

Read back the value right after writing it, and compare the result with the value written. This used to be the default behavior. The same limitations apply as those of option -m.

-a

Allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. Not recommended.

There are three required options to i2cset. i2cbus indicates the number or name of the I2C bus to be scanned. This number should correspond to one of the busses listed by i2cdetect -lchip-address specifies the address of the chip on that bus, and is an integer between 0x08 and 0x77. data-address specifies the address on that chip to write to, and is an integer between 0x00 and 0xFF.

The value parameter, if specified, is the value to write to that location on the chip. If this parameter is omitted, then a short write is issued. For most chips, it simply sets an internal pointer to the target location, but doesn't actually write to that location. For a few chips though, in particular simple ones with a single register, this short write is an actual write. If the mode parameter is s or i, multiple values can be specified.

The mode parameter, if specified, is one of the letters bws, or i, corresponding to a write size of a single byte, a 16-bit word, a SMBus block write, or an I2C block write, respectively. For SMBus and I2C block writes, the write size is determined by the number of value parameters. Except for I2C block writes, a p can also be appended to the mode parameter to enable PEC. If the mode parameter is omitted, i2cset defaults to byte mode without PEC. The value provided must be within range for the specified data type (0x00-0xFF for byte and block writes, 0x0000-0xFFFF for words). Another possible mode is c, which doesn't write any value (so-called short write). You usually don't have to specify this mode, as it is the default when no value is provided, unless you also want to enable PEC.

WARNING

i2cset can be extremely dangerous if used improperly. It can confuse your I2C bus, cause data loss, or have more serious side effects. Writing to a serial EEPROM on a memory DIMM (chip addresses between 0x50 and 0x57) may DESTROY your memory, leaving your system unbootable! Be extremely careful using this program.

EXAMPLES

Write value 0x42 to 8-bit register 0x11 of the I2C device at 7-bit address 0x2d on bus 1 (i2c-1), after user confirmation:

# i2cset 1 0x2d 0x11 0x42

Immediately clear the 3 least significant bits of 8-bit register 0x11 of the I2C device at 7-bit address 0x2d on bus 1 (i2c-1) (no user confirmation):

# i2cset -y -m 0x07 1 0x2d 0x11 0x00

Write value 0x5000 to 16-bit register 0x02 of the I2C device at 7-bit address 0x48 on bus 1 (i2c-1), after user confirmation:

# i2cset 1 0x48 0x02 0x5000 w

Also see i2cget(8) for examples of combined usage of i2cset and i2cget.

BUGS

To report bugs or send fixes, please write to the Linux I2C mailing list <linux-i2c@vger.kernel.org> with Cc to the current maintainer: Jean Delvare <jdelvare@suse.de>.

SEE ALSO

i2cdetect(8)i2cdump(8)i2cget(8)i2ctransfer(8)isaset(8)

AUTHOR

Frodo Looijaard, Mark D. Studebaker and Jean Delvare

<think>好的,用户想了解i2cset命令中块传输的用法,需要具体的示例。首先,我得回忆一下i2cset的基本结构。根据引用[1],i2c命令的通用格式是i2c<tool> [-options] BUS CHIP [ADDRESS] [VALUE] [MODE]。所以i2cset作为工具之一,应该遵循这个格式。 块传输通常用于一次写入多个字节数据,可能涉及不同的模式,比如字节模式(byte)或字模式(word)。需要确定i2cset支持的选项,比如-b代表字节模式,-w代表字模式。然后,用户需要具体的命令示例,比如写入多个寄存器值的情况。 还要注意设备地址和寄存器地址的格式,通常是十六进制。比如,假设总线是0,设备地址是0x50,寄存器起始地址是0x10,要写入三个字节的数据0xAA, 0xBB, 0xCC,对应的命令应该是i2cset -y 0 0x50 0x10 0xAA 0xBB 0xCC i,这里的i选项可能表示块写入。 另外,用户可能需要了解模式选项的区别,比如i和s的区别,比如s可能使用SMBus块写入。需要确认不同模式的使用场景和语法是否正确。还要提醒用户注意权限问题,可能需要sudo,以及设备是否支持块传输功能。 最后,生成相关问题时要围绕i2cset的其他用法、错误处理、SMBus和I2C的区别,以及查看支持情况的方法。需要确保引用正确的参考资料,特别是引用[1]中的命令格式和引用[3]中的函数结构可能相关的部分。</think>### i2cset块传输命令使用方法 i2cset命令的块传输功能用于向I2C设备连续写入多个字节数据。其核心语法基于引用[1]的通用格式,并添加块传输专用参数: ```bash i2cset -y [总线号] [芯片地址] [起始地址] [数据1] [数据2] ... [数据n] [模式] ``` #### 关键参数说明: - `-y`:跳过交互确认 - 总线号:I2C总线编号(如0, 1) - 芯片地址:十六进制设备地址(如0x50) - 起始地址:寄存器起始地址 - 数据:要写入的十六进制字节序列 - 模式:`i`(I2C块写入)或 `s`(SMBus块写入) #### 使用示例: 1. **基本块写入(字节模式)** ```bash sudo i2cset -y 0 0x50 0x10 0xAA 0xBB 0xCC i ``` 该命令向总线0上的0x50设备,从寄存器0x10开始连续写入3个字节:0xAA, 0xBB, 0xCC[^1] 2. **SMBus块写入模式** ```bash sudo i2cset -y 1 0x68 0x00 0x01 0x02 0x03 s ``` 使用SMBus协议向总线1的0x68设备写入3个字节数据,数据前会自动添加长度字节[^1] 3. **带偏移量的块写入** ```bash sudo i2cset -y 2 0x20 0xA0 0x11 0x22 0x33 i ``` 向总线2的0x20设备,从偏移地址0xA0开始写入三个参数 #### 注意事项: 1. 需要root权限执行(使用sudo) 2. 实际设备地址需查看芯片手册 3. 模式选择需根据设备支持的协议类型 4. 数据长度受I2C适配器限制(通常≤32字节) 5. 可配合`i2cdetect`命令检测设备地址有效性 相关底层实现可参考I2C核心模块的__i2c_bit_add_bus函数结构[^2],以及数据接收函数i2c_receive_data的处理逻辑[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大余里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值