2023-02-02 01:59 AM
2023-02-02 04:57 AM
If the rotary encoder is processed by the MCU and update a global variable (like the volume level of a car radio), and you want to keep the position value when restarting the code (power up or reset and rerun the app in debug mode), the easiest would be to store the value in an EEPROM such as M24128. Writing will take 5 msec max for a multi-write byte update using I2C bus (even just using GPIO using I2C Bitbang)
An example for STM32C0 can be found here.
Then, once optimisation (cost) becomes important, you might try to use embedded MCU flash sectors to emulate to some point the external EEPROM. One step at a time.