If you want to print or log the meaning of an error number, use strerror(errno). Makes debugging easier.
Regards, Hubert On Nov 15, 4:30 pm, shootingatshadow <[email protected]> wrote: > Ahh resource busy, I guess ill need to find a way to free it up..... > > On Nov 15, 10:29 am, shootingatshadow <[email protected]> > wrote: > > > Ahh permissions error, I added some code that chmod the file to give > > me permissions...not their is no error on open. > > > However, I get errno 16 on ioctl code: > > > if (ioctl(file, I2C_SLAVE, addr) < 0) { > > return errno; > > > } > > > The file is good, as errno is 0 after file = open("/dev/i2c-0", > > O_RDWR); > > > The address might be bad, but the chip speck and cating devices show > > it at 0x48. > > > On Nov 15, 9:43 am, shootingatshadow <[email protected]> > > wrote: > > > > I get errno 13 when I try and open the /dev/i2c-0 special character > > > file that gets created on insmod i2c-0.ko. > > > > errno=0; > > > file = open("/dev/i2c-0", O_RDWR); > > > if(file < 0) { > > > return errno; > > > > } > > > > The above code returns with errno as 13. > > > > Any ideas as to why? > > > > Thanks! > > > > On Nov 11, 9:38 am, Pubudu <[email protected]> wrote: > > > > > I think what you are referring as error code being -1 is the return > > > > code of ioctl being -1. > > > > check the value of 'errno' at that point against the error.h > > > > > regards.. > > > > > On Nov 11, 3:01 am, shootingatshadow <[email protected]> > > > > wrote: > > > > > > Ok so, I grabbed the kernel source, built and installed kernel with > > > > > loadable module support and had it built the i2c modules. I then > > > > > insmod the i2c-dev.ko and it worked fine. It created a character > > > > > special file 89 0 under /dev/i2c-0. > > > > > > I can open the file just fine with file = open("/dev/i2c-0", O_RDWR), > > > > > however the ioctl(file, I2C_SLAVE, address) fails with error code -1. > > > > > I looked at (i think) error.h and all errors were positive. I have not > > > > > been able to find a list of ioctl error codes, nor do I know what I am > > > > > doing wrong here. > > > > > > Also, a big thanks to everyone here, you pointed me in the right > > > > > direction and helped me out! > > > > > > On Oct 30, 7:18 am, Deva R <[email protected]> wrote: > > > > > > > now, what exactly is the blocking issue? > > > > > > > On Wed, Oct 27, 2010 at 10:30 PM, shootingatshadow < > > > > > > > [email protected]> wrote: > > > > > > > Thanks for your help, I spent the last few weeks doing more > > > > > > > research > > > > > > > and am still stuck. > > > > > > > > 1.) I went to The Linux Documentation Project, and was unable to > > > > > > > find > > > > > > > anything on I2C development, any suggestions on where to go would > > > > > > > be > > > > > > > appreciated. > > > > > > > its right in ./Documentation/i2c folder.. did u miss more than > > > > > > that?http://lxr.linux.no/linux+v2.6.36/Documentation/i2c/dev-interface > > > > > > > > 2.) My second question, is that the i2c-dev.h header, which from > > > > > > > my > > > > > > > understanding is required for user space i2c access, is > > > > > > > distributed in > > > > > > > the lm-sensors project for Debian based systems. Is their an > > > > > > > alternative for an Arm based Android system? > > > > > > > <linux/*.h> are generic headers which are platform agnostic.. > > > > > > if at all a header is architecture specific (say cpu.h, cache.h) - > > > > > > goes into > > > > > > arch/x86/include/asm/, arch/arm/include/asm/ > > > > > > > only platform specific driver implementation goes under > > > > > > ./arch/arm/<>/<i2c> > > > > > > > > Thanks again! > > > > > > > > On Oct 13, 2:15 am, kavitha bk <[email protected]> wrote: > > > > > > > > Hi, > > > > > > > > U can go through Linux Documentation for i2c > > > > > > > > Plain I2C communication > > > > > > > > ----------------------- > > > > > > > > int i2c_master_send(struct i2c_client *client, const > > > > > > > > char *buf, > > > > > > > > int count); > > > > > > > > int i2c_master_recv(struct i2c_client *client, char > > > > > > > > *buf, int > > > > > > > > count); > > > > > > > > These routines read and write some bytes from/to a client. The > > > > > > > > client > > > > > > > > contains the i2c address, so you do not have to include it. The > > > > > > > > second > > > > > > > > parameter contains the bytes to read/write, the third the > > > > > > > > number of bytes > > > > > > > > to read/write (must be less than the length of the buffer.) > > > > > > > > Returned is > > > > > > > > the actual number of bytes read/written. > > > > > > > > int i2c_transfer(struct i2c_adapter *adap, struct > > > > > > > > i2c_msg *msg, > > > > > > > > int num); > > > > > > > > This is if u r doing from kernel. > > > > > > > > > If u want to communicate to a i2c device from user space > > > > > > > > > I2C device files are character device files with major device > > > > > > > > number > > > > > > > > 89 and a minor device number corresponding to the number > > > > > > > > assigned as > > > > > > > > explained above. They should be called "i2c-%d" (i2c-0, i2c-1, > > > > > > > > ..., > > > > > > > > > i2c-10, ...). All 256 minor device numbers are reserved for i2c. > > > > > > > > > Usually, i2c devices are controlled by a kernel driver. But it > > > > > > > > is also > > > > > > > > possible to access all devices on an adapter from userspace, > > > > > > > > through > > > > > > > > the /dev interface. You need to load module i2c-dev for this. > > > > > > > > > Each registered i2c adapter gets a number, counting from 0. You > > > > > > > > can > > > > > > > > examine /sys/class/i2c-dev/ to see what number corresponds to > > > > > > > > which > > > > > > > > adapter. > > > > > > > > > int file = open(/dev/i2c-0, O_RDWR); > > > > > > > > > When you have opened the device, you must specify with what > > > > > > > > device > > > > > > > > address you want to communicate: > > > > > > > > > int addr = 0x40; /* The I2C address */ > > > > > > > > > ioctl(file, I2C_SLAVE, addr) > > > > > > > > > Then u can communicate with the device > > > > > > > > > Regards, > > > > > > > > > Kavitha > > > > > > > > > On Tue, Oct 12, 2010 at 5:42 PM, shootingatshadow < > > > > > > > [email protected] > > > > > > > > > > wrote: > > > > > > > > > I am a bit new to Linux device drivers, been doing some > > > > > > > > > research and > > > > > > > > > trying things out. (Read Linux Device Drivers Book, digging > > > > > > > > > around > > > > > > > > > forums) > > > > > > > > > > So I have found at i2c address 0x38 a chip which I would like > > > > > > > > > to talk > > > > > > > > > to. There is already a driver in place for that chip. I have > > > > > > > > > the spec > > > > > > > > > sheet in hand for that chip as well. However, the device > > > > > > > > > shows up > > > > > > > > > under /proc/bus and in the devices file. How can I access > > > > > > > > > this device > > > > > > > > > and send it information? My only other experience is opening > > > > > > > > > a file > > > > > > > > > under /dev/DEVICE and read and write bytes to it, any > > > > > > > > > suggestions > > > > > > > > > would be greatly appreciated. > > > > > > > > > > -- > > > > > > > > > unsubscribe: > > > > > > > > > [email protected]<android-porting%2Bunsubscribe@ > > > > > > > > > googlegroups.com> > > > > > > > <android-porting%[email protected]<android-porting%252Bunsubsc > > > > > > > [email protected]> > > > > > > > > > > website:http://groups.google.com/group/android-porting > > > > > > > > -- > > > > > > > unsubscribe: > > > > > > > [email protected]<android-porting%2Bunsubscribe@ > > > > > > > googlegroups.com> > > > > > > > website:http://groups.google.com/group/android-porting > > > > > > > -- > > > > > > Regards, > > > > > > Devawww.bittoggler.com -- unsubscribe: [email protected] website: http://groups.google.com/group/android-porting
