I2C and 24LC512 memory devices
Hi, Can anyone help please?
I'm trying to interface a 24LC512 I2C eeprom to WiPy.
I think I have connected it fine. The "scan" command returns  which is correct. I've got 2K2 pullups on SDA and SCL and left WP floating (documented to be enabled for write like this as it has an internal pulldown) - and bypassed Vcc to gnd with 2 off 100nF - powered from 3V3 of the WiPy - and soldered leads.
I've tried the various commands and all I can read is 0xFF after write operations.
I am concerned that these memories require 3 bytes written for each access; the first byte is an A0 or an A1 for write or read command resp for the 1st chip on the bus. Then 2 address bytes. Then read a value back or write a value for storing into eeprom.
I note that a timing cycle can be initiated in that I get a bus error after a write operation unless I put in a delay - but the read operation still returns 0xff.
Anyone actually used I2C on a WiPy to read/write these serial eeproms please?
Any hints please?
Thanks - Richard
Thank you so much - it is surprising though.
I had got majorly confused with if the memory comand actually sent out the proper sequence or not etc. It seems it does.
I've been away with other things this last month or so (earning money). Now it is time to come back to it. I'll get the breadboard happening again shortly.
jmarcelino last edited by
I received the 24LC512 today and just had to do a quick test now before heading to bed :)
I adapted some existing EEPROM code to support the Pycom board and it all seems to be working very well, please have a look at my version:
I don't have time to package this into something better at the moment but can return to it later next week if no one else does it first :)
RichardTXD last edited by livius
Thank you so much for taking an interest and your effort.
Doesn't seem to change anything with same code.
I'm operating under the assumption that I need to manually send the leadin and addressing bytes for read and write.
As below. I tried a few variants but didn't get it working.
from machine import I2C import time # configure the I2C bus # i2c = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9', 'P10')) i2c = I2C(0, I2C.MASTER, baudrate=100000) print('scanning') print(i2c.scan()) # returns list of slave addresses, tells me chip is on the bus loops = 0 addressing = bytearray(3) addressing = 0xA0 # Write command, chip 0 on bus addressing = 0x00 # MSB address addressing = 0x00 # LSB address print(str(addressing)) i2c.writeto(80, addressing, stop=False) # setup chip, no stop means more to follow i2c.writeto(80, '123hello world456') # this should be a "page write" (assume) time.sleep(1) # crazy long. 5mS should be enough addressing = 0xA1 # make it a read command, chip 0 on bus while 1: i2c.writeto(80, addressing, stop=False) # setup chip, no stop means more to follow time.sleep(0.1) # not necessary. "try anything" result = i2c.readfrom(80, 32) # clock out 32 bytes in page mode (assume) print(str(loops) + ' ' + str(result)) time.sleep(1.0) loops = loops + 1
jmarcelino last edited by jmarcelino
Can you try the new firmware 1.7.5b2 and see if it solves the problem?
I ordered a 24LC512 should get it tomorrow to try as well.
jmarcelino last edited by
I only have old Atmel 24C32 EEPROMs in my parts bin, I mostly use much larger Cypress etc SPI NOR Flash or F-RAM, but I'll see if I can order some similar to yours and try it
Let us know if you get it working in the meantime.
Ta. Fair comment. Shouldn't be needed but I'll try it.
In the post on the new version of firmware it was suggested that the Python code does not send the proper lead in code to address a memory chip. It is just generic code which is guaranteed to fail.
The 24LC512's I use demand an A1 or A0 for read or write then the address then the data.
I read all the PyCom/Python doc I could find and assumed it was the same as Arduino Wire library which works.
A poster showed me a command variation that allows "stop" to be conditional which would allow exaclty what I need to create the correct addressing.
I'll try that tomorrow - gotta leave for the day.
Thanks for the comments and taking an interest. I've used I2C memory chips for last 18 years and quite like them. We've found them to be very robust and reliable and low current though capacity is low by modern standards and somewhat slow.
but what if you add
but i see that @jmarcelino found the reason of that? Post here findings :)
RichardTXD last edited by livius
The writing code is done in an Arduino app, fairly large, that I won't post. It is a work in progress. If you have the memory devices and an arduino I can send you something - it just uses the 'wire' library and does page writes etc.
This is the reading code. Absolutley nothing clever.
-----begin---------- from machine import I2C, UART import time # Configure 2nd uart port uart1 = UART(1, baudrate=19200) uart1.write('hello') # read up to 5 bytes # configure the I2C bus # i2c = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9', 'P10')) i2c = I2C(0, I2C.MASTER, baudrate=100000) print('scanning') print(i2c.scan()) # returns list of slave addresses loops = 0 while 1: result = i2c.readfrom_mem(80, 0, 32) print(str(loops) + ' ' + str(result)) # print(str(loops)) time.sleep(1.0) loops = loops + 1 # i2c.scan() uart1.write('hello') ------ end -----
can you post code used for init and read data from i2c?
because i use it extensively and no isssues with reading from memory. Example i2c memory of gps.
Updated to 1.7.4.b1 and made no difference.
Reading first 16 bytes of I2C occasionally works from power up. Thereafter a re-read returns rubbish.
Must power down the WiPy and retry to read I2C memory again.
Sorry false alarm.
The issue is NOT fixed.
The i2c.readfrom_mem command only works after power up then it fails every other time.
I'm using a pre-written serial eeprom - I can read it the first time after power up sometimes. There after it appears to be locked up or similar.
Spent hours on it.
Anyone played with I2c serial memroies please?????
Hi and thanks. I just now got round to working on this problem.
I changed the resistors - no change in operation - always returning 0ffh.
I FOUND IT... on the WiPy2 expansion board, I've not seen the circuit, but I think maybe there is something else connected to the I2C pins(?) I pulled the links for Led and Chg and Batt and all of a sudden I could read the I2C memory chip I'd written on something else.
It was something on the expansion board.
Thanks for the help - Richard
2K2 pullups can be too strong try with 10K or 4K7.