EEPROM

Want to write a value so that you can access it if the microchip loses power and restarts? Write it to EEPROM!

The Attiny 24/44/84 family have 128/256/512 Bytes of In-System Programmable EEPROM, so it’s not enormous…

The avr/eeprom.h code is from avr-libc, a Standard C library for AVR-GCC. Here’s a link to the library:(https://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html)

The coolest thing about this code is seeing what you have written to EEPROM in AVR Studio’s EEPROM viewer when you’re in Debug Mode.


/*
 * Attiny84 EEPROM.c
 *
 * Created: 2/5/2019 2:18:28 PM
 * Author : FablabDigiscope
 */

#include <avr/io.h>
#include <avr/eeprom.h>

int main(void)
{

    while (1)
    {
		uint8_t hello[] = "Wow this is really cool!";
		eeprom_write_block (hello, (void*)0x00AA, sizeof (hello)); // structure: void eeprom_write_block (const void *__src, void *__dst, size_t __n)
    }
}

Atmel’s instructional videos on EEPROM on Youtube were helpful for this code.