summaryrefslogtreecommitdiff
path: root/tools/i2cget.8
blob: e0b8644dcc2c37008f5da2a1081d03038ca521c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
.TH I2CGET 8 "July 2021"
.SH "NAME"
i2cget \- read from I2C/SMBus chip registers

.SH SYNOPSIS
.B i2cget
.RB [ -f ]
.RB [ -y ]
.RB [ -a ]
.I i2cbus
.I chip-address
.RI [ "data-address " [ "mode " [ length ]]]
.br
.B i2cget
.B -V

.SH DESCRIPTION
i2cget is a small helper program to read registers visible through the I2C
bus (or SMBus).

.SH OPTIONS
.TP
.B -V
Display the version and exit.
.TP
.B -f
Force access to the device even if it is already busy. By default, i2cget
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 i2cget to return an invalid
value. So use at your own risk and only if you know what you're doing.
.TP
.B -y
Disable interactive mode. By default, i2cget 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. Use with caution.
.TP
.B -a
Allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. Not recommended.
.PP
There are two required options to i2cget. \fIi2cbus\fR indicates the number
or name of the I2C bus to be scanned.  This number should correspond to one of
the busses listed by \fIi2cdetect -l\fR. \fIchip-address\fR specifies the
address of the chip on that bus, and is an integer between 0x08 and 0x77.
.PP
\fIdata-address\fR specifies the address on that chip to read from, and is
an integer between 0x00 and 0xFF. If omitted, the currently active register
will be read (if that makes sense for the considered chip).
.PP
The \fImode\fR parameter, if specified, is one of the letters \fBb\fP,
\fBw\fP, \fBc\fP, or \fBi\fP, corresponding to a read byte data, a read
word data, a write byte/read byte, or an I2C block read transaction,
respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to
enable PEC, except for I2C block transactions. If the \fImode\fR
parameter is omitted,
i2cget defaults to a read byte data transaction, unless \fIdata-address\fR is
also omitted, in which case the default (and only valid) transaction is a
single read byte.
.PP
The \fIlength\fR parameter, if applicable and specified, sets the length
of the block transaction. Valid values are between 1 and 32. Default value
is 32.

.SH WARNING
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 setting \fImode\fR to \fBcp\fP (write byte/read
byte with PEC). Be extremely careful using this program.

.SH EXAMPLES
.PP
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:
.nf
.RS
# i2cget 1 0x2d 0x11
.RE
.fi
.PP
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:
.nf
.RS
# i2cget 1 0x48 0x00 w
.RE
.fi
.PP
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:
.nf
.RS
# i2cset -y 9 0x50 0x00 ; i2cget -y 9 0x50 ; i2cget -y 9 0x50
.RE
.fi
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.
.PP
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:
.nf
.RS
# i2cset -y 9 0x53 0x00 0x00 ; i2cget -y 9 0x53 ; i2cget -y 9 0x53
.RE
.fi
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 \fIwrite\fR 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 \fIi2ctransfer\fR to achieve the same in a safe and faster way.
.PP
Read the first 8 bytes of an EEPROM device at 7-bit address 0x50
on bus 4 (i2c-4):
.nf
.RS
# i2cget -y 4 0x50 0x00 i 8
.RE
.fi

.SH 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>.

.SH SEE ALSO
i2cdetect(8), i2cdump(8), i2cset(8), i2ctransfer(8)

.SH AUTHOR
Jean Delvare

This manual page was strongly inspired from those written by David Z Maze
for i2cset.