How to read & write to a 25aa1024 (1 Mbit SPI Bus Serial EEPROM) via 16F88


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41

    Default

    Quote Originally Posted by mackrackit View Post
    How do you have pins A0 and A1 connected?

    I have not had a chance to work on this today yet so I do not have any new news.

    Tied to ground.

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

    Default This one is for Dave...

    mackrackit, You can't use Shiftout and Shiftin for an I2C bus driven part. That is why you had no luck using it with a 24FC1025... It requires the pullup resistor for communicating the ACK signal back to the processor. Shiftout keeps the pin in an active state wghich ever it is... I recently posted code for talking to 24LC1025's here on the forum... Why not just use it for a starting point... I don't remember which thread it was in reply to but I believe it had to do with I2C....

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41

    Default

    Dave,

    I've searched through all the posts on the 24LC1025 and didn't find any code you posted but I found code that is basically the same as what I have tried already. If you can find the thread you were thinking of that would be great.

    The only thing I have not tried is changing is my pullups from 4.7k to 2k and trying to write to it 1 page at a time but if I cant byte-write to begin with I'm sure the page write will not work either. I will try changing the Pullups tonight and see what happens.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I got the idea for shifting here.
    http://www.rentron.com/PicBasic/i2c_communication.htm

    Reading back over my code and data sheet I see some things are backwards. Maybe ...

    Never did find that code posting. Found lots of others for different parts.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41

    Default Changed the Pullups to 2.2K and still no change

    Everything is the same as before with the new pullup values of 2.2K...back to the drawing board

    I am going to be out of town for the next week so I wont be able to test anything new but I will be on here checking if any new ideas/breakthroughs come up.
    Last edited by wolwil; - 18th April 2010 at 02:24.

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

    Default

    wolwil, Here it is again incase you didn't find it. Maxpages is set for 1023 x the number of 24LC1025's you have connected. The routine saves the last storage pointer in the last 2 locations of the last 24LC1025. Block is incremented once for each page. Before you start a clean write you would set block to 0 which is the first page. When you want to read back the data then you would call READ_WRITE_BLK1025 and block would have the last address written..

    This routine is rock solid and I use it for accessing 4 x 24LC1025's for a total of over 4 gigabits of memoy to record Azmnuth,Elevation,East/West/Up/Down Sensor data and control flag information for about 2 months at 1 minute intervals... I hope this helps...

    Code:
     
    CNTRL_BYTE    CON    $A0        'CONTROL BYTE FOR 24LC1025 I2C EEPROM MEMORY (A0/A1 USED FOR CHIP SELECT)
    MAX_PAGES    CON    4095    'MAXIMUM MEMORY STORAGE PAGES,(32 BYTES/MINUTE x 4 MINUTES x PAGES = TOTAL MINUTES)
     
    '*********************************************************************
    RW_EEPROM1025:        'READ FROM or WRITE TO SERIAL EEPROM
    '*********************************************************************
        IF READ_WRITE = 1 THEN    'WRITE 128 BYTE BLOCK TO EEPROM
            IF BLOCK <> 0 THEN    'IF STARTING NEW PASS DON'T READ OLD LOCATION
                READ_WRITE = 0    'SET FOR BLOCK READ
                GOSUB READ_WRITE_BLK1025    'READ FROM SERIAL EEPROM NEXT AVAILABLE STORAGE BLOCK
                READ_WRITE = 1    'SET FOR BLOCK WRITE
            ENDIF
            DEVICE = BLOCK / 512    'SELECT WHICH PHYSICAL ADDRESS BOUNDRY & EEPROM
            ADDRESS = BLOCK << 7    'CALCULATE 12C ADDRESS TO STORE DATA TO
            CNTROL_BYTE = CNTRL_BYTE    'COPY CONTROL BYTE
            CNTROL_BYTE.1 = DEVICE.1    'SET LSB OF HARDWARE ADDRESS
            CNTROL_BYTE.2 = DEVICE.2    'SET MSB OF HARDWARE ADDRESS
            CNTROL_BYTE.3 = DEVICE.0    'SET 64K BLOCK BIT
            INTCON.7 = 0    'CLEAR GLOBAL INTERRUPT
            I2CWRITE SDA,SCL,CNTROL_BYTE,ADDRESS,[STR STOR_DATA\128]    'SAVE DATA TO 12C
            WRITEOCCURED = 1
            INTCON.7 = 1    'SET GLOBAL INTERRUPT
            PAUSE 6        'ALLOW TIME FOR I2C WRITE ~5Ms.
            BLOCK = BLOCK + 1    'INCREMENT FOR NEXT AVAILABLE BLOCK TO WRITE
            BLOCK = BLOCK MIN MAX_PAGES    'LIMIT TO n BLOCKS OF 128 BYTES
            GOSUB READ_WRITE_BLK1025    'WRITE TO or READ FROM SERIAL EEPROM LAST STORAGE BLOCK
        ELSE
            DEVICE = BLOCK / 512    'SELECT WHICH PHYSICAL ADDRESS BOUNDRY & EEPROM
            ADDRESS = BLOCK << 7    'CALCULATE 12C ADDRESS TO STORE DATA TO
            CNTROL_BYTE = CNTRL_BYTE    'COPY CONTROL BYTE
            CNTROL_BYTE.1 = DEVICE.1    'SET LSB OF HARDWARE ADDRESS
            CNTROL_BYTE.2 = DEVICE.2    'SET MSB OF HARDWARE ADDRESS
            CNTROL_BYTE.3 = DEVICE.0    'SET 64K BLOCK BIT
            INTCON.7 = 0    'CLEAR GLOBAL INTERRUPT
            I2CREAD SDA,SCL,CNTROL_BYTE,ADDRESS,[STR READ_DATA\128]    'LOAD IN ENTIRE BLOCK
            WRITEOCCURED = 1
            INTCON.7 = 1    'SET GLOBAL INTERRUPT
        ENDIF
        RETURN
     
    '*********************************************************************
    READ_WRITE_BLK1025:    'WRITE TO or READ FROM SERIAL EEPROM NEXT AVAILABLE STORAGE BLOCK
    '*********************************************************************
        ADDRESS = 65534        'POINT TO LAST STORED DATA(WORD) ADDRESS
        DEVICE = MAX_PAGES / 512    'SELECT WHICH PHYSICAL ADDRESS BOUNDRY & EEPROM
        CNTROL_BYTE = CNTRL_BYTE    'COPY CONTROL BYTE
        CNTROL_BYTE.1 = DEVICE.1    'SET LSB OF HARDWARE ADDRESS
        CNTROL_BYTE.2 = DEVICE.2    'SET MSB OF HARDWARE ADDRESS
        CNTROL_BYTE.3 = DEVICE.0    'SET 64K BLOCK BIT
        IF READ_WRITE = 1 THEN
            INTCON.7 = 0    'CLEAR GLOBAL INTERRUPT
            I2CWRITE SDA,SCL,CNTROL_BYTE,ADDRESS,[BLOCK.LOWBYTE,BLOCK.HIGHBYTE]    'WRITE DATA POINTER TO 12C    
            WRITEOCCURED = 1
            INTCON.7 = 1    'SET GLOBAL INTERRUPT
            PAUSE 6        'ALLOW TIME FOR I2C WRITE ~5Ms.
        ELSE
            INTCON.7 = 0    'CLEAR GLOBAL INTERRUPT
            I2CREAD SDA,SCL,CNTROL_BYTE,ADDRESS,[BLOCK.LOWBYTE,BLOCK.HIGHBYTE]    'READ DATA POINTER FROM 12C    
            WRITEOCCURED = 1
            INTCON.7 = 1    'SET GLOBAL INTERRUPT
        ENDIF
        RETURN
    Dave Purola,
    N8NTA
    Last edited by ScaleRobotics; - 14th June 2010 at 02:24. Reason: Added code tags

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Hi Dave,
    Thanks for posting your code. I also found my problem...

    My problem is "I am a newbe!!!".
    I forgot PORTF.6 on the 18F6680 is an analog pin.
    RTFD RTFD RTFD

    For what it is worth.. When I take care of the analog issue I can read the part with SHIFTIN/OUT. I can not write to the part that way yet. Still have a timing problem I guess. It may not be worth messing with other than an exercise in coding.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41

    Default

    Quote Originally Posted by Dave View Post
    CNTRL_BYTE CON $A0 'CONTROL BYTE FOR 24LC1025 I2C EEPROM MEMORY (A0/A1 USED FOR CHIP SELECT)
    Maybe this is where I am getting confused... you have the control byte being $A0 which is basically saying to write to the 24LC1025 seeing how the read write bit in that is a 0 like this "10100000" but the you say in your comment that the A0/A1 is for chip select...So in this following line of code where I have the $A0 is that the 8 bit control byte or just the Chip Select portion of it???

    Code:
    I2CREAD PORTB.1,PORTB.4,$A0,addr,[B1]
    See I thought if I wanted to write to chip select A1 I needed to use $A2 or in binary like this %10100010 and if I wanted to read from it I needed to use $A3 or in binary like this %10100011.

    Every combination to read and write to all 4 Chips:

    %10100000 or $A0 = Write to A0 (Pins A0 & A1 Tied Low)
    %10100001 or $A1 = Read from A0
    %10100010 or $A2 = Write to A1 (Pins A0 Tied Low & A1 Tied High)
    %10100011 or $A3 = Read from A1
    %10100100 or $A4 = Write to A2 (Pins A0 Tied High & A1 Tied Low)
    %10100101 or $A5 = Read from A2
    %10100110 or $A6 = Write to A3 (Pins A0 and A1 Tied High)
    %10100111 or $A7 = Read from A3

    So with me having both A0 and A1 Pins Tied to ground I should be using the first 2 options when trying to read/write to the chip or am I just way off on this???

    Am I incorrect in my thinking of what PBP is calling the Control Byte???

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