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. These include the audio codec SGTL5000, the accelerometer MMA7660, and the PMIC TPS65180 for the e-ink display. All of them are connected to I2C1.
In U-Boot, there is a built-in I2C driver along with command-line tools for interacting with I2C devices. However, the standard I2C command in the command line is limited to a single I2C bus. If you need to access different I2C buses, you must modify the macro definitions in the U-Boot configuration file, such as `u-boot-xx/include/configs/mx50_arm2.h`. For example:
```c
#define CONFIG_SYS_I2C_PORT I2C2_BASE_ADDR
```
This defines which I2C bus is used by default. Hardware connections for the I2C bus involve two lines: SCL (clock) and SDA (data). Each I2C device must have a unique address. It's important to note that the I2C bus should be in a high state on both SCL and SDA lines during initialization. If either line is low, it could indicate a hardware issue, so always check the physical connections first before proceeding.
The I2C command in U-Boot provides several useful functions:
**3.1 I2C Bus Scan**
To detect all devices connected to an I2C bus, you can use the `i2c probe` command. This will list all the devices found on the selected I2C bus (e.g., I2C2).
**3.2 Reading from I2C Devices**
For example, to read 16 registers starting from address 0x20, you would use:
```
U-Boot> i2c md 0x20 0 16
```
Here, `md` stands for "memory dump" in the context of I2C.
- `0x20` is the I2C address of the peripheral.
- `0` indicates the starting register address.
- `16` specifies the number of registers to read.
**3.3 Writing to I2C Devices**
To write a value to a specific register, you can use the `i2c mw` command. For instance:
```
U-Boot> i2c mw 0x20 01 0x12
```
- `mw` means "memory write" for I2C.
- `0x20` is the I2C address.
- `01` is the register number.
- `0x12` is the value to be written.
**4. Limitations**
One drawback of the current setup is that it only supports a single I2C bus by default. To access other buses, you need to modify the code or recompile U-Boot with the appropriate settings. This makes it less flexible when working with multiple I2C devices across different buses. In practice, developers often need to adjust the source code to support multi-bus operations, which can be time-consuming but necessary for more complex systems.
Interactive Whiteboard
Interactive whiteboard,COB LED display,touch screen display,LCD whitboard,meeting tablet
Shanghai Really Technology Co.,Ltd , https://www.really-led.com