LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Got i2c working ? You can answer this for me. (https://www.linuxquestions.org/questions/linux-hardware-18/got-i2c-working-you-can-answer-this-for-me-199988/)

Mike Davies 07-01-2004 01:16 PM

Got i2c working ? You can answer this for me.
 
I'm trying to get an i2c interface going, and I'm not quite sure where my problems lie. Suffice to say, it doesn't work.

I have built an Philips style adaptor. I'm running with a 2.4.20 kernel. The software modules appear to load OK, and I have this in /proc

# ls -l /proc/bus
-r--r--r-- 1 root root 0 Jun 29 18:18 i2c
-r--r--r-- 1 root root 0 Jun 29 18:18 i2c-0
dr-xr-xr-x 3 root root 0 Jun 29 18:18 isapnp
# cat /proc/bus/i2c
i2c-0 i2c Philips Parallel port adapter Bit-shift algorithm
# cat /proc/bus/i2c-0
cat: read: Invalid argument
#

What I don't understand is this problem with /proc/bus/i2c-0.

Am I right in thinking that this file should contain the addresses of all the devices on the i2c-0 bus ? and I should be able to read the file shouldn't I ?

Ignoring that problem for a moment - if I try to set the slave address with something like

if( ( r = ioctl(fd, I2C_SLAVE, addr)) < 0)
{
fprintf(stderr, "Error eeprom_open: %s\n", strerror(errno));
return -1;
}

then it errors out. This code snippet is from 'eeprog' which is a simple program to access 24Cxx EEPROM devices available at codesink.org/eeprog.html so I guess should work OK. I assume it fails because it can't read the file /proc/bus/i2c-0

So the problem is either with the adaptor I have built (and it's not detecting my chips correctly) or the way the modules have loaded.

If I disconnect my adaptor, then I still get problems typing the contents of /proc/bus/i2c-0 as above.

Can someone with i2c working please confirm that I should be able to type out the contents of /proc/bus/i2c-0 and that it contains addresses of devices on the i2c bus.

If not, what does it contain if anything ?

Mike Davies 07-03-2004 04:12 AM

I'll answer my own question here in case someone else comes across the problem.

Basically, it's a bug in the 2.4 kernel.

The bug is in module i2c-core.c and a patch is available. I found it by using Google and searching for "cat: read: Invalid argument"

I hope this helps someone in the future.
:)

J.W. 07-03-2004 01:30 PM

Mike - congratulations on solving the problem, and thanks also for describing how you solved it. I am certain that your posts will be helpful to future visitors who may encounter the same issue.

Also, Welcome to LQ! -- J.W.


All times are GMT -5. The time now is 04:52 AM.