From: paul k. <pau...@xs...> - 2005-02-15 08:34:18
|
I contacted the person (sorry the e-mail is currently unavailable so I am not sure about his name) responsible for the port of the pcf8574 module to kernel 2.6. He was so kind to answer my questions. first this code: char buf[1]; buf[0] = 4; file = open("\sys\bus\i2c\devices\0-0020\write",O_WRONLY); write(file,buf,1); Is correct, except that this file only accepts asci strings. So it should be something like this; char buf[1]; buf[0] = '4'; file = open("\sys\bus\i2c\devices\0-0020\write",O_WRONLY); write(file,buf,1); To send a byte to the I2C bus. Now to the way on how to do it. (Luis are you still reading, here comes your I2C API :-) ) file = open("/dev/i2c-0",O_RDWR); // open i2c bus ioctl(file,I2C_SLAVE,0x26); // select device struct i2c_smbus_ioctl_data args; args.read_write = I2C_SMBUS_WRITE; args.size = I2C_SMBUS_BYTE; args.command = 0x03; // <- this is the byte to write!! ioctl(file,I2C_SMBUS,&args); // write byte to selected device There is hardly any documentation on this and it required some digging in kernel source code to find that 'command' should contain the byte write. But it does work, to write a byte to the port. Now for the sad news. The display doesn't start yet. Of course this can have several reasons, that I still have to look into. It might even require bringing an oscilloscope home from work. Luis, thanks for your feedback! Paul Luis.F.Correia wrote: >Hi! > > > >>-----Original Message----- >>From: paul kamphuis [mailto:pau...@xs...] >>Sent: Monday, February 14, 2005 7:51 AM >>To: lcd...@li... >>Subject: [Lcd4linux-devel] connecting i2c lcd >> >>Hi, >> >>First things first, my quick test last friday didn't work! Besides it >>would have been to easy if it worked just like this. >> >>To investigate it a little further, I also did a test with a pcf8574 >>driving some led's. (Sometimes you are just lucky to have >>something like >>that available). I used the following piece of C code to test it. >> >>char buf[1]; >>buf[0] = 4; >>file = open("\sys\bus\i2c\devices\0-0020\write",O_WRONLY); >>write(file,buf,1) >> >>At power up the leds outputs are clearly in an undefined >>state (some on, >>some off) After running the above code all led's go off. So there is >>activity, but not the desired. (note the strange code of 4 to >>turn on a >>led. There are 19 led's connected so it is encoded.) >> >>There is a different way to access a device, and it goes like this >>through the command line: >> >>$ echo 4 > \sys\bus\i2c\devices\0-0020\write >>This correctly turns on the desired led. >> >> > >For all that I know, this is the best way to drive something connected to a >/sys/bus interface. > >All other methods should be used programatically. > > > >>Is there anyone who has an idea of the difference between the >>C code and >>the command line? >> >> > >Try to write some C code using the I2C api. > > > >>Paul >> >> >> > >Luis > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click >_______________________________________________ >Lcd4linux-devel mailing list >Lcd...@li... >https://lists.sourceforge.net/lists/listinfo/lcd4linux-devel > > > > |