I2c write&read


Closed Thread
Results 1 to 16 of 16

Thread: I2c write&read

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    85

    Default I2c write&read

    Hi every one,
    i ahce a problem with writing and reading using I2C WRITE...

    thansk for any help,
    -----------------

    here is the connection:

    pic16f628: porta.6 and 7 are SDA & SCL

    24lc256 (8 bit EEPROM): A0,1,2,3,4 and WP: ground
    SDA &SCL connected 10k to 5V...
    ------------------------
    ;the program:


    CMCON = 1
    TRISA = %11000000 ; set port A6,7 to input (SDA & SLC)
    TRISB = 0
    DPin var PORTA.6 ' I2C data pin
    Cpin var PORTA.7 ' I2C clock pin

    I var byte
    S VAR BYTE
    b1 var byte
    k var byte

    B0 var byte

    i = 0
    b0 = 0

    while b0 != $ff
    lookup I, [$3F,$48,$48,$48,$3F,$3F,$00,$ff],B0 ;put a value into
    ;B0
    I2CWRITE DPIN,CPIN,$A0,i,[B0] ' Write B0 to address I

    Pause 10 ' Delay 10ms after each write
    i = i+1 ' increase the address by 1
    wend
    loop:
    ;reading process
    b1 = 0 ; clear b1
    while b1 !=$ff
    I2CREAD DPIN,CPIN,$A1,i,[B1]

    FOR K = 0 TO 63 ; scan for 64 times
    CALL RESET
    PORTB = b1
    CALL DELAY

    NEXT K
    i = i +1
    wend
    goto loop
    end
    RESET: PORTA.1 = 1 ;RESET 4017
    @NOP
    PORTA.1 = 0
    RETURN

    DELAY: pause 10
    portb = 0 ; reset portb
    porta.0 = 1 ; clock the 4017
    @nop
    porta.0 = 0
    return

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


    Did you find this post helpful? Yes | No

    Post Faq

    Read this thread: I2CRead & I2CWrite not working as expected

    BR,
    -Gusse-

  3. #3
    Join Date
    Apr 2008
    Posts
    85


    Did you find this post helpful? Yes | No

    Default

    thanks for your words,

    i checked but it is ok, the device is 8 bit size. and the address is variable..
    all are defined by BYTE.
    i.e i = 0 to 10 ;(i : location in the EEPROM)


    thanks agains
    MInhle

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


    Did you find this post helpful? Yes | No

    Post

    Hi MInhle,

    Check once more the thread and do like Melanie advices!

    Define I2CDevice as a BYTE, not a constant.
    Define I2CAddress as a WORD (your EEPROM is >16k and therefore variable must be a word)

    Example:
    I2CWrite SDA,SCL,I2CDevice,I2CAddress,[DataA]

    BR,
    -Gusse-
    Last edited by Gusse; - 4th January 2010 at 08:25.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    10K is also a little high... drop it by at least half to say 4K7.

  6. #6
    Join Date
    Apr 2008
    Posts
    85


    Did you find this post helpful? Yes | No

    Default

    Hello All,

    the deviec is 16f628. the OSC 20Mhz (internal OSC, so R is ~10k-12K)
    and the 24lc256 is BYTE SIZE. (32K X8 BIT)
    the address is variable.

    i will change to 4.7k and redefine eeprom address.

    however the fuse defined: (work well )

    OSC: INTRO CLOCKOUT
    MCLR: INPUT PIN
    (all other defined in the fuse window: marain unchange)

    thank for all

    regards,

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

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