EEPROMs

If doesn't fit into any other category ....
User avatar
Electroguard
Posts: 945
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 times

EEPROMs

Post by Electroguard »

Have you done anything with EEPROMs, Francesco ?

The only thing I can find was an old post by Theo which I saved from the old forum before it got lost...
Reading and writing I2C ram and eeprom: [Local Link Removed for Guests]
Don't know if it's possible, but would be nice to eventually write and read cheap non-volatile EEPROM as string variables (alternative to volatile BAS.RTCMEM$)

non-volatile memory.jpg

eeprom4.jpg
Fixed address, but ridiculously cheap: https://www.aliexpress.com/item/1005005 ... ry_from%3A

eeprom3.jpg
Price shown for 5 addressable modules with write-protect: https://www.aliexpress.com/item/100500 ... ry_from%3A
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2194
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: EEPROMs

Post by cicciocb »

Yes, it should not be hard to implement, even if this can be done internally without using any external eeprom simply writing into a file :D
Jan Volk
Posts: 107
Joined: Wed Mar 03, 2021 1:35 pm
Been thanked: 34 times

Re: EEPROMs

Post by Jan Volk »

I once wrote a climate control (ventilation windows) for a hobby greenhouse with BascomAVR and an Arduino nano and wrote the settings and offsets to an eeprom and after a power failure I retrieved them and continued to regulate with workable values, which has been going on for 8 years now. use.
It would be nice if I could access an external eeprom from Annex32?

Jan
User avatar
cicciocb
Site Admin
Posts: 2194
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: EEPROMs

Post by cicciocb »

As I said should not be hard to implement but what is the advantage to store into an eeprom compared to store internally in the module?

Does someone could show me the advantage?
Jan Volk
Posts: 107
Joined: Wed Mar 03, 2021 1:35 pm
Been thanked: 34 times

Re: EEPROMs

Post by Jan Volk »

In the past, fixed storage was only possible with EEPROM or with a backup battery on the RAM memory.
Now flash memory has taken over this role. The only thing I can think of is that if the program crashes and has to be flashed again and the storage flash has also been deleted, one can fall back on the old settings and the adjustment parameters in the eeprom.
Can the eeprom on a DS3231 RTC module also be used for access codes and passwords or other settings that can be lost during flashing?

Jan
User avatar
Electroguard
Posts: 945
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 times

Re: EEPROMs

Post by Electroguard »

As you say Francesco, the filename can be stored to file.
I do remember using such a 'config' file for quite a while.
It was mostly on 1Mb Sonoffs at that time, which didn't seem to like it, cos out of about a dozen, I don''t have any that still work.
That's why I'm having to develop new remote switches using some old electro-dragons and various other esp relays.
I just feel that EEPROM data is likely to outlive any ESP file data.
But yeah, saving to file is the quick and easy option.
And I have recently been thinking about using a config file again, so maybe it's time to revisit... and should be easy enough to upgrade to EEPROM$ if it ever becomes an alternative to BAS.RTCMEM$.

BTW - Out of the many LFS firmware upgrades I've done this year, most have been ok, but about 4 or 5 times there were problems which needed re-doing the LFS partition, therefore losing all contents. And of course 8266's file contents are always lost now cos the Online Flasher does not have the Toolkit's Firmware Update option.
Not problems, just some feedback.


Edit: Yeah Jan, was looking earlier at RTC memory not sure about DS3231, but DS1307 definitely has some available, don't know if the Annex arduino RTC drivers can access it though.
User avatar
Electroguard
Posts: 945
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 times

Re: EEPROMs

Post by Electroguard »

eeprom4.jpg

The only possible advantage I can see for having smaller capacities is that their write sequence would take less time.
But I wouldn't have thought it mandatory to sequence through all addresses.
So if the contents were of a variable length string$ for example, then presumably only the addresses up to and including the string termination character would actually need to be written, allowing quicker write times for shorter strings.
So it would seem to be a case of biggest is best, but maybe I am missing something.
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2194
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: EEPROMs

Post by cicciocb »

