Page 1 of 2

24LC512 I2C memory

Posted: Sat Dec 07, 2019 4:22 am
by JacquesC
Hello,
does somebody used an I2C memory like a 24LC256 or I2C512 ?
Each time I try to write at any adress, I always read the same value :

Code: Select all

# I2C Memory : 24LC512
# Wired : A0, A1, A2 and WP to Vss (GND)
#         4k7 pullup resistors to Vdd (3.3V) on SCL and SDA pins
# The I2C memory response '80' to a i2c.scan()

from machine import Pin, I2C
from time import sleep_ms

I2C_BUS = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)

# Address in the 24LC512 where I try to read/write some data
adress_stock = 0x10 
print("Adress R/W : ", adress_stock)

# Is there something before I try to write ?
print("Read before : ", I2C_BUS.readfrom_mem(80, adress_stock, 4 ) )
sleep_ms(10)

# Try to write '0x1234' in the memory at 0x10 adress
val = b'1234'
print("try to write : ", val )
I2C_BUS.writeto_mem(80, adress_stock, val)
sleep_ms(10)

# Does the memory received and stocked the information ?
print("verify : ", I2C_BUS.readfrom_mem(80, adress_stock, 4) )
But I always have the same result :
>>> %Run -c $EDITOR_CONTENT
Adress R/W : 16
Read before : b'\xff\xff\xff\xff'
try to write : b'1234'
verify : b'\x00\x00\x00\x00'
>>>

If somebody have an idea I will be grateful ;)
Jacques

Re: 24LC512 I2C memory

Posted: Sun Dec 08, 2019 9:02 am
by pythoncoder
This device is an EEPROM chip: accessing it is rather more involved than what you are trying to do. You need to find (or write) a MicroPython device driver for the chip. It's a day or two's work if you've done this kind of thing before: maybe someone has already written one. If you look at the datasheet you will get some idea of what is involved.

An alternative would be to use an FRAM module where a driver already exists.

Re: 24LC512 I2C memory

Posted: Sun Dec 08, 2019 1:18 pm
by rcolistete

Re: 24LC512 I2C memory

Posted: Sun Dec 08, 2019 6:29 pm
by JacquesC
Thanks a lot for your answers.
I will have a look next week. I haven't got the choice, I have to find a solution, the eeprom is soldered on the board :roll: and I bought about twenty :?
I will come back soon
Jacques

Re: 24LC512 I2C memory

Posted: Mon Dec 09, 2019 11:18 am
by pythoncoder
From a quick look, that driver should work. It dates from the early days of MicroPython: we've learned a bit about optimising MicroPython code over the last five years so it could be improved. It is slow with a 50ms delay after each write. It's also Pyboard-specific, though that should be easy to fix.

Re: 24LC512 I2C memory

Posted: Wed Dec 11, 2019 9:38 am
by pythoncoder
I figured I could improve that driver quite substantially so I wrote this one. The docs list the advantages. Enjoy!

Re: 24LC512 I2C memory

Posted: Wed Dec 11, 2019 8:21 pm
by rcolistete
pythoncoder wrote:
Wed Dec 11, 2019 9:38 am
I figured I could improve that driver quite substantially so I wrote this one. The docs list the advantages. Enjoy!
Bravo !!!

Re: 24LC512 I2C memory

Posted: Sun Dec 15, 2019 7:57 pm
by JacquesC
Many many Thanks Peter, you are a BOSS !!!
What a great job !
Please, send me a post adresse in private message to send you chocolates ;-)
I haven't others words than BRAVO !

Re: 24LC512 I2C memory

Posted: Mon Dec 16, 2019 9:25 am
by pythoncoder
Thank you ;) Keep an eye on my repo as I'm still working on it - but rest assured the driver for your chip has been pretty thoroughly tested.

My aim for the repo is to support a variety of bit-addressable nonvolatile memory devices with a common base class and a common API. So my rather old FRAM driver is being rewritten and moved to this repo. I'm also supporting an SPI EEPROM which has much faster read access than the I2C ones.

Re: 24LC512 I2C memory

Posted: Mon Dec 16, 2019 6:10 pm
by JacquesC
Since last month I didn't knew FRAM memory that is why I have chosen an eeprom memory until a FRAM one.
But with your driver it is not a problem now every thing works perfectly ;)

Your work on the FRAM memory is so interressing that I have ordered some of them :
FM24CL16-G FM24CL16 sop-8 16Kb FRAM Serial 3V Memory. I hope I will be able to fond time and and try to use them.

Be sure Peter I will have a look at your repo ;)