Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, When i type i2cdetect -y 1 it shows devices attached with processor. 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    1

    i2c reading using command line and using coding


    Hi,
    When i type i2cdetect -y 1
    it shows devices attached with processor.

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --


    it means -- i2c device does not exist.

    but when i try to open using
    open("/dev/i2c-1","O_RDWR);

    it is showing device is opened.
    after that when calling ioctl, it is again showing successfully open device.
    Can any one tell me, how to ensure if device is not attached and try to get status by opening that device, it should give error.

    second more thing, if device is not existing, then why able to read using read function called for opened file description for such devices as shown -- in i2cdetect command.

    Can anyone help me, what is it?

    --------
    Learner

  2. #2
    Just Joined!
    Join Date
    Jul 2006
    Location
    localhost
    Posts
    31
    Please note that some I2C devices may never reply back even when operating properly. One example of this would be graphical displays for which it only makes sense to reply when requesting the contents of a buffer. Also note that while the I2C spec does provide an acknowledgement mechanism not every device will use it. To my knowledge, the I2C spec doesn't define any standard command to detect a busy address either.

    This makes it impossible to detect all devices with 100% accuracy. In order to talk to these devices the kernel must allow you to send commands to any address regardless of whether it receives data back or not. It must also allow you to listen for data even though it's not expecting any (after sending an initial read command of course since the master device controls the clock, pure slave devices are incapable of initiating a data transfer).

    If you want to detect if your device is connected or not you must thus use device specific commands which generates a reply, something like a status message or reading the first block. These would be available to you in the device datasheet and may collide with other devices if they are configured to use the same address, so consider what else could be connected in order to avoid unexpected behavior.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •