EEPROM — pymcu.hal.eeprom#
from pymcu.hal.eeprom import EEPROM
Non-volatile byte storage using the internal EEPROM. EEPROM is a zero-cost @inline class —
all reads and writes compile to bare register-level sequences with no SRAM overhead.
Capacity by chip#
Chip |
Size |
Address range |
Write latency |
|---|---|---|---|
ATmega328P |
1024 bytes |
|
~3.4 ms |
ATmega2560 |
4096 bytes |
|
~3.4 ms |
ATmega32U4 |
1024 bytes |
|
~3.4 ms |
ATtiny85/45/25 |
512/256/128 bytes |
varies |
~3.4 ms |
Endurance: 100 000 write/erase cycles per cell. Data retention: 20+ years at 25 °C.
class EEPROM#
EEPROM()#
Creates an EEPROM handle. No registers are written at construction time.
Methods#
Method |
Signature |
Description |
|---|---|---|
|
|
Write one byte. Blocks ~3.4 ms for write to complete. |
|
|
Read one byte. Returns immediately. |
Example#
from pymcu.hal.eeprom import EEPROM
from pymcu.types import uint8, uint16
def main():
ee = EEPROM()
# Persist a calibration offset
ee.write(0x00, 42)
# Read it back after power cycle
cal: uint8 = ee.read(0x00)
Wear-leveling#
Each cell has a finite write endurance (~100 k cycles). For values that change frequently (counters, log entries), distribute writes across multiple addresses rather than hitting the same cell repeatedly.
ATmega328P register map#
Register |
Address |
Description |
|---|---|---|
|
|
EEPROM Address High |
|
|
EEPROM Address Low |
|
|
EEPROM Data Register |
|
|
EEPROM Control Register (EEPE, EEMPE, EERIE, EEPM) |