linux下用i2c-tools读写i2c器件的问题

今天猎鹰兄用ioctrl读写i2c器件有问题,我用i2c-tools试了下,可以用I2C_SMBUS和I2C_RDWR读i2c器件,

所以估计是应用程序写的有问题,有现成的应用可以用,要先拿这些应用去测试驱动.

i2cget 使用的是I2C_SMBUS指令,用法如下:

root@ZYF_LINUX:~# i2cget
Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77)
  MODE is one of:
    b (read byte data, default)
    w (read word data)
    c (write byte/read byte)
    Append p for SMBus PEC

 

读写的log如下:(从/dev/i2c-2上读取地址为0x5c的器件,读2字节)

root@ZYF_LINUX:~# i2cget -y 2 0x5c 0 w
0x3110

 

eeprog 使用的是I2C_RDWR指令,用法如下:

root@ZYF_LINUX:~# eeprog
eeprog 0.7.6, a 24Cxx EEPROM reader/writer
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
Usage: eeprog [-fqxdh] [-16|-8] [ -r addr[:count] | -w addr ]  /dev/i2c-
ddress

  Address modes:
        -8              Use 8bit address mode for 24c0x...24C16 [default
        -16             Use 16bit address mode for 24c32...24C256
  Actions:
        -r addr[:count] Read [count] (1 if omitted) bytes from [addr]
                        and print them to the standard output
        -w addr         Write input (stdin) at address [addr] of the EEP
        -h              Print this help
  Options:
        -x              Set hex output mode
        -d              Dummy mode, display what *would* have been done
        -f              Disable warnings and don't ask confirmation
        -q              Quiet mode

The following environment variables could be set instead of the command
line arguments:
        EEPROG_DEV              device name(/dev/i2c-N)
        EEPROG_I2C_ADDR         i2c-address

        Examples
        1- read 64 bytes from the EEPROM at address 0x54 on bus 0 starti
           at address 123 (decimal)
                eeprog /dev/i2c-0 0x54 -r 123:64
        2- prints the hex codes of the first 32 bytes read from bus 1
           at address 0x22
                eeprog /dev/i2c-1 0x51 -x -r 0x22:0x20
        3- write the current timestamp at address 0x200 of the EEPROM on
           bus 0 at address 0x33
                date | eeprog /dev/i2c-0 0x33 -w 0x200

[line 204]

 

log如下:

root@ZYF_LINUX:~# eeprog /dev/i2c-2 0x5c -x -r 0:2
eeprog 0.7.6, a 24Cxx EEPROM reader/writer
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
  Bus: /dev/i2c-2, Address: 0x5c, Mode: 8bit

____________________________WARNING____________________________
Erroneously writing to a system EEPROM (like DIMM SPD modules)
can break your system.  It will NOT boot anymore so you'll not
be able to fix it.

Reading from 8bit EEPROMs (like that in your DIMM) without using
the -8 switch can also UNEXPECTEDLY write to them, so be sure to
use the -8 command param when required.

Use -f to disable this warning message

Press ENTER to continue or hit CTRL-C to exit


  Reading 2 bytes from 0x0

 0000|  10 31

[最后修改于2011-08-17 22:50]
Logo

更多推荐