This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Continuous data write in serial eeprom using I2C

I am trying to write the routine to store the char, int, float datas in the serial eeprom 24FC512 and read back the written values using random read method.

My problem is sometimes only the data is written properly and read back corretly.

I dont know what is the reason behind the wrong writing and reading.

But my I2C_Read, I2C_Write, I2C_Start,I2C_Stop works well with my RTC DS1307.

Idont know why the problem is coming with EEPROM?

Can anybody give me a suggestion?

Parents Reply Children
  • Don't bother with separate functions for byte, int, long, etc.

    As far as the memory is concerned, it's all just a matter of reading and writing bytes - the memory neither knows nor cares whether a particular byte actually represents a 'char', or half an 'int', or whatever!

    Just write yourself two generic functions which take arguments telling them where to start, and how many bytes to transfer.
    Your prototypes would look something like:

    // Write data to EEPROM:
    //   source_address  - start address of the data to be written;
    //   ee_destination  - starting location in the EEPROM for writing
    //   number_of_bytes - number of bytes to be written
    //   Return value:     code indicating success/fail?
    char write_ee( void * source_address, unsigned int ee_destination, unsigned char number_of_bytes );
    
    // Read data from EEPROM:
    //   destination_address  - start address for the data read from the EEPROM;
    //   ee_source            -  starting location in the EEPROM for reading;
    //   number_of_bytes      - number of bytes to be read
    //   Return value: code indicating success/fail?
    char read_ee( void * destination_address, unsigned int ee_source, unsigned char number_of_bytes );
    


    You may want to adjust the data types to suit your specific requirements. Note that void* means "a pointer to anything"; use the sizeof operator to find the numbre of bytes for a particular data type - see your 'C' textbook for further details.

  • Thank you very much.

    I did it.