The eeproms are quite slow, in particular for writing as the process is based on erase / write cycles.
In addition, the interface is I2C that is also slow so I suppose that it will take several seconds for writing, depending on the size of the message to write.
User avatar
cicciocb
Site Admin
Posts: 2194
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: EEPROMs

Post by cicciocb »

Hi all,
I played a little bit with the EEPROM present on this RTC module:
image.png
The goal was to integrate the EEPROM functions directly into Annex, but I found it easier to write a small library directly with Annex. To my surprise, it works well and quite fast.

The EEPROM installed on this module is a 24C32, which has 4 KB of capacity—more than enough to store configuration parameters and other data. Any EEPROM size should be supported. The buffer size could probably be optimized for specific EEPROMs, but I think 32 bytes should work for any size.

In any case, using a larger EEPROM is not justified, as you can always save large strings to files in the ESP32 internal flash memory or on an SD card.

Below is a small "library" that contains the basic "write_eeprom " and "read_eeprom " routines. The program is self-explanatory: you simply write a string to a specific address and can read back the string from this address.

Code: [Local Link Removed for Guests]

'library for reading / writing to eeproms
'this library works with a athyc532 
'that is a 24C32N with 32 bytes page write mode. 
'This eeprom can be found on the cheap RTC / EEprom modules
I2C.SETUP 47,21   'Pins as shown
EE_ADDR = &h50 'I2C address of the eeprom

'write at several address
write_eeprom 0, "Annex32 RDS"
write_eeprom 100, "Stored"
write_eeprom 200, "Into"
write_eeprom 300, "External"
write_eeprom 400, "EEprom"

'and read back from the eeprom
r$ =""
read_eeprom 0, r$
wlog r$
read_eeprom 100, r$
wlog r$
read_eeprom 200, r$
wlog r$
read_eeprom 300, r$
wlog r$
read_eeprom 400, r$
wlog r$
end

'==============================================================
'write an eeprom using pages of 32 bytes, and 5ms of write time
'use a buffer of 32 bytes (this is function of the eeprom)
'==============================================================
sub write_eeprom(address, msg$)
  local k, z, ad, le, bk, ofs, m$
  local buf_size
  buf_size = 32
  m$ = msg$ + chr$(255)
  le = len(m$)
  'write the first block that could not be aligned
  ofs = address mod buf_size
  bk = buf_size - ofs
  i2c.begin EE_ADDR
  ad = address
  i2c.write ad >> 8
  i2c.write ad and 255
  for z=1 to bk
      i2c.write asc(mid$(m$, z, 1))
  next z
  le = le - bk
  i2c.end
  pause 5 ' time for writing
  'write the remaining part of the message    
  k = 1
  while le > 0
    i2c.begin EE_ADDR
    ad = k*buf_size + (address and (65536 - buf_size))
    i2c.write ad >> 8
    i2c.write ad and 255
    if (le > buf_size) then bk = buf_size else bk = le
    for z=1 to bk
      i2c.write asc(mid$(m$, z + k*buf_size - ofs, 1))
    next z
    le = le - buf_size
    i2c.end
    'print "writing block "; k
    pause 5 ' time for writing
    k = k + 1
  wend
end sub

'==============================================================
'read from an external eeprom
' consider the eeprom of max 4096 bytes
'==============================================================
sub read_eeprom(address, msg$)
  local k, z, ad, le, bk, c
  msg$=""
  le = 4096 'size max (in bytes) of the eeprom
  i2c.begin EE_ADDR
  i2c.write address >> 8
  i2c.write address and 255
  i2c.end
  for k = 0 to int(le/128)
    if (le > 128) then bk = 128 else bk = le
    i2c.reqfrom EE_ADDR, bk
    for z=1 to bk
      c = i2c.read
      if c <> 255 then
        msg$ = msg$ + chr$(c)
      else 'exit from the loops
        k = 9999
        z = 9999
      end if
    next z
    le = le - 128
  next k
  i2c.end
end sub

You do not have the required permissions to view the files attached to this post.
User avatar
Electroguard
Posts: 945
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 times

Re: EEPROMs

Post by Electroguard »

Thank you very much, Francesco - hopefully I should receive some modules to test with before long.
Post Reply