Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2013
    Posts
    29

    Default I2C read and write to 24C01 eeprom

    I and difficulty reading and write to the eeprom,the reading instruction I used is

    I2Cread SDA,SCL,$A0,$00,[data1.......data7]
    I2Cwrite SDA,SCL,$A0,$00,[data1......data7]

    all data are define as word variable

    I'm not sure it have written into the memory correctly or not,but the value of data1 can read into data3 and data2 value can read in data5

    I have check with a oscilloscope using I2C analysis,trigger on missing acknowledge signal all data return no acknowledgement
    have I did something wrong?
    Last edited by Sabahan; - 20th November 2017 at 16:59.

  2. #2
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    59

    Default Re: I2C read and write to 24C01 eeprom

    From the manual, p. 158:

    The Address size sent (byte or word) is determined by the size of the variable that is used. If a byte-sized variable is used for the Address, an 8-bit address is sent. If a word-sized variable is used, a 16-bit address is sent. Be sure to use the proper sized variable for the device you wish to communicate with. Constants should not be used for the Address as the size can vary dependent on the size of the constant. Also, expressions should not be used as they can cause an improper Address size to be sent.

  3. #3
    Join Date
    Oct 2009
    Posts
    539

    Default Re: I2C read and write to 24C01 eeprom

    If using bytes then the format would be something like
    Code:
    I2CWRITE SDApin,SCLpin,$A0,$00,[data1,data2,... etc etc]

    If using word variables the format would be something like this
    Code:
    I2CWRITE SDApin,SCLpin,$A0,$00,[data1.lowbyte,data1.highbyte, data2.lowbyte,data2.highbyte, etc etc]
    IC2READ would have the corresponding values in its statement

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,218

    Default Re: I2C read and write to 24C01 eeprom

    you don't say what chip/osc you are using , consider this

    The timing of the I2c

    instructions is set so that standard speed devices(100kHz) will
    be accessible at clock speeds up to 8MHz. Fast mode devices (400kHz) may be
    used up to 20MHz. If it is desired to access a standard speed device at above
    8MHz, the following DEFINE should be added to the program:
    DEFINE I2C_SLOW 1
    also read the data sheet for your eprom re
    1. address command size
    2 page size
    writes that exceed a page in size or cross a page boundary can go wrong

    read the manual and watch out for common myths
    Attached Images Attached Images  
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Oct 2009
    Posts
    539

    Default Re: I2C read and write to 24C01 eeprom

    Richard, I was using the OP's example hence the address, and trying to explain that as a word variable he needed to write the high and low bytes. It was not meant as an optimised example...

    I used the following to send word variable values to a PCA chip.. it might not be tight code, it may not be "as it should" in the eyes of more experienced programmers, or it may not follow convention in the manual... But it works

    Code:
        pcaChannel = 1  
        i2cControl = $6 + 4*pcaChannel                              
        I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,CH2_PWM.lowbyte,CH2_PWM.highbyte]

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    1,218

    Default Re: I2C read and write to 24C01 eeprom

    Quote Originally Posted by Scampy View Post
    I used the following to send word variable values to a PCA chip..
    making a special case where endianness needs to be managed.

    the pca chip requires the data sent low byte first, i2cread/write natively send high byte first.


    to do that for a eprom is just a typing exercise
    This is more entertaining than Free to Air TV

  7. #7
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    156

    Default Re: I2C read and write to 24C01 eeprom

    Hi Richard,

    I did a project a while ago which stored word values to a 24LC02 EEPROM.
    The only way I could get it to work was to use the lowbyte and highbyte method that Scampy mentioned.

    Can you show me a snippet of your code that will successfully write a word value to EEPROM?

    Cheers
    Barry
    VK2XBP

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    1,218

    Default Re: I2C read and write to 24C01 eeprom

    no problem barry, this scans i2c bus reports valid addresses
    and then reads and writes a mixed lot of word/byte vars

    ps used a 24c08
    Attached Files Attached Files
    This is more entertaining than Free to Air TV

Similar Threads

  1. I2C eeprom read write
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th July 2010, 17:49
  2. How to Read / Write I2c 24LC16B EEprom
    By odie52 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th May 2010, 03:00
  3. read/write eeprom
    By mel4853 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 1st March 2010, 02:17
  4. I2C Read and Write
    By DerekMacom in forum mel PIC BASIC
    Replies: 14
    Last Post: - 21st April 2008, 15:44
  5. Write and Read from eeprom
    By savnik in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 9th June 2007, 14:56

Members who have read this thread : 16

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts