Need help with i2c implementation

Hi all,
          I have a beagleboard-xM Rev.C on to which DVDSK-4.01 with
angstrom linux is ported. Im new to linux environment and trying to
write a simple code to read a register from a device which will be
connected to beagleboard processor(i,e.,DM3730) via i2c. After some
searching on the web i was able to write it to certain extent which is
pasted below.

#include <stdio.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <linux/glib.h>
#include <linux/gprintf.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define REG_IDENT 0x11

main(void)
{

int file, val,i;
char *filename = "/dev/i2c-2";
int addr= 0x42;

sprintf(filename,"/dev/i2c-2");
if ((file = open(filename, O_RDWR)) < 0) {
    /* ERROR HANDLING: you can check errno to see what went wrong */
    perror("Failed to open the i2c bus");
    exit(1);
}

if (ioctl(file, I2C_SLAVE, addr) < 0) {
    printf("Failed to acquire bus access and/or talk to slave.\n");
    /* ERROR HANDLING; you can check errno to see what went wrong */
    exit(1);
}

while(1)
{
     val = i2c_smbus_read_byte_data(file, REG_IDENT);
     printf("device_id = %d\n",val);
     for(i=0;i<10000;i++);
}

}

now i get the following errors.

edcn400@edcn400-desktop:~/Desktop/i2c$ make
/home/edcn400/CodeSourcery/Sourcery_G++_Lite//bin/arm-none-linux-
gnueabi-gcc -o adv_i2c adv_i2c.c
adv_i2c.c:4:24: error: linux/glib.h: No such file or directory
adv_i2c.c:5:27: error: linux/gprintf.h: No such file or directory
make: *** [helloworld] Error 1
edcn400@edcn400-desktop:~/Desktop/i2c$

how do i solve this problem.

If my approach to the i2c implementation is wrong, please do correct
me.

Thanking you,
Shravan Kulkarni

Makefile that is written for the compilation is pasted below.

include $ /home/edcn400/ti-dvsdk_dm3730-evm_4_01_00_09/Rules.make
helloworld:
$(CSTOOL_PREFIX)gcc -o adv_i2c adv_i2c.c

regards,
Shravan Kulkarni

Is there supposed to be 2 of “//” in the gcc line?

Hi Mark,
Thank you for your reply. i followed the steps given for helloworld program’s Makefile in the omap3530 software developers guide. it compiled for the helloworld program and it worked on the beagleboard.

i have pasted the link for omap3530 software developers guide documents. it is in page 3 and 4
http://www.uweb.ucsb.edu/~karenportillo/files/OMAP3530_Software_Developers_Guide.pdf

there is no // in the gcc line. if i have to include where should i have to do it.

thanking you,
shravan kulkarni

Hi Mark,
I apologies for my stupid response. i corrected the ‘//’ in the gcc line. it was there in Rules.make file. But im still getting the same error. i have pasted the error below.

edcn400@edcn400-desktop:~/Desktop/i2c$ make
/home/edcn400/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc -o adv_i2c adv_i2c.c
adv_i2c.c:4:24: error: linux/glib.h: No such file or directory
adv_i2c.c:5:27: error: linux/gprintf.h: No such file or directory
make: *** [adv_i2c] Error 1
edcn400@edcn400-desktop:~/Desktop/i2c$

regards,
Shravan Kulkarni

Try the instructions here [1]. This is what I use in teaching Beagle i2c to my class. Everything runs and compiles on the Beagle. It’s a good starting point.

Let me know if it works.

–Mark (another Mark)

[1] http://elinux.org/EBC_Exercise_05_I2C