24LC512 I2C memory

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
JacquesC
Posts: 8
Joined: Sun Feb 17, 2019 5:04 am

24LC512 I2C memory

Post by JacquesC » Sat Dec 07, 2019 4:22 am

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

User avatar
pythoncoder
Posts: 4017
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 24LC512 I2C memory

Post by pythoncoder » Sun Dec 08, 2019 9:02 am

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.
Peter Hinch

User avatar
rcolistete
Posts: 187
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil

Re: 24LC512 I2C memory

Post by rcolistete » Sun Dec 08, 2019 1:18 pm


User avatar
JacquesC
Posts: 8
Joined: Sun Feb 17, 2019 5:04 am

Re: 24LC512 I2C memory

Post by JacquesC » Sun Dec 08, 2019 6:29 pm

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

User avatar
pythoncoder
Posts: 4017
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 24LC512 I2C memory

Post by pythoncoder » Mon Dec 09, 2019 11:18 am

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.
Peter Hinch

User avatar
pythoncoder
Posts: 4017
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 24LC512 I2C memory

Post by pythoncoder » 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!
Peter Hinch

User avatar
rcolistete
Posts: 187
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil

Re: 24LC512 I2C memory

Post by rcolistete » Wed Dec 11, 2019 8:21 pm

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 !!!

User avatar
JacquesC
Posts: 8
Joined: Sun Feb 17, 2019 5:04 am

Re: 24LC512 I2C memory

Post by JacquesC » Sun Dec 15, 2019 7:57 pm

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 !

User avatar
pythoncoder
Posts: 4017
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 24LC512 I2C memory

Post by pythoncoder » Mon Dec 16, 2019 9:25 am

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.
Peter Hinch

User avatar
JacquesC
Posts: 8
Joined: Sun Feb 17, 2019 5:04 am

Re: 24LC512 I2C memory

Post by JacquesC » Mon Dec 16, 2019 6:10 pm

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 ;)

Post Reply