i2ctransfer(8) | System Manager's Manual | i2ctransfer(8) |
i2ctransfer - send user-defined I2C messages in one transfer
i2ctransfer [-f] [-y] [-v] [-a]
i2cbus desc [data] [desc [data]] ...
i2ctransfer -V
i2ctransfer is a program to create I2C messages and send
them combined as one transfer. For read messages, the contents of the
received buffers are printed to stdout, one line per read message.
Please note the difference between a transfer and a message
here. A transfer may consist of multiple messages and is started with a
START condition and ends with a STOP condition as described in the I2C
specification. Messages within the transfer are concatenated using the
REPEATED START condition which is described there as well. There are some
advantages of having multiple messages in one transfer. First, some devices
keep their internal states for REPEATED START but reset them after a STOP.
Second, you cannot get interrupted during one transfer, but it might happen
between multiple transfers. Interruption could happen on hardware level by
another I2C master on the bus, or at software level by another I2C user who
got its transfer scheduled between yours. This program helps you to create
proper transfers for your needs.
The first parameter i2cbus indicates the number or name of the I2C bus to be used. This number should correspond to one of the busses listed by i2cdetect -l.
The next parameter is one or multiple desc blocks. The number of blocks is limited by the Linux Kernel and defined by I2C_RDWR_IOCTL_MAX_MSGS (42 as of v4.10). desc blocks are composed like this:
{r|w}<length_of_message>[@address]
If the I2C message is a write, then a data block with the data to be written follows. It consists of <length_of_message> bytes which can be marked with the usual prefixes for hexadecimal, octal, etc. To make it easier to create larger data blocks easily, the data byte can have a suffix.
On bus 0, from an EEPROM at address 0x50, read 8 byte from offset 0x64 (first message writes one byte to set the memory pointer to 0x64, second message reads from the same chip):
# i2ctransfer 0 w1@0x50 0x64 r8
For the same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0 (one write message; first byte sets the memory pointer to 0x42, 0xff is the first data byte, all following data bytes are decreased by one):
# i2ctransfer 0 w17@0x50 0x42 0xff-
i2ctransfer 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.
Wolfram Sang, based on i2cget by Jean Delvare
This manual page was originally written by Wolfram Sang based on the manual for i2cset by David Z Maze <dmaze@debian.org>.
February 2017 |