24LC256 and PIC16F877


Closed Thread
Results 1 to 3 of 3
  1. #1
    Tomas's Avatar
    Tomas Guest

    Post 24LC256 and PIC16F877

    Hi,

    I have used I2CREAD and I2CWRITE in order to write to and read from the 24LC256 EEPROM. As example code i'm using I2CX.bas with the byte address changed to WORD.
    I have connected the two wires in I2C protocol as follows:

    SCL var PORTC.3 ' Clock pin
    SDA var PORTC.4 ' Data pin

    These two pins according to the 24LC256 data sheet are not supposed to be HIGH as the same time. However after lodding the .HEX file the pins were constantly HIGH. The conde looks like this:

    For B0 = 0 To 15 ' Loop 16 times
    B1 = B0 + 100 ' B1 is data for SEEPROM
    I2CWRITE SDA,SCL,$A0,B0,[B1] ' Write each location
    Pause 10 ' Delay 10ms after each write
    Next B0

    Loop: For B0 = 0 To 15 Step 2 ' Loop 8 times
    I2CREAD SDA,SCL,$A0,B0,[B1,B2] ' Read 2 locations in a row
    Lcdout $fe,1,#B0,": ",#B1," ",#B2," " ' Display 2 locations
    Pause 1000
    Next B0

    Goto loop

    Finally when running all i can see is the address incrementing by 2 and the two data variables B1 and B2 were just 0.
    Can anyone see what the problem is? Please help. Thanks for you time in advance.
    Tom

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Hi Tom,

    assuming the variables used are declared as:

    B0 VAR WORD
    B1 VAR BYTE
    B2 VAR BYTE

    the code is ok.


    If you are using a fast crystal (20MHz), add these two DEFINEs:

    DEFINE I2C_SLOW 1
    DEFINE I2C_SCLOUT 1

    Add pullups (4k7) to the data and clock line and it should work.
    (it might work with a pullup on the data line only)

    rgds
    Last edited by NavMicroSystems; - 1st March 2004 at 17:27.

  3. #3
    Tomas's Avatar
    Tomas Guest


    Did you find this post helpful? Yes | No

    Smile It works!

    Hi,
    It works now, i had 10K to pull up the data and clock lines. May be that coursed the problem. Thank you very much.
    I have 8 of 25LC256 devices and in each device i will store A/D results until they are full and once full start storing again.
    I'm thinking to do it as follows:
    I'll store the result of the A/D from say channel 0 in EEPROM-device 1 with device-address $A0.
    And the result to the A/D from channel 1 will be stored in EEPROM device 2 with device address $A2.
    And the the last EEPROM-device will have address of $AE and A/D result from channel 7 will be stored in it.
    I'm thinking to use FOR ... NEXT and there is 32 768 bytes in each device. However i'm worried if this approach will take a lot of time and i'm not sure how to write to the 64 byte page of an 24LC256 device.
    Once this is done, i like to send the results from each EEPROM to a PC using RS232 protocol.
    I'm new to PicBasic Pro and i know that the way i'm thinking to do is so "BAD". Can you please give some tips how to approach the problem with good performance?
    Best Regards,
    Tom.

Similar Threads

  1. PIC16F877 and EEPROM FM24C16A
    By igeorge in forum Schematics
    Replies: 13
    Last Post: - 14th December 2004, 01:21

Members who have read this thread : 1

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