I2C-With the 24LC16B


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    ron6699's Avatar
    ron6699 Guest

    Default I2C-With the 24LC16B

    Hi Guys!

    I have a Pic 16C84 with a serial Eeprom 24LC16B.
    I want to read the first 63 bytes and write it in the internel Eeprom
    of my Pic.

    My Programm:

    include "modedefs.bas"
    define OSC 4
    B0 var byte
    B1 var byte
    B2 var byte
    cont con %10100110



    for b0=0 to 63
    HIGH PORTB.4 'data pin
    HIGH PORTB.5 'clock pin
    Pause 50
    LOW PORTB.4 'start signal for 24LC16B
    I2cread PORTB.4,PORTB.5,cont,b0,B2
    pause 50
    write b0,b2
    LOW PORTB.4 'stop signal for 24LC16B
    next b0
    end

    This writes only "FF" in the internel Eeprom,
    not my Data from the serial Eeprom!

    Can you help me?

    RON

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what are your A0,A1,A2 settings... are they to ground?!? if so try this one
    Code:
    define OSC 4
    B0 var word
    B1 var byte
    B2 var byte
    cont con %10100000
    b1=0
    for b0=0 to 63
         I2cread PORTB.4,PORTB.5,cont,b0,[b2]
         write b1,b2
         pause 50
         b1=b1+1
    next b0
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    ron6699's Avatar
    ron6699 Guest


    Did you find this post helpful? Yes | No

    Unhappy Hi again!

    yes,A0,A1,A2 are on ground.

    but with your code,nothing happens.

    with my code the pic reads "FF" in the internal eeprom

    i have searched and posted in many forums last week,
    but nobody can help me.

    Please help me!

    RON

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    well it's suppose to work... can you send your data to your PC or on a PORT and monitor that??? have you put 1k - 4k7 pull-ups on SDA & SCL pins ?!? Is by any chance you revert SDA & SCL pins?!?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Be sure you have the WP (pin #7) tied to ground, and pull-up
    resistors on SDA & SCL (pins #4 & #5)

    A0, A1 and A2 are not used on the 24LC16B, so you can leave
    these pins (#1,#2,#3) floating.

    The control byte consists of a 4-bit control code of %1010 which
    remains constant.

    The next 3-bits in the control byte are the "block select bits".
    These can be from %000 to %111 for blocks 0 to 7 (8 blocks total).

    Note that these 3-bits are the high-order "address" bits, so you do
    not follow the control byte with a word sized variable for the address
    of this EEPROM. The upper 3-bits of the word address are the lower
    nibble bits 1,2,3 in the control byte.

    The last bit of the control byte is for read or write, but PBP will
    automatically flip this bit for you.

    So, the control byte can be from %1010 000 0 to %1010 111 0 to
    access blocks 0 to 8. The low-order address byte can be from 0-255.

    Code:
    B0 var byte
    B1 var byte
    B2 var byte
    Cont con %10100110 ' Control 1010 + block #3 address 011
    SYMBOL SDA = PORTB.4 ' Data pin
    SYMBOL SCL = PORTB.5 ' Clock pin
    
    Main:
        FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes 
          B1=B0+4        ' Write address + 4 to each location
          I2cWrite SDA,SCL,Cont,B0,[B1] ' Cont + B0 = word address
          PAUSE 10      ' Pause for writes
        NEXT B0
        
        FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes
          I2cRead SDA,SCL,Cont,B0,[B2] ' Cont + B0 = word address
          WRITE B0,B2
        NEXT B0
        
    Display:
        FOR B0 = 0 to 63
         READ B0,B2
         HSEROUT ["ADD: ",DEC B0," VAL: ",DEC B2,13,10]
        NEXT B0
    
    Here: GOTO Here
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    ron6699's Avatar
    ron6699 Guest


    Did you find this post helpful? Yes | No

    Unhappy 24lc16b

    Hi again!

    Thank you for your code example.

    But it still don't works.Sorry for that!

    Here is a Picture of my connections:

    http://www.xg-midifiles.de/24LC16B.jpg

    I use OSC=RC in my programmer settings.

    I can't understand wy it don't works.

    By'e
    RON

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