Problem with I2C (24c32 eeprom)


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default I2C using 24C32, Lab-X1

    I'm new to PIC & this is my 1st post. I know this is an old thread but I had a similar problem with the "255" output & could not find a specific fix. Maybe this update will help out going forward.

    Final summary - I changed B0 from "BYTE" to "Word". This allowed correct excecution but I don't know if it was the real cause.

    My whining goes here .. after 3 days of data sheets, permutations of the code and troubleshhoting the Lab-X1. (which really did'nt need any)

    Detail - The hardware is brand new flawless Lab-X1. The original code is straight from the Lab-X1 included files = i2cx.bas (below) with a 24C32 eeprom. 16f877a

    Using MCS+ with ME U2 programmer & ICD:
    Define LOADER_USED 1

    .................................................. ........

    'Define LCD registers and bits
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1

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

    B0 var Byte ' Address <<<<I changed this to "WORD"
    B1 var byte ' Data 1
    B2 var byte ' Data 2

    ADCON1 = 7 ' Set PORTA and PORTE to digital
    Low PORTE.2 ' LCD R/W line low (W)
    Pause 100 ' Wait for LCD to start up


    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

    End

    ...........................

    The MCS+ ICD shows that variables B1 & B2 increment properly but when the program goes from this line:

    I2CREAD SDA,SCL,$A0,B0,[B1,B2] ' Read 2 locations in a row

    to this line:

    Lcdout $fe,1,#B0,": ",#B1," ",#B2," " ' Display 2 locations

    then both B1 & B2 go to the 255 value.

    The data sheet for the eeprom states that it uses a "byte" size variable.
    The MELAb code defines the variable properly.

    As a newbie I get to say for at least a couple more posts "I don't get it" why the change from the I2Cread line to the LCDOUT line would change the variable to 255.

    My complements to MELABS MCS+ for a nice ICD combo.
    Last edited by MikeM17; - 3rd October 2007 at 19:56.

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


    Did you find this post helpful? Yes | No

    Default

    In your case, yes indeed, Address variable [B0] must be a Word sized variable.

    let's see if we open and read the 24c32 datasheet...
    http://www.atmel.com/dyn/resources/p...ts/doc0336.pdf

    PDF page 11, figure 2, it really show you need to send the device Address/Control Byte ($A0), then Word Address (2 bytes-1 Word), and finally the data.
    Steve

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

  3. #3
    Join Date
    Sep 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    OK Steve, thx. ... Lesson learned:
    "Speed reading the data sheet 12 times does not equal slooowww reading it once." Maybe I'll use that under my signature.

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. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  5. I2C eeprom and DS1307 @40MHz problem
    By ius01 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th July 2007, 07:41

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