I2CGET(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

πŸ’– i2cget β€” bestie edition πŸ’–

okay so. this is i2cget(8), a page from the System Manager's Manual, and it's here to teach you how to read from I2C/SMBus chip registers. yes that's the NAME section. yes we're doing it with sparkle. stay with me ✨


🌸 SYNOPSIS 🌸

i2cget [-f] [-y] [-a] i2cbus chip-address [data-address [mode [length]]]
i2cget -V
i2cget -h

like... that's the whole shape of it. three ways in, one of them is "just give me the version", one is "help me pls", and the big one is the actual reading. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

i2cget is a small helper program whose whole entire job is reading registers that are visible through the I2C bus (or the SMBus, same energy, different dress code). that's it. that's the vibe. it reads. πŸŽ€


✨ OPTIONS ✨

  • -V β€” show me the version and dip. bye bestie πŸ‘‹
  • -h β€” show me the help and dip. also bye πŸ‘‹
  • -f β€” FORCE access to the device even if it's already busy. so by default, i2cget will straight up refuse to touch a device that's already under the control of a kernel driver. with this flag? it does it anyway. and like... > this flag is dangerous. it can seriously confuse the kernel driver in question. it can also make i2cget return an invalid value. so use at your own risk and only if you actually know what you're doing. fr fr. πŸ’€
  • -y β€” disable interactive mode. normally i2cget waits for you to confirm before it starts messing with the I2C bus, which is very "are you sure bestie" of it. with this flag it just... does the operation directly. this is mainly meant to be used in scripts. use with caution. ⚠️
  • -a β€” allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. not recommended. that's the whole note. πŸ™ˆ

🧚 the arguments, bestie

there are two required options to i2cget. yes, required. mandatory. non-negotiable.

  • 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. go look at that list, it's giving inventory 🫢
  • chip-address β€” the address of the chip on that bus. an integer between 0x08 and 0x77.
  • data-address β€” the address on that chip to read from, an integer between 0x00 and 0xFF. if you omit it, the currently active register gets read (if that even makes sense for the chip you're talking to, iykyk).
  • mode β€” if you specify it, it's one of the letters b, w, c, s, or i, and they mean:
    • b β†’ a read byte data
    • w β†’ a read word data
    • c β†’ a write byte/read byte
    • s β†’ an SMBus block read
    • i β†’ an I2C block read transaction

a p can also be appended to the mode parameter to enable PEC β€” except for I2C block transactions, those don't get a p. if the mode parameter is omitted, i2cget defaults to a read byte data transaction... unless data-address is also omitted, in which case the default (and only valid) transaction is a single read byte. cute. consistent. love that for us. 🌈

  • length β€” if applicable and specified, this sets the length of the block transaction. valid values are between 1 and 32. default value is 32. πŸ“

πŸ’€ WARNING πŸ’€

okay so real talk, no jokes for one second:

i2cget can be extremely dangerous if used improperly.

I2C and SMBus are designed in such a way that an SMBus read transaction can be seen as a write transaction by certain chips. this is particularly true if you set mode to cp (write byte/read byte with PEC). be extremely careful using this program. like, both eyes open, hands steady, main character energy but the responsible kind. πŸ”₯


πŸ“ EXAMPLES πŸ“

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

# i2cget 1 0x2d 0x11

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

# i2cget 1 0x48 0x00 w

set the internal pointer register of a 24C02 EEPROM at 7-bit address 0x50 on bus 9 (i2c-9) to 0x00, then read the first 2 bytes from that EEPROM:

# i2cset -y 9 0x50 0x00 ; i2cget -y 9 0x50 ; i2cget -y 9 0x50

this assumes that the device automatically increments its internal pointer register on every read, and supports read byte transactions (read without specifying the register address, "Receive Byte" in SMBus terminology). most EEPROM devices behave that way. note that this is only safe as long as nobody else is accessing the I2C device at the same time. a safer approach would be to use a "Read Word" SMBus transaction instead, or an I2C Block Read transaction to read more than 2 bytes. 🧠

set the internal pointer register of a 24C32 EEPROM at 7-bit address 0x53 on bus 9 (i2c-9) to 0x0000, then read the first 2 bytes from that EEPROM:

# i2cset -y 9 0x53 0x00 0x00 ; i2cget -y 9 0x53 ; i2cget -y 9 0x53

this again assumes that the device automatically increments its internal pointer register on every read, and supports read byte transactions. while the previous example was for a small EEPROM using 8-bit internal addressing, this example is for a larger EEPROM using 16-bit internal addressing. beware that running this command on a small EEPROM using 8-bit internal addressing would actually write 0x00 to the first byte of that EEPROM. 😭 the safety concerns raised above still stand, however in this case there is no SMBus equivalent, so this is the only way to read data from a large EEPROM if your master isn't fully I2C capable. with a fully I2C capable master, you would use i2ctransfer to achieve the same in a safe and faster way. slay. ⭐

read the first 8 bytes of an EEPROM device at 7-bit address 0x50 on bus 4 (i2c-4):

# i2cget -y 4 0x50 0x00 i 8

πŸŽ€ 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>. they want your bug reports, bestie, it's not a bother, it's a contribution πŸ’Œ


πŸ‘‘ SEE ALSO πŸ‘‘

i2cdetect(8), i2cdump(8), i2cset(8), i2ctransfer(8)


🌟 AUTHOR 🌟

Jean Delvare

this manual page was strongly inspired from those written by David Z Maze for i2cset. iconic lineage honestly πŸ’œ


and that's the whole page!! it came from the System Manager's Manual and it was dated May 2022, and the footer signed off as I2CGET(8) β€” so that's us, that's the vibe, go read some registers responsibly, love u, bye πŸ¦‹πŸŒΈπŸ«ΆπŸ’–