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


Results 1 to 37 of 37

Threaded View

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

    Thumbs up Finally got it to work!!!

    First and foremost Thank You, Thank You, Thank You for all of your help guys I really do appreciate it.

    Here is the working Code:
    Code:
    ' Define serial output pin
    SO      con     0 
    
    ' Define serial mode                          
    T2400   con     0                           
    
    ' 2 Byte Address Vars
    addr1   var     word                       
    addr2   var     word                       
    addr3   var     word                        
    
    ' Vars for data being written
    D1      Var     Byte                        
    D2      Var     Byte                      
    D3      Var     Byte                        
    
    ' Vars for data being read
    B1      VAR     BYTE                       
    B2      VAR     BYTE                       
    B3      VAR     BYTE                        
    
    ' Set Data Bytes
    D1 = 7                                      
    D2 = 6
    D3 = 5
    
    ' Set Address Bytes
    addr1 = 1
    addr2 = 2
    addr3 = 3
    
    I2CWRITE PORTB.1,PORTB.4,$A0,addr1,[D1]      ' Write a 1 to address 1
    PAUSE 10                                     ' Wait 10ms for write to complete
    I2CWRITE PORTB.1,PORTB.4,$A0,addr2,[D2]      ' Write a 2 to address 2
    PAUSE 10                                     ' Wait 10ms for write to complete
    I2CWRITE PORTB.1,PORTB.4,$A0,addr3,[D3]      ' Write a 3 to address 3
    PAUSE 10                                     ' Wait 10ms for write to complete
    
    I2CREAD PORTB.1,PORTB.4,$A0,addr1,[B1]      ' Read address 1 into B1
    I2CREAD PORTB.1,PORTB.4,$A0,addr2,[B2]      ' Read address 2 into B2
    I2CREAD PORTB.1,PORTB.4,$A0,addr3,[B3]      ' Read address 3 into B3
    
    Serout SO,T2400,["Addr",#addr1,":",#B1," and then Addr",#addr2,":",#B2," and then Addr",#addr3,":",#B3,13,10] ' Print B1's Value in DEC
    and it's out putting this to Hyperterm:
    Code:
    Addr1:7 and then Addr2:6 and then Addr3:5
    Addr1:7 and then Addr2:6 and then Addr3:5
    Addr1:7 and then Addr2:6 and then Addr3:5
    The problem I had in the beginning was I had the SDA/SCL Pins wrong and I did not have the A2 pin Tied to +5V but after correcting those I had my control byte misunderstood and thats why it would not work. After changing the control byte back to $A0 with the A2 held High and the propper pins chosen for SDA and SCL it now works like it should.

    I hope this thread saves everyone a ton of time in the future with these chips I know I sure learned a ton from this little experiance
    Last edited by wolwil; - 26th April 2010 at 00:58.

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