Addressing I2C memory

Discuss the Firewing language

Addressing I2C memory

Postby skartalov » Wed Nov 06, 2013 4:20 pm

Hi,

I have connected 24LC32 I2C EEPROM , and can read and write, BUT address only 256 bytes of it.

I found that the I2C module has a one BYTE variable for addressing, I need the address to be two bytes long.

So how to address the whole 4096 bytes available in this chip?

Any help?
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: Addressing I2C memory

Postby David John Barker » Wed Nov 06, 2013 5:25 pm

I think the 24LC32 has just an 8 bit I2C address. You would typically send the 8 bit I2C address, followed by the data address high byte followed by the data address low byte - something like:

[i2c_address] [addr_byte1] [addr_byte0]
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Addressing I2C memory

Postby skartalov » Fri Nov 08, 2013 2:18 pm

I used the following for read write EEPROM:

Code: Select all
Public Sub i2cwrite (paddress As ushort, pdata As Byte)
    I2C.Start                         
    I2C.WriteByte(I2C_EEPROM)             
    I2C.WriteByte(paddress)           
    I2C.WriteByte(pdata)                 
    I2C.Stop
    DelayMS(10)
End Sub
Public Function i2cread (pAddress As ushort) As Byte
    I2C.Start
    I2C.WriteByte(I2C_EEPROM)
    I2C.WriteByte(paddress)             
    I2C.Restart                         
    I2C.WriteByte(I2C_EEPROM + 1)
    return I2C.ReadByte()
    I2C.Acknowledge(IsNotAcknowledge)
    I2C.Stop   
End Function


now I addes 2 bytes for address:

Code: Select all
Public Sub i2cwrite (paddress As ushort, pdata As Byte)
    I2C.Start                         
    I2C.WriteByte(I2C_EEPROM)             
    I2C.WriteByte(paddress.1)
    I2C.WriteByte(paddress.0)             
    I2C.WriteByte(pdata)                 
    I2C.Stop
    DelayMS(10)
End Sub
Public Function i2cread (pAddress As ushort) As Byte
    I2C.Start
    I2C.WriteByte(I2C_EEPROM)
    I2C.WriteByte(paddress.1)
    I2C.WriteByte(paddress.0)               
    I2C.Restart                         
    I2C.WriteByte(I2C_EEPROM + 1)
    return I2C.ReadByte()
    I2C.Acknowledge(IsNotAcknowledge)
    I2C.Stop   
End Function


In both cases I can address only the first 256 bytes of the memory, which is strange!
So how to address the whole memory? Any suggestions?

Also very weird, today I tried 24LC1025 (which is 128kb x 8bit EEPROM) -> It doesn't work at all! It has the same addressing mode as the 24LC32.... Hmmm.....

what else should I try ?!?
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: Addressing I2C memory

Postby David John Barker » Fri Nov 08, 2013 2:42 pm

There was something about this device on the Swordfish forum some time ago - similar problem. It's worth a read I think:

http://www.forum.sfcompiler.co.uk/viewtopic.php?t=146&view=previous&sid=a246661bece630409737ebe4d274dac0
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Addressing I2C memory

Postby skartalov » Fri Nov 08, 2013 3:26 pm

Thanks! After few modifications now I can address the whole 128kB in 24LC1025 EEPROM MEMORY.

This is the WORKING code:

Code: Select all
Public Sub i2cwrite (paddress As ushort, pdata As Byte)
    I2C.Start                         
    I2C.WriteByte(I2C_EEPROM)             
    I2C.WriteByte(paddress.byte1)
    I2C.WriteByte(paddress.byte0)             
    I2C.WriteByte(pdata)                 
    I2C.Stop
    i2c.waitforwrite(I2C_EEPROM)
End Sub

Public Function i2cread (paddress As ushort) As Byte
    I2C.Start
    I2C.WriteByte(I2C_EEPROM)
    I2C.WriteByte(paddress.byte1)
    I2C.WriteByte(paddress.byte0)               
    I2C.Restart                         
    I2C.WriteByte(I2C_EEPROM + 1)
    return I2C.ReadByte()
    I2C.Acknowledge(IsNotAcknowledge)
    I2C.Stop   
End Function
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: Addressing I2C memory

Postby David John Barker » Fri Nov 08, 2013 4:38 pm

Great stuff!! Thanks for sharing your working code :D
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest

x