I2CSET(8)

πŸ“¦
version 4.4 Β· 2 versions
, in alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

i2cset β€” set I2C registers, bestie πŸ’–

okay so real talk, this is i2cset from the System Manager's Manual, section 8, and it's literally the tiny little helper that goes and pokes registers on your I2C bus. She's small. She's powerful. She can absolutely ruin your day if you're not careful. Let's get into it πŸ¦‹


✨ SYNOPSIS ✨

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

πŸ’… DESCRIPTION πŸ’…

So i2cset is a small helper program whose whole entire job is to set registers visible through the I2C bus. That's it. That's the gig. She's not complicated, she's just dangerous, which is honestly a vibe 🫢


πŸŽ€ OPTIONS πŸŽ€

  • -V β€” Display the version and then dip. exits immediately πŸ’¨
  • -h β€” Display the help and exit. also dips, but with more info.
  • -f β€” Force access to the device even if it's already busy. By default, i2cset will refuse to touch a device that's 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. (iykyk, and if you don't know, that's your sign not to 🚩)
  • -y β€” Disable interactive mode. By default i2cset will wait for a confirmation from the user before messing with the I2C bus. With this flag it just goes ahead and does the operation directly. Mainly meant to be used in scripts πŸ€–
  • -m mask β€” The mask parameter, if specified, describes which bits of value will actually be 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. Heads up though: this parameter assumes that the read and write operations for the specified mode are symmetrical for the device you're accessing. That may or may not be the case, because neither I2C nor SMBus guarantees it. so... yeah πŸ™ˆ
  • -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, and you do not get to skip them, no cap:

  • i2cbus β€” the number or name of the I2C bus to be scanned. This number should correspond to one of the busses listed by i2cdetect -l.
  • chip-address β€” the address of the chip on that bus, and is an integer between 0x08 and 0x77.
  • data-address β€” 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, that just 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 b, w, s, 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 at all (the 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. πŸ’€

fr fr. this is the part where you read the warning. like actually read it.


🌈 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. they're a duo, they're iconic, they do everything together πŸ’ž


πŸ› 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>. she reads her mail, bestie ✨


πŸ‘€ SEE ALSO πŸ‘€

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


πŸ‘‘ AUTHOR πŸ‘‘

Frodo Looijaard, Mark D. Studebaker and Jean Delvare

This manual page was originally written by David Z Maze <dmaze@debian.org> for the Debian GNU/Linux system.


okay that's the whole page, you're all caught up 🫢 and for the little sign-off moment: this masterpiece dropped in May 2022, it lives under i2cset(8), and yes she's still out here being a System Manager's Manual legend. stay safe, mind the EEPROMs, don't be messy with -f πŸ’–βœ¨πŸŽ€