I2CWRITE problem


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Location
    morocco
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    hi art im newbe but if im right i noticed an error in your code .sorry if its not.
    Code:
    W0 var byte
    epin var word   <<<<<  i think this is address ?
    
    W0 = 0
    FOR cntr = 0 TO 2000  	'should be( FOR epin= 0  TO 2000 )!	or (cntr)should be var  xxx
    epin = epin + 5		'
    I2CWRITE porte.1,porte.2,%10100000,epin,[W0,W0,W0,W0,W0],error	
    pause 10						'
    						'
    NEXT cntr
    hope this helps
    see Gusse code moght it helps
    Last edited by MR2010; - 26th January 2010 at 06:08.

  2. #2
    Join Date
    Jan 2010
    Location
    morocco
    Posts
    16


    Did you find this post helpful? Yes | No

    Question

    hi gusse guess SDA PORTD.1 is always input what will happens ? u did set SDA port input only read .u have to leave trisd alone and set portd = 0 , i can say trisd s gone to charge you lol

    Code:
    TRISD.0 = 0
    TRISD.1 = 1 '<<<should be TRISD.1 = 0  or  only PORTD = %0000  
    TRISD.3 = 0
    TRISE.4 = 0
    
    SCL     VAR PortD.0 
    SDA     VAR PortD.1   
    LED     VAR PortD.3
    
    
    END
    im newbe hope this helps
    hope u get better gusse
    regards
    Last edited by MR2010; - 26th January 2010 at 07:01.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by MR2010 View Post
    hi gusse guess SDA PORTD.1 is always input what will happens ? u did set SDA port input only read .u have to leave trisd alone and set portd = 0 , i can say trisd s gone to charge you lol

    im newbe hope this helps
    hope u get better gusse
    regards
    To my understanding I2CWRITE and I2CREAD -functions take care of port settings. So basically, whatever user is pre-defining in SW, I2C-routine will over-write it.
    - I2C clock is always coming from master (PIC) and it is output.
    - I2C data is bi-directional, so port will change between input and output.

    Please, somebody wiser correct if I'm totally wrong.

    Code:
    I2CAddressEEprom = 0 TO 1024
    Value should be 1023. 0 + 1023 = 1024.

    BR,
    -Gusse-

    PS. Getting better, little by little ...
    Last edited by Gusse; - 26th January 2010 at 08:37.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by MR2010 View Post
    hi art im newbe but if im right i noticed an error in your code .sorry if its not.
    Code:
    W0 var byte
    epin var word   <<<<<  i think this is address ?
    
    W0 = 0
    FOR cntr = 0 TO 2000  	'should be( FOR epin= 0  TO 2000 )!	or (cntr)should be var  xxx
    epin = epin + 5		'
    I2CWRITE porte.1,porte.2,%10100000,epin,[W0,W0,W0,W0,W0],error	
    pause 10						'
    						'
    NEXT cntr
    hope this helps
    see Gusse code moght it helps
    Yes epin is an address word but it is incremented by the line:
    epin = epin + 5 in the code I provided.
    This is correct because the I2CWRITE command has written five addresses sequentially.
    The cntr var should be declared at the top, I forgot that.

    Art, I have used external eeproms on most all of my projects and have never had any problems with bad data.
    Hi Dave,
    Solar electricity rules, and if you use it to run a fridge it slaps nature in the face
    I'll try a paralel resistor value to equal 2.2K, and retry the DEFINE I2C_SLOW 1.
    Normally I don't have problems with EEPROMS either.

    One other thing.
    I have introduced five new byte vars, and done a readback of the five
    written bytes so the program can verify what was read from the EEPROM is
    the same as what was written 10ms ago.
    If the results don't match, it goes back to rewrite the original (correct) values.

    When it gets to one of the addresses in question, it just hangs there
    rewriting all the time, and never getting the data right.

  5. #5
    Join Date
    Jan 2010
    Location
    morocco
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I JUST DESCOVERED THE BLOODY PROBLEM IS
    Code:
    I2CAddressEEprom    VAR WORD
    WHEN U PUT VAR BYTE IT WORKS GREAT BUT WHEN U PUT VAR WORD IT DOESNT IT WRITES ONLY 4TH BYTE .IM CONFUSED THE PROBLEM IS IN THE ADRESS OR THE DATA X,

    HOPE U CAN FIND IT GUYS
    GOOD LUCK ..!
    Last edited by MR2010; - 26th January 2010 at 09:56.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Whether you use a word or byte address depends on the EEPROM device.
    It's in the manual for I2CREAD.

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


    Did you find this post helpful? Yes | No

    Default

    Address size depends on EEPROM size (see table)
    PicBasic Manual I2C -part
    (2 bytes = 1 word)

    Manual is Your friend

    BR,
    -Gusse-
    Last edited by Gusse; - 26th January 2010 at 10:24. Reason: Repeating same as Art ;)

  8. #8
    Join Date
    Jan 2010
    Location
    morocco
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by art View Post
    whether you use a word or byte address depends on the eeprom device.
    It's in the manual for i2cread.

    yeah but when u use xxx var byte

    for xxx = 0 to 255 it works
    THE PROBLEM IS WHEN IT COUNT FROM 0 TO 1023 IN WORD VAR IT DOES SOMETHING WRONG IM OUT FOR JOB WILL TRY LATER TAKE CARE EVERYONES I KNOW U WILL FINDOUT


    try it out
    Last edited by MR2010; - 26th January 2010 at 10:24.

  9. #9
    Join Date
    Jul 2005
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    I have been reading this discussion with interest as I have had a similiar problem to yours.

    What I tried to do was to write 32 words in a word array to a 24LC256. Initially my micro was the 18F452, but I have moved over to the 18F4680. Both devices gave the same problem. My line of code was:

    DATA var WORD [31]
    AA var WORD
    I2WR var byte
    I2ADDR var WORD

    I2CWRITE PORTC.4, PORTC.3, I2WR, I2ADDR, [ STR DATA\32 ], I2C_ERR

    I would then read the data back as single words:

    I2CREAD PORTC.4, PORTC.3, I2RD, I2ADDR, [ AA ], I2C_ERR


    When I read the data back, I would repeatedly read some correct data, a bunch of $FFFF, more correct data, then the data would appear to 'move' and would not be at the designated eprom address. All very strange, but whats more it was repeatable within locations of the device.

    The device data sheet specifiies that it can read and write a page of 64 bytes, (32 words).

    I over came the problem by writing each word in the word array individually, pausing 5 ms between each word write. Not the best solution but it work. This way wastes 160ms of processing time.

    I am still trying to find a way to solve my problem as I really need to write the data block in one hit. I might try using the hardware I2C technique next as I2CWRITE ... [ STR DATA\32] didn't work for me.


    Paul.

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


    Did you find this post helpful? Yes | No

    Default

    Paul, I notice that you have only declared 31 WORDS but you are loading the eeprom with 32 BYTES. You can only load individual BYTES into the eeprom even if they are in an array. You would be loading the LOWBYTE of each of the words in the DATA array into the eeprom. Even then, you have only declared 31 words and not 32.

    Dave Purola,
    N8NTA

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