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