.. include:: ../substitutions.rst .. include:: stdout.rst I2C === The phyCORE-RT1170 module provides support for Inter-Integrated Circuit (I2C) communication, enabling connections with a variety of external I2C-compatible devices. This standard two-wire bus is commonly used for low-speed communication between integrated circuits on the same board or across short distances. The i.MX RT1170 processor includes two I2C controllers. For in-depth technical information, refer to the *I2C Interface* chapter in the |hw-manual-link|. I2C Buses --------- The phyBOARD-Atlas RT1170 exposes two I2C buses through the carrier board: * ``lpi2c2`` * ``lpi2c5`` Each bus is connected to specific onboard peripherals, as shown below. .. list-table:: lpi2c2 Devices :header-rows: 1 * - Interface - Address (7-bit) * - EEPROM - 0x50 * - EEPROM Identification Page - 0x58 .. list-table:: lpi2c5 Devices :header-rows: 1 * - Interface - Address (7-bit) * - Audio Codec - 0x18 * - Accelerometer/Gyroscope (ICM-40627) - 0x69 Accessing I2C Devices via Shell ------------------------------- To interact with I2C devices from the command line, begin by scanning the bus for connected peripherals. The example below scans the ``lpi2c5`` bus: .. code-block:: console :substitutions: |target-prompt| i2c scan lpi2c5 |intf-i2c-scan| In this case, the scan reveals two devices: the audio codec at address ``0x18`` and the accelerometer at address ``0x69``. To read a register from a device, use the ``i2c read`` command followed by the bus name, device address, and register offset: .. code-block:: console :substitutions: |target-prompt| i2c read lpi2c5 0x18 0 |intf-i2c-read| .. note:: Direct register access via the I2C shell commands is primarily intended for debugging. For production use, it is strongly recommended to access I2C devices through dedicated drivers whenever possible. ICM-40627 Accelerometer/Gyroscope Example ------------------------------------------ Rather than reading raw registers, devices with a Zephyr sensor driver, such as the ICM-40627 at ``0x69``, can be read through the sensor shell subsystem. Use ``sensor get`` with the device's node name to fetch all of its channels: .. code-block:: console :substitutions: |target-prompt| sensor get icm40627@69 .. code-block:: none :caption: Expected Output channel type=0(accel_x) index=0 shift=6 num_samples=1 value=9869222577ns (-2.748544) channel type=1(accel_y) index=0 shift=6 num_samples=1 value=9869222577ns (-0.622493) channel type=2(accel_z) index=0 shift=6 num_samples=1 value=9869222577ns (7.067682) channel type=3(accel_xyz) index=0 shift=6 num_samples=1 value=9869222577ns, (-2.748544, -0.622493, 7.067682) channel type=4(gyro_x) index=0 shift=6 num_samples=1 value=9869222577ns (-0.002128) channel type=5(gyro_y) index=0 shift=6 num_samples=1 value=9869222577ns (-0.004256) channel type=6(gyro_z) index=0 shift=6 num_samples=1 value=9869222577ns (0.010641) channel type=7(gyro_xyz) index=0 shift=6 num_samples=1 value=9869222577ns, (-0.002128, -0.004256, 0.010641) channel type=12(die_temp) index=0 shift=6 num_samples=1 value=9869222577ns (36.594201) The accelerometer and gyroscope channels report values in m/s² and rad/s respectively, and ``die_temp`` reports the sensor's internal die temperature in °C. EEPROM Uptime Counter Example ----------------------------- .. jinja:: :file: templates/i2c-uptime-counter.jinja Source Code ~~~~~~~~~~~ .. literalinclude :: source-code/uptime_counter.c :language: c For more information see the |http-link-intf-i2c-uptime-counter| file. .. include:: ../../common/support-disclaimer-us.rst