peterhinch / micropython_eeprom

MicroPython device drivers for memory chips (EEPROM, FRAM, Flash, SPIRAM)
MIT License
73 stars 33 forks source link

when the dictionary is too large, write data incorrectly #7

Closed QQWE1345 closed 3 years ago

QQWE1345 commented 3 years ago

QQPCRealTimeSpeedup_rzpIKJHr9Y

I encountered this problem in use, when the dictionary is too large, write data incorrectly

QQWE1345 commented 3 years ago

below is the code:

d = {0: '', 1: '{G0001#000P0500T9000!#001P0996T0995!}', 2: '{G0002#000P0500T9000!#001P0996T0995!}', \ 3: '{G0002#000P0500T9000!#001P0996T0995!}', 4: '{G0002#000P0500T9000!#001P0996T0995!}', 5: '{G0002#000P0500T9000!#001P0996T0995!}'} wdata = ujson.dumps(d).encode('utf8') sl = '{:10d}'.format(len(wdata)).encode('utf8') eep[0 : len(sl)] = sl # Save data length in locations 0-9

print(eep[:10])

start = 128 # Data goes in 10: end = start + len(wdata) print(start," ",end) eep[start : end] = wdata print(wdata) print(eep[start : end])

pyb.delay(300)

slenx = int(eep[:10].decode().strip()) # retrieve object size

startx = 128

endx = startx + slenx

dx = ujson.loads(eep[startx : endx])

print(dx)

peterhinch commented 3 years ago

You are running very old firmware - the first thing I would do is update to V1.15 and repeat.

Have you run the tests in the test program to check your hardware? You may have no need of the filesystem test but I would definitely run full_test as it is thorough and would definitely expose an error of the type seen. What EEPROM chip are you using?

It seems to be behaving as if the data were written at a start location of 64 rather than 128, so that when you display data at [128:end] you are missing the first 64 bytes. It would be worth checking if the data at [64:129] matches this theory. I can't explain this at all, given that the same method is used for reading and writing.

QQWE1345 commented 3 years ago

Thank you very much for your reply. I will adjust the firmware version and test it again

QQWE1345 commented 3 years ago

20210510121714

with V1.15 I get the result above, eeprom missing data 0-36 my chip is AT24C256

QQWE1345 commented 3 years ago

It seems that My chip only supports writing 64 bytes at a time, my fault thank you very much :)

20210510125212

peterhinch commented 3 years ago

The 128 byte page size is hard coded in the driver. While you could change this, it might be easier just to buy one of the supported chips. Good luck with whatever you decide to do.

QQWE1345 commented 3 years ago

with my chip , just change 128 to 64 in full_test() and everyyhing will be ok

peterhinch commented 3 years ago

I'm not sure this is true. Look at this method. It needs proper analysis and unfortunately I haven't the time to do this at the moment,