Implement AVR328 EEPROM handling

This commit is contained in:
2025-10-01 00:08:25 +02:00
parent 5cce419c74
commit 2e6fe9ba6b
2 changed files with 35 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
#ifndef EEPROM_H
#define EEPROM_H
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "config.h"
uint8_t eepromRead(uint8_t address);
void eepromWrite(uint8_t address, uint8_t data);
+25
View File
@@ -0,0 +1,25 @@
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "config.h"
uint8_t eepromRead(uint8_t address) {
// wait for previous write
while (EECR & (1 << EEPE));
//read from address
EEAR = address;
return EECR |= (1 << EERE);
}
void eepromWrite(uint8_t address, uint8_t data) {
// wait for previous write
while (EECR & (1 << EEPE));
//write to address
EEAR = address;
EEDR = data;
EECR |= (1 << EEMPE);
EECR |= (1 << EEPE);
}