Read/Write uC internal memory

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Andrew1234
Posts: 20
Joined: Sat Oct 16, 2021 3:58 pm

Read/Write uC internal memory

Post by Andrew1234 » Mon Oct 25, 2021 12:55 pm

I want to write a value to the internal non-volatile memory of the uC, so it can be retrieved after a subsequent startup. I don't see a library function to do this in the quick reference guide for the pyboard.

For example, suppose I read a value from the ADC, and I use that value to set a volume control register in an external device using the I2C bus. I would like to recall that volume control setting after reset. I'm looking for a function to allow me to write the value to internal memory, so I can later read it back, to accomplish this.

Regards
Andy

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Read/Write uC internal memory

Post by Roberthh » Mon Oct 25, 2021 2:34 pm

AFAIK, such a function exists only in the form of writing the data to a file.

Andrew1234
Posts: 20
Joined: Sat Oct 16, 2021 3:58 pm

Re: Read/Write uC internal memory

Post by Andrew1234 » Mon Oct 25, 2021 4:24 pm

Thanks very much. I'll look into that idea further. Also my example doesn't make too much sense, since I can just read the ADC again on power-up. But the general question remains (if for example I used a pair of GPIOs to implement up-down buttons, and I want to recall the final volume setting). Another thought is I could have an external memory and read/write to it via I2C or SPI. But my preference would be to use the uC memory to avoid the extra IC.

Regards
Andy

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Read/Write uC internal memory

Post by dhylands » Mon Oct 25, 2021 7:12 pm

You didn't mention which board you're using.

There are functions available on some ports to make the RTC non-volatile memory accessible.

You'll need to add a backup battery in order for the memory to be retained across power cycles.

For the pyboard, see this post: viewtopic.php?f=6&t=7064&p=40196#p40196

Some ports have RTC.memory() (ESP8266 and ESP32) viewtopic.php?f=2&t=7013

Post Reply