I2C test of NVIDIA Jetson

0 background

Jetson development board has I2C interface. This paper introduces the use of this interface. Taking Jetson TX2 as an example, the methods of other devices are similar, mainly due to the difference of hardware interface

1 hardware connection

Pass< Jetson TX1-TX2 Developer Kit Carrier Board Specification  > It can be seen that the 3rd and 5th pins in the J21 row of pins of TX2 represent SDA and SCL interfaces respectively, which can be connected with the equipment through DuPont line. At the same time, it shall be connected to the equipment in common( Other devices, such as nano/NX, can view their corresponding carrier documents)

  J21 pin is defined as follows

Or view it directly This link , it can be seen that the 3rd and 5th pins are SDA and SCL pins of I2C BUS 1

2 I2C tools

2.1 installation method

In jetpack, the i2c tools tool has been installed to query i2c instructions. If not, you can use apt to install

$ sudo apt-get update
$ sudo apt-get install -y i2c-tools

The I2C tools tool includes the following parts

i2cdetect ---- used to find the address of the connected device

i2cdump ---- used to read the contents of all registers in a specific address

i2cset -------- write contents to a specific register

i2cget ------- read value from specific register

2.2 i2cdetect

The i2cdetect command is used to detect the I2C bus condition on the system

$ sudo i2cdetect -l
i2c-3   i2c             3190000.i2c                             I2C adapter
i2c-1   i2c             c240000.i2c                             I2C adapter
i2c-8   i2c             31e0000.i2c                             I2C adapter
i2c-6   i2c             31c0000.i2c                             I2C adapter
i2c-4   i2c             Tegra BPMP I2C adapter                  I2C adapter
i2c-2   i2c             3180000.i2c                             I2C adapter
i2c-0   i2c             3160000.i2c                             I2C adapter
i2c-7   i2c             c250000.i2c                             I2C adapter
i2c-5   i2c             31b0000.i2c                             I2C adapter

It can be seen that there are 9 groups of I2C interfaces on TX2, which scan each bus respectively to obtain mounting information

i2cdetect -y -r -a 1

Of which:

  • -y means ignoring interaction problems
  • -r is SMBus   read byte command
  • -a is all addresses, and 1 represents i2c-1 of TX2 development board

2.3 i2cdump

i2cdump is used to view the value of the device register

i2cdump [-f] [-y] [-r first-last] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]

Check the values of all registers of device 0x50 on bus 7

$ i2cdump -y 7 0x50
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 01 00 0d 00 ee 0c e8 03 42 44 00 00 00 00 00 00    ?.?.????BD......
10: 00 00 00 00 36 39 39 2d 38 33 33 31 30 2d 31 30    ....699-83310-10
20: 30 30 2d 42 30 32 20 44 2e 30 00 00 00 00 00 00    00-B02 D.0......
30: 00 00 a5 04 a8 4b 04 00 a6 04 a8 4b 04 00 00 00    ..???K?.???K?...
40: 00 00 00 00 a7 04 a8 4b 04 00 30 33 32 30 32 31    ....???K?.032021
50: 38 31 36 39 30 39 39 00 00 00 00 00 00 00 00 00    8169099.........
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
90: 00 00 00 00 00 00 4e 56 43 42 1c 00 4d 31 00 00    ......NVCB?.M1..
a0: a5 04 a8 4b 04 00 a6 04 a8 4b 04 00 a7 04 a8 4b    ???K?.???K?.???K
b0: 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ?...............
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b9    ...............?

2.4 i2cset

i2cset is used to set the value of a single register of the device

i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]

For example, set the address to 0x50 and the value of 0x20 register in the device to 0x04.

$ sudo i2cset -f -y 2 0x50 0x20 0x04

2.5 i2cget

i2cget is used to view the value of a single register of the device

i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
    b (byte, default)
    w (word)
    W (word on even register addresses)
    s (SMBus block)
    i (I2C block)
    c (consecutive byte)
    Append p for SMBus PEC

For example, read the value of 0x20 register in the device with address 0x50.

$ sudo i2cget -y 2 0x50 0x20
0x30

2.6 i2ctransfer

i2ctransfer is used to read and write device register values (can be used for double byte registers)

sudo i2ctransfer -f -y [bus serial number] w [length of data to be written] @ [device address] [high byte of register address] [low byte of register address] r [length of data to be read].

For example, on bus 1, start with device address 0x10 and register address 0x0101, and read data with a length of 16 bytes.

$ sudo i2ctransfer -f -y 1 w2@0x10 0x01 0x01 r16
0x80 0x80 0x00 0x08 0x10 0x1a 0x00 0x00 0x00 0x10 0x27 0x00 0x00 0x40 0x79 0x0d

3 i2c code example

There is an i2c library for linux on github, address: https://github.com/amaork/libi2c

After downloading, it can be used through script installation

git clone https://github.com/amaork/libi2c.git
cd libi2c
sudo python setup.py install

Test script

cd example
python pylibi2c_tools.py -b /dev/i2c-1 -d 0x1b --iaddr 0x0b --data 0x00

It means to write the value 0x00 to the register 0x0b to the device with address 0x1b on bus 1. Other use methods are similar. Refer to the code description  

reference resources

Tags: IoT stm32

Posted on Sun, 05 Sep 2021 18:47:52 -0400 by ninevolt1