LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   how to read/write a 16-bit address e2prom? (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/how-to-read-write-a-16-bit-address-e2prom-824197/)

giampaquestions 08-04-2010 03:45 PM

how to read/write a 16-bit address e2prom?
 
I need a clue on how to use the interface "at24.c" to write and read the 16-bit EEPROMs, like the 24c256, in user mode. I cross-compiled the kernel (2.6.32) with the "at24" option enabled and now I am able to write and read the i2c EEPROM memory during kernel startup, but I have no idea how to use this interface in user mode, in particular I would like to know how to access a particular EEPROM memory location with 16-bit address.

theNbomr 08-07-2010 07:01 PM

Did the driver create a device file: /dev/XXXX?, where XXXX is some name that reflects the name or type of device (i2c) that it accesses. If so, I think you would use the usual open()/read()/write()/seek()/close/ioctl() semantics to access it. THere may be significant functionality buried in the ioctl() interface. I don't know anything specific about the device to which you refer, but Documentation / i2c / dev-interface may be enlightening.

--- rod.

giampaquestions 08-15-2010 02:00 PM

With your indications I have compiled this simple program and seems to work.
Code:

#include <stdio.h>
#include <stdlib.h>

  void main(int argc, char **argv)
  {
  FILE *f;

    f = fopen("/sys/bus/i2c/devices/3-0050/eeprom", "r+");
    fseek(f, 100, SEEK_SET);
    fprintf(f, "MySimpleTest");
    fclose(f);
  }

Thanks!


All times are GMT -5. The time now is 07:59 AM.