Sei sulla pagina 1di 3

Last update: 2010/06/09 01:26

bootloaders:u-boot:i2c http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:i2c

Das U-Boot and I2C


Das U-Boot supports I2C busses and provides a simple C API to people developing code as well as a command line interface.

Configuration
For hardware I2C busses, you need the hard define as well as a specific driver: #define CONFIG_HARD_I2C /* Always defined for hardware I2C support */ #define CONFIG_BFIN_TWI_I2C /* Selects the Blackfin on-chip TWI peripheral driver */ #define CONFIG_SYS_I2C_SPEED /* default speed (in HZ) */ #define CONFIG_SYS_I2C_SLAVE 0 For software I2C busses, you need the soft define as well as a bunch of helper macros (see the top level README): #define CONFIG_SOFT_I2C /* Always defined for software I2C support */ #define #define #define #define #define #define #define I2C_INIT /* initialize your software i2c */ I2C_ACTIVE /* activate SDA */ I2C_TRISTATE /* deactivate SDA */ I2C_READ /* read SDA */ I2C_SDA(bit) /* set SDA to <bit> */ I2C_SCL(bit) /* set SCL to <bit> */ I2C_DELAY /* delay some time */

#define CONFIG_SYS_I2C_SPEED /* default speed (in HZ) */ #define CONFIG_SYS_I2C_SLAVE 0 For the command line I2C interface: #define CONFIG_CMD_I2C

I2C API
The I2C API is documented in the include/i2c.h header. Consult that for more information.

Command Line Interface


With the i2c command, you can get low level access (usually for debugging purposes) straight from
http://docs.blackfin.uclinux.org/ Printed on 2011/03/09 20:28

http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:i2c bootloaders:u-boot:i2c

Last update: 2010/06/09 01:26

the command line.

Usage
bfin> <strong>help i2c</strong> i2c - I2C sub-system Usage: i2c speed [speed] - show or set I2C bus speed i2c dev [dev] - show or set current I2C bus i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing) i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill) i2c nm chip address[.0, .1, .2] - write to I2C device (constant address) i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum i2c probe - show devices on the I2C bus i2c reset - re-init the I2C Controller i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device Here you can easily set the I2C speed, select a different bus (for when the driver supports more than 1 I2C bus at a time), or reset the cotroller.

Probing
The i2c probe command allows for quickly discovering any clients on the I2C bus. Here you can see an I2C slave being found at address 0x20: bfin> <strong>i2c probe</strong> Valid chip addresses: 20

Reading
The i2c md command allows you to quickly read specific registers from an I2C device. To read 16 registers starting at register 0 from slave 0x20: bfin> <strong>i2c md 0x20 0 0x10</strong>

Writing
There are a few I2C sub-commands to write to a device in a variety of ways. You can interactively enter values starting at register 0x5 (and auto-incrementing to the next register) to slave 0x20: bfin> <strong>i2c mm 0x20 0x5</strong>
Printed on 2011/03/09 20:28 http://docs.blackfin.uclinux.org/

Last update: 2010/06/09 01:26

bootloaders:u-boot:i2c http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:i2c

Or you can interactively enter values at register 0x5 over and over to slave 0x20: bfin> <strong>i2c nm 0x20 0x5</strong> You can write a 0x30 registers starting at register 0x5 with a specific value of 0x18 to slave 0x20: bfin> <strong>i2c mw 0x20 0x5 0x18 0x30</strong>

From: http://docs.blackfin.uclinux.org/ - Analog Devices | Mixed-signal and Digital Signal Processing ICs Permanent link: http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:i2c Last update: 2010/06/09 01:26

http://docs.blackfin.uclinux.org/

Printed on 2011/03/09 20:28

Potrebbero piacerti anche