I2C(8)
π I2C(8) β System Managerβs Manual π
okay so bestie, this is i2c β yes, the page is called I2C(8), and itβs from the System Managerβs Manual. Itβs the utility that lets you do raw data transfers (read or write) to devices on an I2C bus. It can also scan the bus for available devices and reset the I2C controller. iconic behavior honestly π
β¨ NAME β¨
i2c β test I2C bus and slave devices
π SYNOPSIS π
i2c -a address [-f device] [-d r|w] [-w 0|8|16|16LE|16BE] [-o offset]
[-c count] [-m tr|ss|rs|no] [-b] [-v]
i2c -h
i2c -i [-v] [cmd ...] [-]
i2c -r [-f device] [-v]
i2c -s [-f device] [-n skip_addr] [-v]
π DESCRIPTION π
okay so hereβs the whole vibe: i2c can be used to perform raw data transfers (read or write) to devices on an I2C bus. It can also scan the bus for available devices and reset the I2C controller. lowkey powerful, highkey useful π¦
The options are as follows, and yes bestie, Iβm listing every single one:
-aaddress β 7-bit address on the I2C device to operate on (hex).-bβ binary mode - when performing a read operation, the data read from the device is output in binary format on stdout.-ccount β number of bytes to transfer (decimal).-dr|w β transfer direction:r- read,w- write. Data to be written is read from stdin as binary bytes.-fdevice β I2C bus to use (default is/dev/iic0).-iβ Interpreted mode.-hβ Help.-mtr|ss|rs|no β addressing mode, i.e., I2C bus operations performed after the offset for the transfer has been written to the device and before the actual read/write operation.trβ complete-transferssβ stop then startrsβ repeated startnoβ none
Some I2C bus hardware does not provide control over the individual start, repeat-start, and stop operations. Such hardware can only perform a complete transfer of the offset and the data as a single operation. The tr mode creates control structures describing the transfer and submits them to the driver as a single complete transaction. This mode works on all types of I2C hardware.
-nskip_addr β address(es) to be skipped during bus scan. One or more addresses ([0x]xx) or ranges of addresses ([0x]xx-[0x]xxor[0x]xx..[0x]xx) separated by commas or colons.-ooffset β offset within the device for data transfer (hex). The default is zero. Use-w 0to disable writing of the offset to the slave.-rβ reset the controller.-sβ scan the bus for devices.-vβ be verbose.-w0|8|16|16LE|16BE β device offset width (in bits). This is used to determine how to pass offset specified with-oto the slave. Zero means that the offset is ignored and not passed to the slave at all. The endianness defaults to little-endian.
π INTERPRETED MODE π
When started with -i any remaining arguments are interpreted as commands, and if the last argument is '-', or there are no arguments, commands will (also) be read from stdin. yes bestie, itβs giving little command language moment π
Available commands:
'r' bus address [0|8|16|16BE] offset countβ Read command,countbytes are read and hexdumped to stdout.'w' bus address [0|8|16|16BE] offset hexstringβ Write command,hexstring(white-space is allowed) is written to device.'p' anythingβ Print command, the entire line is printed to stdout. (This can be used for synchronization.)
All numeric fields accept canonical decimal/octal/hex notation.
Without the -v option, all errors are fatal with non-zero exit status.
With the -v option, no errors are fatal, and all commands will return either "OK\n" or "ERROR\n" on stdout. In case of error, detailed diagnostics will precede that on stderr.
Blank lines and lines starting with '#' are ignored.
πΈ EXAMPLES πΈ
- Scan the default bus (
/dev/iic0) for devices:
i2c -s
- Scan the default bus (
/dev/iic0) for devices and skip addresses0x45to0x47(inclusive) and0x56.
i2c -s -n 0x56,45-47
- Read 8 bytes of data from device at address
0x56(e.g., an EEPROM):
i2c -a 0x56 -d r -c 8
- Write 16 bytes of data from file
data.binto device0x56at offset0x10:
i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
- Copy 4 bytes between two EEPROMs (
0x56on/dev/iic1to0x57on/dev/iic0):
i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
- Reset the controller:
i2c -f /dev/iic1 -r
- Read 8 bytes at address
24in an EEPROM:
i2c -i 'r 0 0x50 16BE 24 8'
- Read 2x8 bytes at address
24and48in an EEPROM:
echo 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
β οΈ WARNING β οΈ
Many systems store critical low-level information in I2C memories, and may contain other I2C devices, such as temperature or voltage sensors. Reading these can disturb the firmware's operation and writing to them can "brick" the hardware.
bestie I am not kidding, this is the part where you slow down and read twice. critical low-level info is not a vibe to poke at casually π
π SEE ALSO π
π°οΈ HISTORY π°οΈ
The i2c utility appeared in FreeBSD 8.0.
π AUTHORS π
The i2c utility and this manual page were written by Bartlomiej Sieka (<tur@semihalf.com>) and Michal Hajduk (<mih@semihalf.com>).
Poul-Henning Kamp (<phk@FreeBSD.org>) added interpreted mode.
π source/version: Debian Β· date: May 22, 2019 Β· page: I2C(8) β okay thatβs the whole page, ily, bye bestie! π π«Ά
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms