[i2c] I2C: Getting Compiation Error for application program
Jean Delvare
khali at linux-fr.org
Wed Sep 20 15:12:22 CEST 2006
Hi Sachin,
> I am trying to compile simple program (appended), but getting lots of compilation error.
...which you don't show. Are we supposed to guess?
> I am using Timesys Linux 2.6.13 for ppc440 evaluation board.
Please don't post to 3 mailing lists at once. I've stripped the other
two.
> Command used for compilation:
> $> gcc eeprom-client.c -o eeprom-client.o
>
> Could you help me to find out the reason behind getting the errors?
>
> Regards,
> Sachin Rane
>
>
> 8< ------------------------eeprom-client.c -------------------------------------------------------------------------------------
>
> #include <linux/i2c.h>
This header file doesn't exist in userspace, so you don't want to
include it.
> #include <linux/i2c-dev.h>
Are you certain the compiler picks the right file (from the lm_sensors
package and not from the kernel tree?) You should check the
preprocessor output (gcc -E) to make sure.
>
> int main()
> {
> int file;
> int adapter_nr = 0; /* probably dynamically determined */
> char filename[20];
> int addr = 0xA1; /* The I2C address */
No, the 7-bit I2C address of your EEPROM is 0x50.
>
> sprintf(filename,"/dev/i2c-%d",adapter_nr);
> if ((file = open(filename,O_RDWR)) < 0)
> {
> exit(1);
> }
>
> if (ioctl(file,I2C_SLAVE,addr) < 0)
> {
> exit(1);
> }
> else
> {
> printf("\n Able to bind the adapter");
> }
> return 0;
> }
>
> 8< -------------------------------------------------------------------------------------------------------------
>
As a side note, we already have some tools to work with eeproms. Look
under prog/eepromer in the lm_sensors package. Maybe these are OK for
what you want to do and you don't even need to write your own.
--
Jean Delvare
More information about the i2c
mailing list