Hi David,
On Tue, 09 Sep 2008 11:21:45 -0400, David Canales
<[EMAIL PROTECTED]> wrote:
Hello,
I am working in a controller using the motorola coldfire 5282 into the
uCevolution test board from Arcturus. In the last days, I downloaded the
"uClinux-dist-2008-FEB-05-r0-release" distribution from arcturus site.
It's working with the kernel 2.6, and I understand that this
distribution have a better support for i2c communication. I have been
tried to implement the i2c but I don't know how to do this.
I have configure Device Drivers---->
I2C Support-------->
<m> I2C Support-------->
<m> I2C Device Interface
I2C Hardware bus support --->
<m> MCF Coldfire
Then I read from documentation inside the distribution
linux2.6/Documentation/i2c/dev-interface to use this protocol is
necessary only do this:
So let's say you want to access an i2c adapter from a C program. The
first thing to do is "#include <linux/i2c-dev.h>". Please note that
there are two files named "i2c-dev.h" out there, one is distributed
with the Linux kernel and is meant to be included from kernel
driver code, the other one is distributed with lm_sensors and is
meant to be included from user-space programs. You obviously want
the second one here.
Now, you have to decide which adapter you want to access. You should
inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned
somewhat dynamically, so you can not even assume /dev/i2c-0 is the
first adapter.
Next thing, open the device file, as follows:
int file;
int adapter_nr = 2; /* probably dynamically determined */
char filename[20];
sprintf(filename,"/dev/i2c-%d",adapter_nr);
if ((file = open(filename,O_RDWR)) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
When you have opened the device, you must specify with what device
address you want to communicate:
int addr = 0x40; /* The I2C address */
if (ioctl(file,I2C_SLAVE,addr) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
but this does not work, I need more documentation and if is possible a
example that can help me to make my work possible.
I do not know what you have changed in your code in the example above,
you need to change
adapter_nr
and addr
according to your i2c device.
for my test, I use adapter_nr=0 and addr=0x12;
here is the code:(tried on 53281-EVM module)
------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c.h>
#include <errno.h>
#include <string.h>
int main (int argc, char ** argv){
int file;
int adapter_nr = 0; /* probably dynamically determined */
char filename[20];
sprintf(filename,"/dev/i2c-%d",adapter_nr);
if ((file = open(filename,O_RDWR)) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
printf("error: %s\n", strerror(errno));
exit(1);
}
int addr = 0x12; /* The I2C address */
if (ioctl(file,I2C_SLAVE,addr) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
printf("OK\n");
}
I have seen that can be load a module for i2c in the mcf called
i2c-mcf.c i load the module using insmod i2c-mcf.ko, but my question is
how i can use the function in that the module have, or how i can use
the driver I am confuse.
you may need to install all modules you enabled above
i2c-core.ko i2c-dev.ko and i2c-mcf.ko
also you need the device node:
add following line in the vendors/Arcturus/uC5282-xE16C64/Makefile
after "DEVICES = \"
DEVICES += i2c-0,c,89,0
or you can create it at runtime:
# mknod /tmp/i2c-0 c 89 0
and change the test program using
sprintf(filename,"/tmp/i2c-%d",adapter_nr);
PLEASE HELP ME BECAUSE I AM HAVE STUCK IN THE DEVELOPMENT OF A VERY
IMPORTANT PROJECT.
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev
--
David Wu
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev