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

    Thumbs down Still doesn't work

    If you are still using the schematic from MeLabs then...
    Nope I found that mistake of mine earlier and fixed it

    The other thing I see in the data sheet is the last bit of the control byte sets Read or Write.
    0 = READ
    1 = WRITE
    Yeah this one amazes me with PBP having an I2CREAD and a I2CWRITE command but yet you still have to tell it to READ or WRITE?!?!?!

    Just to clarify I found this under section 5.0 saying that a READ operation should be a 1 and WRITE should be a 0
    The last bit of the control byte defines the operation to
    be performed. When set to a one, a read operation is
    selected, and when set to a zero, a write operation is
    selected.
    PAUSE 10 'Is that long enough?
    Yes I believe so because the 24FC1025 only has a 5ms delay needed

    And you may have to add this but try the above stuff first
    DEFINE I2C_SLOW 1
    I tried it and got the same results, nothing but 255's.

    Do you know if the 24FC1025 is flashed with all 0's or all 1's from the factory? Before I was getting %00000000 from var B1 and now I am getting %11111111 but I want to know if its actually reading that or if its a blip in the coding.

    Here is the updated code:
    Code:
    DEFINE I2C_SLOW 1
    SO      con     0                           ' Define serial output pin
    T2400   con     0                           ' Define serial mode
    contR    CON     %10100001                   ' Define Control byte
    contW    CON     %10100000                   ' Define Control byte
    addr    CON     %0000000000000111           ' 2 Byte Address of 7
    D1      CON     %00000111
    B0      VAR     BYTE                        ' Var for data being read
    B1      VAR     BYTE                        ' Var for 2nd byte 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,B0]      ' Read address 7 into B1
                                                   ' and address 8 into B0
    
    Serout SO,T2400,["Addr",#addr,":",#B1," and then ",#B0,13,10] ' Print
    I added a 2nd byte to check an address I have not written to and also get a 255 from that but early on in the code I set B1 and B0 to 0 and its getting changed somehow. So either I am reading all 1's from the addresses or the code is screwy.

    PS sorry about the novel here, but its late and I tend to ramble when I'm tired.

    Other notes:
    I am using a 4MHz external clock to run the show if that matters. I will be switching to a 20MHz once I have everything working.

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

    Default

    I picked up a couple of these 24FC1025 and I am not having any luck either.

    A0 and A1 and WP are connected to VSS.
    A2 connected to VDD.
    10K pull up on SDA and SCL.
    Tried "start/stop" sequence before and after I2C commands...

    Out put to terminal is 0 no matter what.
    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
        DEFINE I2C_SLOW 1
        DEFINE I2C_SCLOUT 1
        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    VAR WORD
        DATI    VAR BYTE
        DATO    VAR BYTE
        ADDR = %0000000000000000
        DATO = %11110000
        
        START:
        SEROUT2 PORTB.2, 16572,["TEST",$d,$a]
        PAUSE 1000
        
        HIGH CPIN:HIGH DPIN:LOW DPIN
        I2CWRITE DPIN,CPIN,CONTW,ADDR,[DATO]  
        HIGH CPIN:LOW DPIN:HIGH DPIN
        Pause 10                
    
        HIGH CPIN:HIGH DPIN:LOW DPIN
        I2CREAD DPIN,CPIN,CONTR,ADDR[DATI]        
        HIGH CPIN:LOW DPIN:HIGH DPIN
    
        Serout2 PORTB.2, 16572,["DATA IN ",BIN DATI]       
        SEROUT2 PORTB.2, 16572,[$d,$a]
    
        GOTO START
    Dave
    Always wear safety glasses while programming.

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

    Default

    I give up...
    Dave
    Always wear safety glasses while programming.

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

    Default

    I give up...
    Haha! Well at least I learned the problem isn't me

    So does anyone out there know the assembly code to make this work???

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

    Default

    When I get back tonight I am thinking of do some sort of bit banging, maybe that will work.
    Dave
    Always wear safety glasses while programming.

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

    Default

    mackrackit, Why are you using 10 k's for the pullup's? I believe the spec. says 4.7K or lower.. Might be the problem....

    Dave Purola,
    N8NTA

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

    Default

    The data sheet for this part call for 10k at 100 kHz and 2k for 400 kHz and 1 MHz.

    It did not work at the higher speeds so I was trying it at the slow.
    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
    mackrackit, Why are you using 10 k's for the pullup's? I believe the spec. says 4.7K or lower.. Might be the problem....

    Dave Purola,
    N8NTA
    I am using 4.7K. Sorry I forgot to mention that I was doing that different from the schematic I posted.

    Did you get it to work?

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