uboot i2c 驱动

  • 熟悉i2c 驱动框架并且调试i2c

1.i2c 驱动框架图
uboot i2c 驱动_第1张图片

2.uboot i2c command

help i2c
i2c bus [muxtype:muxaddr:muxchannel] - show I2C bus info
crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
i2c dev [dev] - show or set current I2C bus
i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device
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 probe [address] - test for and show device(s) on the I2C bus
i2c read chip address[.0, .1, .2] length memaddress - read to memory
i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory
to I2C; the -s option selects bulk write in a single transaction
i2c reset - re-init the I2C Controller
i2c speed [speed] - show or set I2C bus speed

2.1.常用命令

  • i2c dev:查看现在操作的是哪个bus

    • i2c dev 1 //将当前bus切换为bus 1
  • i2c bus:查看系统有几个i2c bus

  • i2c probe: 查看当前busbus上有多少slave,且slaveID是多少.(详见下面的note)

    • i2c probe 0x50 //0x50:从设备地址
  • i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr} :

    • i2c_chip:从设备地址
    • devaddr:从设备片内地址
    • {.0, .1, .2}:从设备片内地址长度[1-2]
    • len: 要读取数据的长度(十六进制)
    • memddr: the address where to store things in memory
  • i2c write {memaddr} {i2c_chip} {devaddr}{.0, .1, .2} {len}

    • i2c write 100000 50 0.1 10 write data from memory to i2c devices.
  • i2c md {i2c_chip} {addr}{.0, .1, .2} {len}: read from I2C device

    • i2c md 50 0.2 0x10
    • 0x50 - address of the slave
    • 0.2 - memory display starts at address 0x000 (indicated by 0), the .2 specifies the length of the address field.
    • 0x10 - shows that the i2c md command will display 16 registers.
  • i2c mw chip address[.0, .1, .2] value [count]:write to I2C device (fill)

    • i2c mw 50 0.2 0a 40
  • i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}:i2c memory modify (auto-incrementing)

    • i2c mm 0x51 0x174.2
  • i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2} :i2c memory modify (constant address)

2.2.Example:

1.测试i2c 读写
=>i2c md 50 0.2 10 //从EEPROM地址0读取数据
0000: 4e 58 49 44 30 78 37 30 00 00 00 00 00 00 00 00 NXID0x70…
=> i2c mw 50 0.2 ff 6 //从EEPROM地址0开始修改6个字节的数据为ff
=> i2c md 50 0.2 6
0000: ff ff ff ff ff ff 37 30 00 00 00 00 00 00 00 00 .XID0x70…

2.Writing to EEPROM, there are two commands available as shown below:
1st method (using i2c mm command):

# i2c mm 0x51 0x174.2
# 00000174: 55 ? 55
# 00000175: 44 ? 44
# 00000176: 33 ? 33
# 00000177: 22 ? 22
# 00000178: 11 ? 11
# 00000179: 02 ? 02

2nd method (using i2c mw command):

# i2c mw 0x51 0x16c.2 55
# i2c mw 0x51 0x16d.2 44
# i2c mw 0x51 0x16e.2 33
# i2c mw 0x51 0x16f.2 22
# i2c mw 0x51 0x170.2 11
# i2c mw 0x51 0x171.2 02
# i2c md 0x51 0x16c.2 6

Note: 0x51 is EEPROM base address. 0x174 is location for EMAC1 address within EEPROM and ‘2’ from 0x174.2 indicating 2 bytes length address format.

你可能感兴趣的:(i2c)