- Wed Mar 23, 2022 6:48 am
#94057
JPM06 wrote:Hello, everybody,
I am trying to use the <EEPROM.h> library on an ESP-01, without any success.
My program runs fine on a NodeMCU/ESP12, but on the ESP-01 the data is read as 0 ( not FF!) at each reset or restart.
Is there any mean to write directly in the memory, without using that library? I have to store and retrieve a single byte.
Thanks for any help on the subject.
I'll write this as if you're a beginner (for future searchers) although I think you are more advanced.
Before jumping off to roll your own flash memory routines...
CHECKI know the EEPROM library works fine on a 1MB ESP-01. I just looked in my pile and don't have one of the 512K versions to check, but I would think it should work as it was written when the 512K units were the most common ones out there. Looking at the EEPROM code, it should work for the 512K versions as well. Are you sure you're using the correct
Flash Size setting?
Untitled.png
OTHER LIBRARIESThere may be libraries on the Arduino Library Manager that might help you... I can't really make a suggestion. I wrote my own for
InqPortal.
IF YOU JUST WANT TO MESS WITH FLASH FOR FUNFlash isn't as easy as memory! You can't just save and re-save just one byte. First you have to allocate an entire 4KB sector. This is because to re-write, you must erase first, and you can only erase a whole sector.
- You need to get the Espressif documentation
- #include <spi_flash.h>
- Functions you'll need are spi_flash_erase_sector, spi_flash_write and spi_flash_read.
- You need to pick a sector to work in. EEPROM uses the 4th from the end. Therefore it changes for every memory configuration 512KB, 1MB, 4MB, 16MB. So if you are using a 512K ESP-01, you'd use sector = (512KB / 4KB) - 5 = sector 123.
- You should spi_flash_erase_sector the very first install of your Sketch.
- Use spi_flash_write to write your data.
- Next time you boot up use spi_flash_read to get your value.
- Before you write a changed value, you'll need to spi_flash_erase_sector again.
- Then spi_flash_write to write your data again.
- And just to make it just that bit more "fun", the read and write methods use memory offsets instead of sectors.
- All big fun!
Good Luck,
InqP.S. In this context: Fun = self abuse.
You do not have the required permissions to view the files attached to this post.