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
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I have tried several different resistor sizes and still nothing.
    I think I am actually communicating with it as it "ACK" backs at me...
    Here is my current mess...
    Code:
    '  18F6680  24FC1025
        DEFINE OSC 20
        @ __CONFIG    _CONFIG1H, _OSC_HS_1H
        @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
        @ __CONFIG    _CONFIG4L, _LVP_OFF_4L
        
        TRISF = 0
        PORTF = 0
       
        DPIN    VAR PORTF.6    'I2C DATA PIN
        CPIN    VAR PORTF.7    'I2C CLOCK PIN
        CONTR   CON %10100001  'READ CONTROL
        CONTW   CON %10100000  'WRITE CONTROL
        ADDR_HB    VAR BYTE
        ADDR_LB    VAR BYTE
        DATI    VAR BYTE
        DATO    VAR BYTE
        ACK     VAR BIT
        ADDR_HB = %00000000
        ADDR_LB = %00000000
        DATO = %11100000
        CNT VAR BYTE
        CNT = 0
        
        START:CNT = CNT + 1
        GOSUB WRITE_DATA
        PAUSE 100
        GOSUB READ_DATA
        SEROUT2 PORTB.2, 16572,["TEST ",DEC CNT,$d,$a]
        Serout2 PORTB.2, 16572,["DATA IN ",BIN DATI]      
        SEROUT2 PORTB.2, 16572,[$d,$a]
        PAUSE 500
        GOTO START
        
        WRITE_DATA:  ACK=1   :Serout2 PORTB.2, 16572,["ACK ",BIN ACK,$d,$a] 
        GOSUB START_ROM
        SHIFTOUT DPIN,CPIN,1,[CONTW]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        Serout2 PORTB.2, 16572,["ACK ",BIN ACK,$d,$a] 
        SHIFTOUT DPIN,CPIN,1,[ADDR_HB]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        SHIFTOUT DPIN,CPIN,1,[ADDR_LB]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        SHIFTOUT DPIN,CPIN,1,[DATO]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        GOSUB STOP_ROM
        PAUSE 10
        RETURN
        
        READ_DATA:
        GOSUB START_ROM
        SHIFTOUT DPIN,CPIN,1,[CONTR]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        SHIFTOUT DPIN,CPIN,1,[ADDR_HB]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        SHIFTOUT DPIN,CPIN,1,[ADDR_LB]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        GOSUB START_ROM
        SHIFTOUT DPIN,CPIN,1,[CONTR]
        SHIFTIN DPIN,CPIN,0,[ACK\1]
        SHIFTIN DPIN,CPIN,0,[DATI\8]
        GOSUB STOP_ROM
        PAUSE 10
        RETURN
        
        START_ROM:
        HIGH CPIN:HIGH DPIN:LOW DPIN:RETURN
        STOP_ROM:
        HIGH CPIN:LOW DPIN:HIGH DPIN:RETURN
    Dave
    Always wear safety glasses while programming.

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

    Default I made a break through I just don't know what it means :D

    I changed the Control Byte for the read and the write from this:
    Code:
    contR    CON     %10100001                  
    contW    CON     %10100000
    to this:
    Code:
    contR    CON     %10100011                  
    contW    CON     %10100010
    Thinking that because A2 is held high for it to operate then the control bit for A2 should also be a 1... here is the new code:
    Code:
    DEFINE I2C_SLOW 1
    SO      con     0                           ' Define serial output pin
    T2400   con     0                           ' Define serial mode
    contR    CON     %10100011                   ' Define Control byte
    contW    CON     %10100010                   ' Define Control byte
    addr    CON     %0000000000000111           ' 2 Byte Address of 7
    addr2   CON     %0000000000001000           ' 2 Byte Address of 8
    D1      CON     %00000111
    B0      VAR     BYTE                        ' Var for data being read
    B1      VAR     BYTE                        ' Var for data being read
    
    B0 = 0
    B1 = 0
    I2CWRITE PORTB.1,PORTB.4,contW,addr,[D1]      ' Send the byte 1 to address 7
    
    PAUSE 10                                    ' Wait 10ms for write to complete
    
    I2CREAD PORTB.1,PORTB.4,contR,addr,[B1]      ' Read address 7 into B1
    I2CREAD PORTB.1,PORTB.4,contR,addr2,[B0]      ' Read address 8 into B0
    
    Serout SO,T2400,["Addr",#addr,":",#B1," and then Addr",#addr2,":",#B0,13,10] ' Print B1's Value in DEC
    this is the output from hyperterm:
    Code:
    Addr7:2 and then 2
    Like I said I don't know what it means but it sure is different then what I was getting.

    Any thoughts as to why it now is reading a "2" and not 255 or 0??? Its almost like it read the last 2 bits of the write control byte as if the write command wrote the last 2 bits of the control byte to the EEPROM.


    UPDATE:
    I just switched the control byte to be:
    Code:
    contR    CON     %10100001                  
    contW    CON     %10100010
    and got this as an output (Note the "6" in Address 8 to begin and then it get over written to "255" the next go around):
    Code:
    Addr7:2 and then Addr8:6
    Addr7:2 and then Addr8:255
    Addr7:2 and then Addr8:255
    Addr7:2 and then Addr8:255
    Addr7:2 and then Addr8:255
    also I know I'm writing to it because in the example output above I read address 6 with it too (not shown in the code but I added it after posting) and I was reading "255" every time. So this tells me that I am writing a "6" to address 8 but then on the second loop it gets over written/erased to "255" but the "2" in address 7 remains constant and in memory. Now keep in mind that no where in my code do I try to write to address 8 it just happens, more than likely from an over flow from the write to address 7. So basically the byte I am trying to write to 7 gets split into a "2" in address 7 and a "6" in address 8 then address 8 gets overwritten on the 2nd loop to a "255".

    and when I do the control byte like this:
    Code:
    contR    CON     %10100011                  
    contW    CON     %10100000
    I get this (the same as having both A2 bits set to 1):
    Code:
    Addr7:2 and then Addr8:2
    Addr7:2 and then Addr8:2
    Addr7:2 and then Addr8:2
    Last edited by wolwil; - 17th April 2010 at 05:37.

  3. #3
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Sorry, read the data sheet wrong. Nevermind
    Last edited by ScaleRobotics; - 17th April 2010 at 06:50.

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

    Default

    Whoops it dawned on me what I am doing by changing that Bit. I guess that my novice understanding of this made me stumble upon the fact that I am now writing and reading from a different Chip Select, but seeing how I only have the one chip I dont understand how its reading/writing chip 01 when it should be chip 00.

    So I guess where I was calling it the A2 bit its actually the A0 bit that I was changing.

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

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  6. #6
    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.

  7. #7
    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

  8. #8
    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.

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