I2CWRITE problem


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dave View Post
    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

    Hi Dave,

    That is correct, the 1st element in the array, DATA[0], the second element DATA[1], the 32nd DATA[31].

    The STR command counts the elements in an array, [ STR DATA\1] would send element DATA[0]. PBPro knows if I am using WORDS or BYTES and counts them appropriately.

    In this section of the PBPro manual, it clearly states that WORD variable arrays can be sent.

    Paul.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by Paul View Post
    Hi Dave,

    That is correct, the 1st element in the array, DATA[0], the second element DATA[1], the 32nd DATA[31].

    The STR command counts the elements in an array, [ STR DATA\1] would send element DATA[0]. PBPro knows if I am using WORDS or BYTES and counts them appropriately.

    In this section of the PBPro manual, it clearly states that WORD variable arrays can be sent.

    Paul.
    Hi Paul,

    Check from manual about Arrays

    It is two different things:
    - Number of elements (array; 1,2,3,... )
    - Location of element (string; 0,1,2,... )

    BR,
    -Gusse-
    Last edited by Gusse; - 26th January 2010 at 14:41.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Just to elaborate on the problem,
    The middle part of this video shows the function that writes to EEPROM.
    The messages are short because I can only type about 15 letters before
    the first one stuffs up.
    Each letter requires 6 bytes because they are stored as mono bitmaps,
    and there is some lead in space written with zeros.



    Art.

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


    Did you find this post helpful? Yes | No

    Post

    Hi Art,

    Couple of things came to my mind:

    What is your oscillator speed?
    - I didn't see any DEFINE OSC parameter.

    Is EEPROM only load in I2C bus?
    - Capacitive loading below 400pF per signal line (I2C spec)

    How long wires you have between PIC and EEPROM?
    - Timing CLK & data (this should not be a problem for I2C)

    Write control pin in EEPROM?
    - Grounded? Don't know if floating pin could do something like this?

    De-coupling of PIC and EEPROM?
    - How many caps and sizes

    Crosstalk
    - Any nearby signals that could cause coupling?

    Grounding
    - How is the grounding done? Ground bounce due to common impedance with some high current part of the system (Power supply, PIC, etc...).

    Errors in write mode seems to be very systematic so it can't be just noise, which is causing the problem.

    BR,
    -Gusse-
    Last edited by Gusse; - 26th January 2010 at 16:27. Reason: Some typos corrected

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


    Did you find this post helpful? Yes | No

    Default

    Paul, Yes I understand that the base element number starts at 0 but, you are DECLARING only 31 elements in the array and not 32. Your declaration of the array size has to be the actual number of elements NOT the last element index. RTFM..... Also think about this statement from the manual...(While a single I2CWRITE statement may be used to write multiple bytes at once, doing so may violate the above write timing requirement for serial EEPROMs. Some serial EEPROMS let you write multiple bytes into a single page before necessitating the wait. Check the data sheet for the specific device you are using for these details. The multiple byte write feature may also be useful with I2C devices other than serial EEPROMs that don=t have to wait between writes.) Thats why I always use the page mode.....

    Dave Purola,
    N8NTA
    Last edited by Dave; - 26th January 2010 at 19:42. Reason: I forgot....

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    DATA var WORD [31]
    It's the same in any programming language.
    You declare the number of elements as a Human would say it
    "there are 31 elements in the array" (not correct in this case).

    Man I tried everything..
    2.2K resistors, even shortened the clock and data wired to about six cm each.
    it's really time for a new circuit to do the same test,
    but I don't know what else I could change.
    Last edited by Art; - 27th January 2010 at 01:11. Reason: I just get the urge to edit sometimes

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


    Did you find this post helpful? Yes | No

    Default

    Art, Have you tried the page write mode for storing your data? True, you need a shadow array the size of the page you are trying to write but it is much faster to write a full page than individual bytes if you have any quanity.. Try these subroutines that I wrote a long time ago for an analog waveform generator using a single 24LC512 utilizing the page mode. This routine will store 7 diferent files, made up of 64 blocks of 128 bytes each. I hope this helps...

    CNTRL_BYTE CON $A0 'CONTROL BYTE FOR I2C EEPROM MEMORY (A0/A1 USED FOR CHIP SELECT)
    BLOCK VAR BYTE '64 BLOCK ADDRESS BYTE
    ADDRESS VAR WORD 'ADDRESS WORD FOR SERIAL EEPROM
    CNTROL_BYTE VAR BYTE 'CONTROL BYTE TO SEND TO SERIAL EEPROM
    STOR_DATA VAR BYTE[128]'STORAGE DATA ARRAY
    FILE VAR BYTE 'FILE STORAGE NUMBER 0 to 7

    '************************************************* ********************
    WRITE_EEPROM512: 'WRITE TO SERIAL EEPROM
    '************************************************* ********************
    ADDRESS = FILE << 13 'CALCULATE 12C ADDRESS TO STORE DATA TO
    ADDRESS = ADDRESS + (BLOCK << 7) 'CALCULATE 12C ADDRESS TO STORE DATA TO
    CNTROL_BYTE = CNTRL_BYTE 'COPY CONTROL BYTE
    CNTROL_BYTE.1 = 0' 'SET LSB OF HARDWARE ADDRESS
    CNTROL_BYTE.2 = 0' 'SET MSB-1 OF HARDWARE ADDRESS
    CNTROL_BYTE.3 = 0' 'SET MSB OF HARDWARE ADDRESS
    I2CWRITE SDA,SCL,CNTROL_BYTE,ADDRESS,[STR STOR_DATA\128] 'SAVE DATA TO 12C
    PAUSE 6 'ALLOW TIME FOR I2C WRITE ~5Ms.
    BLOCK = BLOCK + 1 'INCREMENT BLOCK NUMBER
    RETURN

    '************************************************* ********************
    READ_EEPROM512: 'READ FROM SERIAL EEPROM
    '************************************************* ********************
    ADDRESS = FILE << 13 'CALCULATE 12C ADDRESS TO STORE DATA TO
    ADDRESS = ADDRESS + (BLOCK << 7) 'CALCULATE 12C ADDRESS TO STORE DATA TO
    CNTROL_BYTE = CNTRL_BYTE 'COPY CONTROL BYTE
    CNTROL_BYTE.1 = 0' 'SET LSB OF HARDWARE ADDRESS
    CNTROL_BYTE.2 = 0' 'SET MSB-1 OF HARDWARE ADDRESS
    CNTROL_BYTE.3 = 0' 'SET MSB OF HARDWARE ADDRESS
    I2CREAD SDA,SCL,CNTROL_BYTE,ADDRESS,[STR STOR_DATA\128] 'LOAD IN ENTIRE BLOCK
    RETURN

    Dave Purola,
    N8NTA

  8. #8
    Join Date
    Jul 2005
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Gusse View Post
    Hi Paul,

    Check from manual about Arrays

    It is two different things:
    - Number of elements (array; 1,2,3,... )
    - Location of element (string; 0,1,2,... )

    BR,
    -Gusse-

    I had read this section of the manual sometime ago, and have obviously forgotten. Thank you Gusse, Art and Dave. It is good to be corrected and shown your error. Even with the change in array declaration, my page write I2C routine still will not work and exhibit the previously described problem. I will look at the physical aspects of the design (hardware), failing that attempt the hardware I2C routine. I have found some examples of code in the forums.

    Paul

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Dave,
    I can't really use page write because I only want to write 6 bytes at a time.
    The code in the first post only writes zeros, but it isn't really what I want in my application... it's just a simplified code that exhibits the problem.

    I'm duplicating the hardware today, so this will be interesting.

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


    Did you find this post helpful? Yes | No

    Default

    Art, Are you accumulating the data or just re-writing the values at the same locations? If you are accumulating the values (data logger style (appending)) then just wait till you have 64,128 or so on (eeprom page dependent) , readings stored in the shadow ram then dump them to the eeprom.

    Dave Purola,
    N8NTA

  11. #11
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    That's a lot of bytes of RAM for the 16F877.
    I think you get 368 bytes RAM, and PBP consumes some of that.

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


    Did you find this post helpful? Yes | No

    Default

    Art, Like I said, you can use a smaller eeprom like the 24LC256 or 24LC128 which has a 64 byte page write size or as small as a 24LC01B which has an 8 byte page write.

    Dave Purola,
    N8NTA

Similar Threads

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