There are multiple peripheral chips connected to the main chip via the I2C bus. The main chip sends initialization commands through the I2C interface to configure these peripherals. On the I.MX5x platform, at least three key peripherals are typically connected to the I2C bus during system startup: the audio codec SGTL5000, the accelerometer MMA7660, and the PMIC TPS65180 for the E-Ink display. All of these devices are connected to I2C1.
In U-Boot, there is an I2C driver available, and it also provides command-line tools for interacting with I2C devices. However, the default I2C command in U-Boot is limited to a single I2C bus. To use a different I2C bus, such as I2C2, you need to modify the macro definition in the configuration file located at `u-boot-xx/include/configs/mx50_arm2.h`. For example:
```c
#define CONFIG_SYS_I2C_PORT I2C2_BASE_ADDR
```
This change allows the U-Boot environment to communicate with the specified I2C bus.
Regarding hardware connections, the I2C bus consists of only two lines: the clock line (SCL) and the data line (SDA). Each I2C peripheral must have a unique address. It's important to note that both SCL and SDA should be in a high state during hardware initialization. If either line is not high, it may indicate a hardware issue. Before proceeding with software testing, always verify the physical connections and ensure the I2C bus is properly powered and configured.
For I2C operations in U-Boot, several commands are available:
**3.1 I2C Bus Scan**
To detect all I2C devices connected to a specific bus, you can use the `i2c probe` command. This will list all the devices found on the current I2C bus.
Example:
```
U-Boot> i2c probe
```
**3.2 Reading from I2C Devices**
To read data from an I2C device, use the `i2c md` command. For instance, to read 16 registers starting from address 0 of a device with I2C address 0x20:
```
U-Boot> i2c md 0x20 0 16
```
- `md` stands for "memory dump" in the context of I2C.
- `0x20` is the I2C address of the peripheral.
- `0` is the starting register address.
- `16` is the number of registers to read.
**3.3 Writing to I2C Devices**
To write data to an I2C device, use the `i2c mw` command. For example, to write the value `0x12` to register 0x01 of a device with I2C address 0x20:
```
U-Boot> i2c mw 0x20 0x01 0x12
```
- `mw` stands for "memory write" in this context.
- `0x20` is the I2C address.
- `0x01` is the register address.
- `0x12` is the value to be written.
**4. Limitations**
One limitation of the current U-Boot I2C implementation is that it supports only a single I2C bus by default. While reading and writing to devices on the same bus is straightforward, switching between buses requires modifying the source code or recompiling the firmware. This can be inconvenient during development or debugging. Ideally, the tool should allow users to dynamically select which I2C bus to use without changing the code.
Interactive Whiteboard
Interactive whiteboard,COB LED display,touch screen display,LCD whitboard,meeting tablet
Shanghai Really Technology Co.,Ltd , https://www.really-led.com