EEPROMs

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: EEPROMs

Re: EEPROMs

by Electroguard » Mon May 27, 2024 1:04 pm

Ok, I'll need to take a deeper look when I can, Francesco, cos I thought you were just hard-coding multiple short strings to specified locations.

Busy trying to create an espnow range extender at the moment: sensor sending to relay1, which forwards to relay2, etc, ... until reach receiver.
Only isolated point to point coms needed at any device, and hopefully espnow power requirements will be less than wifi, so solar battery may be more viable.

PS. I'm confident that Annex will be around for at least as long as we are, which hopefully will be for a while longer yet.

Re: EEPROMs

by cicciocb » Mon May 27, 2024 12:16 pm

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun May 26, 2024 8:56 pm Electroguard,

It is true that EEPROM is somewhat more robust than FLASH memory.
See data sheet.

2-Wire
Serial EEPROM
32K (4096 x 8)
64K (8192 x 8)
AT24C32
AT24C64

Features
• Low-Voltage and Standard-Voltage Operation
– 2.7 (V CC = 2.7V to 5.5V)
– 1.8 (V CC = 1.8V to 5.5V)
• Low-Power Devices (I SB = 2 μA at 5.5V) Available
• Internally Organized 4096 x 8, 8192 x 8
• 2-Wire Serial Interface
• Schmitt Trigger, Filtered Inputs for Noise Suppression
• Bidirectional Data Transfer Protocol
• 100 kHz (1.8V, 2.5V, 2.7V) and 400 kHz (5V) Clock Rate
• Write Protect Pin for Hardware Data Protection
• 32-Byte Page Write Mode (Partial Page Writes Allowed)
• Self-Timed Write Cycle (10 ms max)
• High Reliability
– Endurance: 1 Million Write Cycles
– Data Retention: 100 Years
• Automotive Grade and Extended Temperature Devices Available
• 8-Pin JEDEC PDIP, 8-Pin JEDEC SOIC, 8-Pin EIAJ SOIC,
and 8-pin TSSOP Packages


SPI FLASH
W25Q16RV

Features
Highest Performance Serial Flash
– 133MHz Single, Dual/Quad SPI clocks
– 266/532MHz equivalent Dual/Quad SPI
– 66MB/S continuous data transfer rate
– Min. 100K Program-Erase cycles
– More than 20-year data retention

Jan
I would be very happy if Annex will be still alive in 2044 :-)

Re: EEPROMs

by cicciocb » Mon May 27, 2024 12:12 pm

Robin, the routine I published already does what you want. You can write messages of any length, 32 is just a parameter of the eeprom, not the size of the messages. The separator is the character 255

Re: EEPROMs

by Electroguard » Mon May 27, 2024 11:42 am

Yeah Jan, is no doubt an eeprom could be good for safe data, especially in event of entire Annex firmware and file system being lost or overwritten.

Now that Francesco has provided us with the mechanism, we still need to do more to make the most of it though, so I've been giving it some thought.
Ideally we should be able to save any length string (up to max eeprom size), so will need a chopper subroutine loop that keeps slicing the string into 32 byte chunks to send to the writer function, then finally adding an EOF character to the last chunk.

Needs a corresponding combiner subroutine loop to keep reading in 32 byte mouthfuls from the reader function and concatenating them into a string until it reaches the EOF character.

This will allow strings larger than 32 bytes (eg: large /path/filenames) to be saved and read back when needed.

But it is only a relatively minor extra step to be able to write/read a large string comprised of several smaller strings, which would allow it to cope with eg: a config file string containing several smaller parameter=data string pairs, which is easily done using word.getpar$ etc.
This would mean that each smaller string would require a string terminator as separator.
So I was thinking of using chr$(10) as the string terminator (separator) character, and chr$(13) as EOF marker.

All easy enough so far, just a matter of somehow linking to Francesco's functions to make them keep being stepped up as needed until EOF is reached.
Only thoughts at the moment though, cos have several bigger priorities to attend to first.

Re: EEPROMs

by Jan Volk » Sun May 26, 2024 8:56 pm

Electroguard,

It is true that EEPROM is somewhat more robust than FLASH memory.
See data sheet.

2-Wire
Serial EEPROM
32K (4096 x 8)
64K (8192 x 8)
AT24C32
AT24C64

Features
• Low-Voltage and Standard-Voltage Operation
– 2.7 (V CC = 2.7V to 5.5V)
– 1.8 (V CC = 1.8V to 5.5V)
• Low-Power Devices (I SB = 2 μA at 5.5V) Available
• Internally Organized 4096 x 8, 8192 x 8
• 2-Wire Serial Interface
• Schmitt Trigger, Filtered Inputs for Noise Suppression
• Bidirectional Data Transfer Protocol
• 100 kHz (1.8V, 2.5V, 2.7V) and 400 kHz (5V) Clock Rate
• Write Protect Pin for Hardware Data Protection
• 32-Byte Page Write Mode (Partial Page Writes Allowed)
• Self-Timed Write Cycle (10 ms max)
• High Reliability
– Endurance: 1 Million Write Cycles
– Data Retention: 100 Years
• Automotive Grade and Extended Temperature Devices Available
• 8-Pin JEDEC PDIP, 8-Pin JEDEC SOIC, 8-Pin EIAJ SOIC,
and 8-pin TSSOP Packages


SPI FLASH
W25Q16RV

Features
Highest Performance Serial Flash
– 133MHz Single, Dual/Quad SPI clocks
– 266/532MHz equivalent Dual/Quad SPI
– 66MB/S continuous data transfer rate
– Min. 100K Program-Erase cycles
– More than 20-year data retention

Jan

Re: EEPROMs

by Electroguard » Sat May 25, 2024 10:08 pm

Yep, works well for me too on this old module I had laying around.
Less convenient to use than BAS.RTCMEM$, but a lot more dependable.

eeprom.jpg

Re: EEPROMs

by Jan Volk » Sat May 25, 2024 9:37 pm

Francesco,

Wow.
This is a simple subroutine for writing and reading to an external I2C EEPROM. Thank you.
Tested this and it works perfectly.
First scan the correct address, otherwise the connection will stop with an error for no reason.
My default address is $h57 (A0, A1, A2 open)
The DS3231 RTC time works well for me.

So now one can include this sub in a control by first checking whether 255 is in the first memory during automatic start-up and then writing a standard list with good control values ​​to the EEPROM.
You can adjust this later from the program.

Jan

Re: EEPROMs

by Electroguard » Sat May 25, 2024 6:34 pm

As a matter of interest, do you know if the Annex RTC functions still work with that TinyRTC module ?

Re: EEPROMs

by Electroguard » Sat May 25, 2024 4:04 pm

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

Re: EEPROMs

by cicciocb » Sat May 25, 2024 3:30 pm

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


Top