- I2C Protocol Analyzer; Contact; No content here yet.use the menu instead! Jeff Rowberg| Contact.
- I2C Tools: All i2c tools operate on a specific i2c bus which is identified by number. The applicable i2c bus driver must be installed first. The bus numbers are assigned in the order the i2c bus drivers are installed. The i2c bus number assignments can be listed by i2cdetect -l.
Select Advanced Options -> I2C -> to enable the I2C driver by kernel. Then you can check if the I2C is enabled: lsmod If I2C enabled, the terminal echoes an i2c-bcm2708 device. Else you can also add it manually. Sudo nano /etc/modules append: i2c-bcm2708 i2c-dev I2C-Tools. I2C-Tools are utilities for ease of monitoring and identifying I2C.
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Overview
I2C Tools is a simple but very useful tool for developing I2C related applications, which is also famous in Linux platform. This example just implements some of basic features of I2C Tools based on esp32 console component. As follows, this example supports five command-line tools:
i2cconfig
: It will configure the I2C bus with specific GPIO number, port number and frequency.i2cdetect
: It will scan an I2C bus for devices and output a table with the list of detected devices on the bus.i2cget
: It will read registers visible through the I2C bus.i2cset
: It will set registers visible through the I2C bus.i2cdump
: It will examine registers visible through the I2C bus.
I2c Protocol Tutorial
If you have some trouble in developing I2C related applications, or just want to test some functions of one I2C device, you can play with this example first.
How to use example
Hardware Required
To run this example, you should have one ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC). For test purpose, you should have a kind of device with I2C interface as well. Here we will take the CCS811 sensor as an example to show how to test the function of this sensor without writing any code (just use the command-line tools supported by this example). For more information about CCS811, you can consult the online datasheet.
Pin Assignment:
Note: The following pin assignments are used by default, you can change them with i2cconfig
command at any time.
SDA | SCL | GND | Other | VCC | |
---|---|---|---|---|---|
ESP32 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V |
Sensor | SDA | SCL | GND | WAK | VCC |
**Note: ** There's no need to add an external pull-up resistors for SDA/SCL pin, because the driver will enable the internal pull-up resistors itself.
How Does I2c Communication Work
Configure the project
Configure the project
Open the project configuration menu (idf.py menuconfig
). Then go into Example Configuration
menu.
- You can choose whether or not to save command history into flash in
Store command history in flash
option. - You can set the maximum number of command line arguments under
Maximum number of command line arguments
option. - You can set the command line buffer length under
Command line buffer length
option.
Build and Flash
Run idf.py -p PORT flash monitor
to build and flash the project..
(To exit the serial monitor, type Ctrl-]
.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
Example Output
Check all supported commands and their usages
Configure the I2C bus
--port
option to specify the port of I2C, here we choose port 0 for test.--sda
and--scl
options to specify the gpio number used by I2C bus, here we choose GPIO18 as the SDA and GPIO19 as the SCL.--freq
option to specify the frequency of I2C bus, here we set to 100KHz.
Check the I2C address (7 bits) on the I2C bus
- Here we found the address of CCS811 is 0x5b.
Get the value of status register
-c
option to specify the address of I2C device (acquired fromi2cetect
command).-r
option to specify the register address you want to inspect.-l
option to specify the length of the content.- Here the returned value 0x10 means that the sensor is just in the boot mode and is ready to go into application mode. For more information about CCS811 you should consult the official website.
Change the working mode
- Here we change the mode from boot to application and set a proper measure mode (by writing 0x10 to register 0x01)
- Now the status value of the sensor is 0x98, which means a valid data is ready to read
I2c Tutorial
Read the sensor data
- The register 0x02 will output 8 bytes result, mainly including value of eCO2、TVOC and there raw value. So the value of eCO2 is 0x01b0 ppm and value of TVOC is 0x04 ppb.
Troubleshooting
I2c Example
- I don't find any available address when running
i2cdetect
command.- Make sure your wiring connection is right.
- Some sensor will have a 'wake up' pin, via which user can put the sensor into a sleep mode. So make sure your sensor in not in the sleep state.
- Reset you I2C device, and then run
i2cdetect
again.
- I can't get the right content when running
i2cdump
command.- Currently the
i2cdump
only support those who have the same content length of registers inside the I2C device. For example, if a device have three register addresses, and the content length at these address are 1 byte, 2 bytes and 4 bytes. In this case you should not expect this command to dump the register correctly.
- Currently the
- I really input argument correctly, but the command line 'discard' the last few arguements from time to time.
- Enlarge the maximum number of arguments in the menuconfig.
How To Use I2c Tools
(For any technical queries, please open an issue on GitHub. We will get back to you as soon as possible.)