Micropython EEPROM write error

david191624
Posts: 1
Joined: Fri Dec 01, 2017 7:19 am

Micropython EEPROM write error

Postby david191624 » Fri Dec 01, 2017 7:29 am

Dear ,

I am trying to write a simple program to test my I2C EEPROM(24LC01BI_SN), i use micropython to write 0 to 100 into EEPROM address from 0 to 100,
after write success. I read back and check back the value , the value is incorrect in some address. E.g. address 10 should be contain 0x0a, but the result is 0x0b and in address 0x0c the value is "r " :( .... may i know that how to fix this problem?




import machine
import time

addr =0
buf[0] = 0

while buf[0]<100:
... buf[0]=buf[0]+1
... ee.writeto_mem(80, addr, buf)
... time.sleep_ms(500)
... addr=addr+1

ee.readfrom_mem(80, 10, 10)

>>>>>b'\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14'

ee.readfrom_mem(80, 5, 10)

>>>>>b'\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Micropython EEPROM write error

Postby ESP_Sprite » Fri Dec 01, 2017 8:13 am

The code does exactly what you tell it to do. You set buf[0] and addr to 0. Then you enter the while loop and add 1 to buf[0], which is now 1, You write that to addr, which is still 0. Then you increase addr by 1, so it is now 1. The while loop restarts and you again add 1 to buff[0], which is now 2. You write that 2 to address addr, which still is 1. Etc. So essentially, you write 1,2,3,4,5,6... to the memory.

Now wrt the print: notice it says /r, not just r. This is an escape code, and if you look it up in an ascii table, you can see that it corresponds to ascii character 13.

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 75 guests