i2c reading using command line and using coding

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
learner
Posts: 5
Joined: Thu 23 May 2013, 10:11

i2c reading using command line and using coding

#1 Post by learner »

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

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#2 Post by Ibidem »

I think you misunderstand it. I ran it and it said
"Error: could not open file '/dev/itc-1' or '/dev/itc/1': No such file or directory"

(I haven't enabled I2C devices in my kernel yet.)
So clearly the message you get is not saying "device not present"...
Let's see what the man page says...
Ah, a device in /dev is a bus not a chip. If it can open the bus, i2cdetect lists the chips on that bus.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

bash-3.00# ./tools/i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- 08 -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 -- 32 -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: 50 -- 52 -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

bash-3.00# ./tools/i2cdetect 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

BUT after

Code: Select all

modprobe -l |grep i2c | while read f ; do modprobe -v `basename $f .ko.gz` ; done
Ibidem : maybe you have old linux/*.h ?

Source Package: i2c-tools (3.1.0-2) from packages.debian.org
without the debian patch .
Puppy 4.3 .

learner
Posts: 5
Joined: Thu 23 May 2013, 10:11

#4 Post by learner »

Hi,
I clearly mentioned that i am able to open i2c device file and again able to get control using ioctl. how am i able to get control of i2c? why is not showing any error for devices, which are not connected i2c bus?

Post Reply