here is the code

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "time.h"
#include "string.h"
#include <asm/etraxi2c.h>

// Global variables
int fd_i2c;


int I2C_Open(void) {
  fd_i2c = open("/dev/i2c", O_RDWR);
  if (fd_i2c <= 0) {
        printf("I2C: open error on /dev/i2c\n");
        return(-1);
  }

  return(0);
}



void I2C_Close(void) {
  close(fd_i2c);
}

int main(int argc, char **argv) {
        int retcode;

        retcode = I2C_Open();
        if (retcode != 0) {
                exit(1);
        }


        I2C_LCD i2clcd;
        i2clcd.slave=64;
        i2clcd.x = 1;
        i2clcd.y = 1;
        sprintf(i2clcd.text, "Hello World");
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDINIT), &i2clcd);
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDPRINT), &i2clcd);
        i2clcd.y = 2;
        i2clcd.x = 3;
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDPRINT), &i2clcd);

        I2C_DATA i2cdata;
        i2cdata.length = 2;
        i2cdata.slave = 66;


        while(1){
                ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_READDATA), &i2cdata);
                printf("%d %d\n", i2cdata.data[0], i2cdata.data[1]);
        };


        I2C_Close();

        return(0);
} // end main()


On 27.11.2006 at , you wrote:
> the folder is included in the sdk patch i believe. i will send you the
> app tonight, i am still in the office at the moment and have not got
> the sdk installed here :)
>
> --- In [email protected], "linu13x" <[EMAIL PROTECTED]> wrote:
> >
> > I have no i2c folder in devboard-R2_01/apps. Could I get it from
> > anywhere? Or would it be possible to send me the example?
> >
> > Regards Steff
> >
> > --- In [email protected], john@ wrote:
> > >
> > > look in
> > > devboard-R2_01/apps/i2c/
> > >
> > >
> > >
> > > n 25.11.2006 at , you wrote:
> > > > --- In [email protected], "linu13x" <vw_chaefer@> wrote:
> > > > >
> > > > > Hi to all fox users.
> > > > >
> > > > > It's the first time that I'm working on the foxboard and I've
some
> > > > > questions.
> > > > > I have to use the I2C-bus to communicate with a 12-bit A/D-
> > > > converter.
> > > > > I must use the canonical I2C lines and not the general I/O
lines.
> > > > >
> > > > > Can anybody tell me, which drivers I have to include?
> > > > > Is there allready an existing code for a simple communication
that
> > > > you
> > > > > could send me?
> > > > > Unfortunately, I can not use the example from acmesystems.it
("bit
> > > > > banging") because I must use the canonical I2C lines.
> > > > >
> > > > > Best regards
> > > > >
> > > > > Steff
> > > > >
> > > > Hi
> > > >
> > > > I have exactly the same problem. I need some code snippets of
how to
> > > > use the included i2c driver.
> > > >
> > > > Regards, Klaus
> > > >
> > > >
> > > >
> > >
> >
>
>
>
>



Reply via email to