I2CWRITE problem


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985

    Default I2CWRITE problem

    Hi Guys,
    I seem to be able to READ ok with I2CREAD,
    but I'm having difficulty with my program, and I've narrowed it down to I2CWRITE.

    I'm using a 24LC512 EEPROM, and I've also tried 256.

    Code:
    W0 var byte
    epin var word
    
    W0 = 0
    FOR cntr = 0 TO 2000					'
    I2CWRITE porte.1,porte.2,%10100000,epin,[W0,W0,W0,W0,W0],error	'
    pause 10						'
    epin = epin + 5						'
    NEXT cntr						'
    It would seem this code should write a lot of zeros, but when I read back the chip
    there are some missing.
    I have erased the EEPROM with my programmer which sets all $FF values,
    and then run this code, then I find when I read back the EEPROM with my
    pic programmer (or with picbasic code) there are some zero bytes.

    They appear to be in groups of 2 or 3 bytes at addresses like:
    100h, 180h, 200h, 280h, 300h, 380h, and so on.

    Any ideas on this? Anyone else seen the same problem?

    I'm using a 16F877A and Port e 1&2 to do the I2C stuff.
    Art.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Oh, I should add that I can entirely write and verify both EEPROMs properly with my pic programmer.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Art, Do you have any interrupts going on in the program? I have seen in the past that if you are interrupted during a I2CWRITE to some eeproms you will write bad data to the locations...

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Just a couple of things to check/try...

    Check:
    ADC turned off for E.1 and E.2

    Try:
    DEFINE I2C_SLOW
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    ADC turned off for E.1 and E.2

    Try:
    DEFINE I2C_SLOW
    Yep, I have all digital pins. The EEPROM works most of the time,
    it just doesn't want to write some addresses.
    DEFINE I2C_SLOW 1 made no difference.

    No interrupts in this program either.

    4.7K pullups, checked 5 Volt supply.

  6. #6
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    Hi Art & All,

    Thanks to Art, I noticed similar I2CWRITE problem with different PIC and EEPROM (I use 18F4520 and 24C64).
    So far I haven't use external EEPROM for storing anything, just used I2CREAD and that has worked very well.

    Below is my test code for WRITE/READ for EEPROM. Test will be passed if X=0 (LED blinking slowly), if X > 0 then it fails immediately (LED blinking fast).

    Code:
    <code><font color="#000000">OSCCON = $70                <font color="#000080"><i>'Int CLK 8MHz
    </i></font>OSCTUNE.6 = 1               <font color="#000080"><i>'PLL 4x
    </i></font>ADCON1= %00001111           <font color="#000080"><i>'$0F = disable A/D converter
    </i></font>TRISD.0 = 0
    TRISD.1 = 1
    TRISD.3 = 0
    TRISE.4 = 0
    
    <b>DEFINE </b>OSC 32
    
    X       <b>VAR BYTE
    </b>Y       <b>VAR BYTE
    </b>SCL     <b>VAR </b>PortD.0 
    SDA     <b>VAR </b>PortD.1   
    LED     <b>VAR </b>PortD.3
    
    I2CDeviceEEprom     <b>VAR BYTE   
    </b>I2CAddressEEprom    <b>VAR WORD 
    </b>I2CDeviceEEprom=$A0
    
    X=0    <font color="#000080"><i>'OK if EEPROM content is 00h and X = 0, if X &gt; 0 then fails
    
    </i></font><b>FOR </b>I2CAddressEEprom = 0 <b>TO </b>8191
        <b>I2CWRITE </b>SDA, SCL, I2CDeviceEEprom, I2CAddressEEprom,[ X ], Error			
        <b>PAUSE </b>10
        <b>I2CREAD </b>SDA, SCL, I2CDeviceEEprom, I2CAddressEEprom,[ Y ], Error
        <b>IF </b>Y &lt;&gt; X <b>THEN GOTO </b>Error
    <b>NEXT </b>I2CAddressEEprom
    
    Blink:
    <b>HIGH </b>LED
    <b>PAUSE </b>1000
    <b>LOW </b>LED
    <b>PAUSE </b>1000
    <b>GOTO </b>Blink
    
    Error:
    <b>HIGH </b>LED
    <b>PAUSE </b>200
    <b>LOW </b>LED
    <b>PAUSE </b>200
    <b>GOTO </b>error
    
    <b>END</b>	
    </code>
    No help from DEFINE I2C_SLOW or any other that I have tried so far (increasing PAUSE time between write and read, etc...).
    Hardware is OK, because I have used it for other purpose and then PIC read only from EEPROM (same PIC and EEPROM). Pull-ups are 4.7k and very solid 5V (no dips). Data lines are quite short (~25mm). EEPROM is only device in I2C-bus. WP pin is grounded....
    Sounds very similar problems as Art has.

    BR,
    -Gusse-
    Last edited by Gusse; - 25th January 2010 at 16:37.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Gusse,
    Your code does not loop, I am sitting here wondering if there is some latency in your hardware, causing your code to run ahead of the eeprom, so the code is finished before the eeprom has finished waking up . . . Maybe in Art's too . . BTW ART, I liked your talking clock, esp when it encounters an error
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. My I2CWRITE - timings and tricks
    By FinchPJ in forum Code Examples
    Replies: 5
    Last Post: - 3rd March 2008, 21:40
  2. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2006, 20:03
  3. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th June 2006, 18:32
  4. Another I2CWRITE problem
    By ErnieM in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th May 2006, 21:57
  5. I2CRead / I2CWrite Problem?
    By koossa in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st October 2005, 18:26

Members who have read this thread : 0

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