2020-07-23 15:19:35 +02:00
|
|
|
|
# System / `i2c` I2C Tool
|
|
|
|
|
|
|
|
|
|
The I2C tool provides a way to debug I2C related problems. This README file will
|
|
|
|
|
provide usage information for the I2C tools.
|
|
|
|
|
|
|
|
|
|
## Contents
|
|
|
|
|
|
|
|
|
|
- System Requirements
|
|
|
|
|
- I2C Driver
|
|
|
|
|
- Configuration Options
|
|
|
|
|
- Help
|
|
|
|
|
- Common Line Form
|
|
|
|
|
- Common Command Options
|
|
|
|
|
- _Sticky_ Options
|
|
|
|
|
- Environment variables
|
|
|
|
|
- Common Option Summary
|
|
|
|
|
- Command summary
|
|
|
|
|
- `bus`
|
|
|
|
|
- `dev`
|
|
|
|
|
- `get`
|
|
|
|
|
- `set`
|
|
|
|
|
- `verf`
|
|
|
|
|
- I2C Build Configuration
|
|
|
|
|
- NuttX Configuration Requirements
|
|
|
|
|
- I2C Tool Configuration Options
|
|
|
|
|
|
|
|
|
|
## System Requirements
|
|
|
|
|
|
|
|
|
|
The I2C tool is designed to be implemented as a NuttShell (NSH) add-on. Read the
|
|
|
|
|
`apps/nshlib/README.md` file for information about add-ons.
|
|
|
|
|
|
|
|
|
|
### Configuration Options
|
|
|
|
|
|
|
|
|
|
- `CONFIG_NSH_BUILTIN_APPS` – Build the tools as an NSH built-in command.
|
|
|
|
|
- `CONFIG_I2CTOOL_MINBUS` – Smallest bus index supported by the hardware
|
|
|
|
|
(default `0`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXBUS` – Largest bus index supported by the hardware
|
|
|
|
|
(default `3`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MINADDR` – Minimum device address (default: `0x03`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXADDR` – Largest device address (default: `0x77`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXREGADDR` – Largest register address (default: `0xff`).
|
|
|
|
|
- `CONFIG_I2CTOOL_DEFFREQ` – Default frequency (default: `4000000`).
|
|
|
|
|
|
|
|
|
|
## Help
|
|
|
|
|
|
|
|
|
|
First of all, the I2C tools supports a pretty extensive help output. That help
|
|
|
|
|
output can be view by entering either:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
nsh> i2c help
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
nsh> i2c ?
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Here is an example of the help output. I shows the general form of the command
|
|
|
|
|
line, the various I2C commands supported with their unique command line options,
|
|
|
|
|
and a more detailed summary of the command I2C command options.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
nsh> i2c help
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Usage: i2c <cmd> [arguments]
|
|
|
|
|
Where <cmd> is one of:
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Show help : ?
|
|
|
|
|
List buses : bus
|
|
|
|
|
List devices : dev [OPTIONS] <first> <last>
|
2021-02-23 13:50:54 +01:00
|
|
|
|
Read register : get [OPTIONS] [<repetitions>]
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Show help : help
|
2021-02-23 13:50:54 +01:00
|
|
|
|
Write register: set [OPTIONS] <value> [<repetitions>]
|
|
|
|
|
Verify access : verf [OPTIONS] <value> [<repetitions>]
|
2020-07-23 15:19:35 +02:00
|
|
|
|
|
|
|
|
|
Where common _sticky_ OPTIONS include:
|
2013-06-02 01:25:16 +02:00
|
|
|
|
[-a addr] is the I2C device address (hex). Default: 03 Current: 03
|
|
|
|
|
[-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
|
|
|
|
|
[-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
|
|
|
|
|
[-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
|
|
|
|
|
[-s|n], send/don't send start between command and data. Default: -n Current: -n
|
2021-02-23 13:50:54 +01:00
|
|
|
|
[-i|j], Auto increment|don't increment regaddr on repetitions. Default: NO Current: NO
|
2013-06-02 01:25:16 +02:00
|
|
|
|
[-f freq] I2C frequency. Default: 100000 Current: 100000
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Notes**:
|
|
|
|
|
|
|
|
|
|
- An environment variable like `$PATH` may be used for any argument.
|
|
|
|
|
- Arguments are _sticky_. For example, once the I2C address is specified, that
|
|
|
|
|
address will be re-used until it is changed.
|
|
|
|
|
|
|
|
|
|
**Warning**:
|
|
|
|
|
|
|
|
|
|
- The I2C dev command may have bad side effects on your I2C devices. Use only at
|
|
|
|
|
your own risk.
|
|
|
|
|
|
|
|
|
|
## Command Line Form
|
|
|
|
|
|
|
|
|
|
The I2C is started from NSH by invoking the `i2c` command from the NSH command
|
|
|
|
|
line. The general form of the `i2c` command is:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
i2c <cmd> [arguments]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Where `<cmd>` is a _sub-command_ and identifies one I2C operations supported by
|
|
|
|
|
the tool. `[arguments]` represents the list of arguments needed to perform the
|
|
|
|
|
I2C operation. Those arguments vary from command to command as described below.
|
|
|
|
|
However, there is also a core set of common `OPTIONS` supported by all commands.
|
|
|
|
|
So perhaps a better representation of the general I2C command would be:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
i2c <cmd> [OPTIONS] [arguments]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Where `[OPTIONS]` represents the common options and and arguments represent the
|
|
|
|
|
operation-specific arguments.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
## Common Command Options
|
|
|
|
|
|
|
|
|
|
### _Sticky_ Options
|
|
|
|
|
|
|
|
|
|
In order to interact with I2C devices, there are a number of I2C parameters that
|
|
|
|
|
must be set correctly. One way to do this would be to provide to set the value
|
|
|
|
|
of each separate command for each I2C parameter. The I2C tool takes a different
|
|
|
|
|
approach, instead: The I2C configuration can be specified as a (potentially
|
|
|
|
|
long) sequence of command line arguments.
|
|
|
|
|
|
|
|
|
|
These arguments, however, are _sticky_. They are sticky in the sense that once
|
|
|
|
|
you set the I2C parameter, that value will remain until it is reset with a new
|
|
|
|
|
value (or until you reset the board).
|
|
|
|
|
|
|
|
|
|
### Environment Variables
|
|
|
|
|
|
|
|
|
|
**Note** also that if environment variables are not disabled (by
|
|
|
|
|
`CONFIG_DISABLE_ENVIRON=y`), then these options may also be environment
|
|
|
|
|
variables. Environment variables must be preceded with the special character
|
|
|
|
|
`$`. For example, `PWD` is the variable that holds the current working directory
|
|
|
|
|
and so `$PWD` could be used as a command line argument. The use of environment
|
|
|
|
|
variables on the I2C tools command is really only useful if you wish to write
|
|
|
|
|
NSH scripts to execute a longer, more complex series of I2C commands.
|
|
|
|
|
|
|
|
|
|
### Common Option Summary
|
|
|
|
|
|
|
|
|
|
- `[-a addr]` is the I2C device address (hex). Default: `03` Current: `03`
|
|
|
|
|
|
|
|
|
|
The `[-a addr]` sets the I2C device address. The valid range is `0x03` through
|
|
|
|
|
`0x77` (this valid range is controlled by the configuration settings
|
|
|
|
|
`CONFIG_I2CTOOL_MINADDR` and `CONFIG_I2CTOOL_MAXADDR`). If you are working
|
2013-06-02 01:25:16 +02:00
|
|
|
|
with the same device, the address needs to be set only once.
|
|
|
|
|
|
|
|
|
|
All I2C address are 7-bit, hexadecimal values.
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
**Note 1**: Notice in the `help` output above it shows both default value of the
|
|
|
|
|
I2C address (`03` hex) and the current address value (also `03` hex).
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
**Note 2**: Sometimes I2C addresses are represented as 8-bit values (with bit zero
|
|
|
|
|
indicating a read or write operation). The I2C tool uses a 7-bit
|
|
|
|
|
representation of the address with bit 7 unused and no read/write indication
|
|
|
|
|
in bit 0. Essentially, the 7-bit address is like the 8-bit address shifted
|
|
|
|
|
right by 1.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
**Note 3**: Most I2C bus controllers will also support 10-bit addressing. That
|
|
|
|
|
capability has not been integrated into the I2C tool as of this writing.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `[-b bus]` is the I2C bus number (decimal). Default: `1` Current: `1`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Most devices support multiple I2C devices and also have unique bus numbering.
|
|
|
|
|
This option identifies which bus you are working with now. The valid range of
|
|
|
|
|
bus numbers is controlled by the configuration settings
|
|
|
|
|
`CONFIG_I2CTOOL_MINBUS` and `CONFIG_I2CTOOL_MAXBUS`.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
|
|
|
|
The bus numbers are small, decimal numbers.
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `[-r regaddr]` is the I2C device register address (hex). Default: `00`
|
|
|
|
|
Current: `00`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The I2C set and get commands will access registers on the I2C device. This
|
2013-06-02 01:25:16 +02:00
|
|
|
|
option selects the device register address (sometimes called the sub-address).
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This is an 8-bit hexadecimal value. The maximum value is determined by the
|
|
|
|
|
configuration setting `CONFIG_I2CTOOL_MAXREGADDR`.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `[-w width] `is the data width (8 or 16 decimal). Default: `8` Current: `8`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Device register data may be 8-bit or 16-bit. This options selects one of those
|
|
|
|
|
two data widths.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `[-s|n]`, send/don't send start between command and data. Default: `-n`
|
|
|
|
|
Current: `-n`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This determines whether or not there should be a new I2C START between sending
|
|
|
|
|
of the register address and sending/receiving of the register data.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2021-02-23 13:50:54 +01:00
|
|
|
|
- `[-i|j]`, Auto increment|don't increment `regaddr` on repetitions. Default:
|
2020-07-23 15:19:35 +02:00
|
|
|
|
`NO` Current: `NO`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
On commands that take a optional number of repetitions, the option can be used
|
|
|
|
|
to temporarily increment the `regaddr` value by one on each repetition.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `[-f freq]` I2C frequency. Default: `400000` Current: `400000`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The `[-f freq]` sets the frequency of the I2C device.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
## Command Summary
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
We have already seen the I2C help (or `?`) commands above. This section will
|
2013-06-02 01:25:16 +02:00
|
|
|
|
discuss the remaining commands.
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
### List buses: `bus [OPTIONS]`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command will simply list all of the configured I2C buses and indicate which
|
|
|
|
|
are supported by the driver and which are not:
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
BUS EXISTS?
|
|
|
|
|
Bus 1: YES
|
|
|
|
|
Bus 2: NO
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
|
|
|
|
The valid range of bus numbers is controlled by the configuration settings
|
2020-07-23 15:19:35 +02:00
|
|
|
|
`CONFIG_I2CTOOL_MINBUS` and `CONFIG_I2CTOOL_MAXBUS`.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
### List devices: `dev [OPTIONS] <first> <last>`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The `dev` command will attempt to identify all of the I2C devices on the
|
|
|
|
|
selected bus. The `<first>` and `<last>` arguments are 7-bit, hexadecimal I2C
|
|
|
|
|
addresses. This command will examine a range of addresses beginning with
|
|
|
|
|
`<first>` and continuing through `<last>`. It will request the value of register
|
|
|
|
|
address zero from each device.
|
2018-08-30 14:35:12 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The register address of zero is always used by default. The previous _sticky_
|
|
|
|
|
register address is ignored. Some devices may not respond to ergister address
|
|
|
|
|
zero, however. To work around this, you can provide a new _sticky_ register
|
|
|
|
|
address on the command as an option to the 'dev' command. Then that new _sticky_
|
|
|
|
|
register address will be used instead of the address zero.
|
2018-08-30 14:35:12 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
If the device at an I2C address responds to the read request, then the `dev`
|
|
|
|
|
command will display the I2C address of the device. If the device does not
|
|
|
|
|
respond, this command will display `--`. The resulting display looks like:
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```shell
|
2013-06-02 01:25:16 +02:00
|
|
|
|
nsh> i2c dev 03 77
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
0 1 2 3 4 5 6 7 8 9 a b c d e f
|
2020-07-23 15:19:35 +02:00
|
|
|
|
00: -- -- -- -- -- -- -- -- -- -- -- -- --
|
2013-06-02 01:25:16 +02:00
|
|
|
|
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
|
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
|
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
|
40: -- -- -- -- -- -- -- -- -- 49 -- -- -- -- -- --
|
|
|
|
|
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
|
70: -- -- -- -- -- -- -- --
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Warnings:
|
|
|
|
|
- The I2C dev command may have bad side effects on certain I2C devices. For
|
|
|
|
|
example, if could cause data loss in an EEPROM device.
|
|
|
|
|
- The I2C dev command also depends upon the underlying behavior of the I2C
|
|
|
|
|
driver. How does the driver respond to addressing failures?
|
|
|
|
|
|
|
|
|
|
### Read register: `get [OPTIONS]`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command will read the value of the I2C register using the selected I2C
|
|
|
|
|
parameters in the common options. No other arguments are required.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command with write the 8-bit address value then read an 8- or 16-bit data
|
|
|
|
|
value from the device. Optionally, it may re-start the transfer before obtaining
|
|
|
|
|
the data.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2021-02-23 13:50:54 +01:00
|
|
|
|
An optional `<repetitions>` argument can be supplied to repeat the read
|
2020-07-23 15:19:35 +02:00
|
|
|
|
operation an arbitrary number of times (up to 2 billion). If auto-increment is
|
|
|
|
|
select (`-i`), then the register address will be temporarily incremented on each
|
2021-02-23 13:50:54 +01:00
|
|
|
|
repetitions. The increment is temporary in the since that it will not alter the
|
2020-07-23 15:19:35 +02:00
|
|
|
|
_sticky_ value of the register address.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
On success, the output will look like the following (the data value read will be
|
|
|
|
|
shown as a 4-character hexadecimal number if the 16-bit data width option is
|
|
|
|
|
selected).
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
READ Bus: 1 Addr: 49 Subaddr: 04 Value: 96
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
All values (except the bus numbers) are hexadecimal.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
### Write register: `set [OPTIONS] <value>`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command will write a value to an I2C register using the selected I2C
|
|
|
|
|
parameters in the common options. The value to write must be provided as the
|
|
|
|
|
final, hexadecimal value. This value may be an 8-bit value (in the range
|
|
|
|
|
`00`-`ff`) or a 16-bit value (in the range `0000`-`ffff`), depending upon the
|
|
|
|
|
selected data width.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command will write the 8-bit address value then write the 8- or 16-bit data
|
|
|
|
|
value to the device. Optionally, it may re-start the transfer before writing the
|
|
|
|
|
data.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2021-02-23 13:50:54 +01:00
|
|
|
|
An optional `<repetitions>` argument can be supplied to repeat the write
|
2020-07-23 15:19:35 +02:00
|
|
|
|
operation an arbitrary number of times (up to 2 billion). If auto-increment is
|
|
|
|
|
select (`-i`), then the register address will be temporarily incremented on each
|
2021-02-23 13:50:54 +01:00
|
|
|
|
repetitions. The increment is temporary in the since that it will not alter the
|
2020-07-23 15:19:35 +02:00
|
|
|
|
_sticky_ value of the register address.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
On success, the output will look like the following (the data value written will
|
|
|
|
|
be shown as a 4-character hexadecimal number if the 16-bit data width option is
|
|
|
|
|
selected).
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
WROTE Bus: 1 Addr: 49 Subaddr: 04 Value: 96
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
All values (except the bus numbers) are hexadecimal.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2021-02-23 13:50:54 +01:00
|
|
|
|
### Verify access: `verf [OPTIONS] <value> [<repetitions>]`
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
This command combines writing and reading from an I2C device register. It will
|
|
|
|
|
write a value to an will write a value to an I2C register using the selected I2C
|
|
|
|
|
parameters in the common options just as described for tie `set` command. Then
|
|
|
|
|
this command will read the value back just as described with the `get` command.
|
|
|
|
|
Finally, this command will compare the value read and against the value written
|
|
|
|
|
and emit an error message if they do not match.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
If no value is provided, then this command will use the register address itself
|
|
|
|
|
as the data, providing for a address-in-address test.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2021-02-23 13:50:54 +01:00
|
|
|
|
An optional `<repetitions>` argument can be supplied to repeat the verify
|
2020-07-23 15:19:35 +02:00
|
|
|
|
operation an arbitrary number of times (up to 2 billion). If auto-increment is
|
|
|
|
|
select (`-i`), then the register address will be temporarily incremented on each
|
2021-02-23 13:50:54 +01:00
|
|
|
|
repetitions. The increment is temporary in the since that it will not alter the
|
2020-07-23 15:19:35 +02:00
|
|
|
|
`sticky` value of the register address.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
On success, the output will look like the following (the data value written will
|
|
|
|
|
be shown as a 4-character hexadecimal number if the 16-bit data width option is
|
|
|
|
|
selected).
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
VERIFY Bus: 1 Addr: 49 Subaddr: 04 Wrote: 96 Read: 92 FAILURE
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
All values (except the bus numbers) are hexadecimal.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
## I2C Build Configuration
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
### NuttX Configuration Requirements
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
|
|
|
|
The I2C tools requires the following in your NuttX configuration:
|
|
|
|
|
|
|
|
|
|
1. Application configuration.
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Using `make menuconfig`, select the i2c tool. The following definition should
|
|
|
|
|
appear in your `.config` file:
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```conf
|
|
|
|
|
CONFIG_SYSTEM_I2C=y
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2016-02-02 17:27:50 +01:00
|
|
|
|
2. Device-specific I2C driver support must be enabled:
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```conf
|
|
|
|
|
CONFIG_I2C_DRIVER=y
|
|
|
|
|
```
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The I2C tool will then use the I2C character driver to access the I2C bus.
|
|
|
|
|
These devices will reside at `/dev/i2cN` where `N` is the I2C bus number.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
**Note**: The I2C driver `ioctl` interface is defined in
|
|
|
|
|
`include/nuttx/i2c/i2c_master.h`.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
### I2C Tool Configuration Options
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
The default behavior of the I2C tool can be modified by the setting the options
|
|
|
|
|
in the NuttX configuration. This configuration is the `defconfig` file in your
|
|
|
|
|
configuration directory that is copied to the NuttX top-level directory as
|
|
|
|
|
`.config` when NuttX is configured.
|
2013-06-02 01:25:16 +02:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `CONFIG_NSH_BUILTIN_APPS` – Build the tools as an NSH built-in command.
|
|
|
|
|
- `CONFIG_I2CTOOL_MINBUS` – Smallest bus index supported by the hardware
|
|
|
|
|
(default `0`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXBUS` – Largest bus index supported by the hardware
|
|
|
|
|
(default `3`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MINADDR` – Minimum device address (default: `0x03`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXADDR` – Largest device address (default: `0x77`).
|
|
|
|
|
- `CONFIG_I2CTOOL_MAXREGADDR` – Largest register address (default: `0xff`).
|
|
|
|
|
- `CONFIG_I2CTOOL_DEFFREQ` – Default frequency (default: `4000000`).
|