AVR Internal EEPROM

EEPROM์€ ์ „๊ธฐ์  ์‹ ํ˜ธ๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์šฐ๊ณ  ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”๋ชจ๋ฆฌ์ž…๋‹ˆ๋‹ค. ATmega328p์˜ ๊ฒฝ์šฐ 1 KB ์‚ฌ์ด์ฆˆ์˜ EEPROM์„ ๋‚ด์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„ํœ˜๋ฐœ์„ฑ ๋ฉ”๋ชจ๋ฆฌ์ด๋ฏ€๋กœ ์ „์›์ด ์ธ๊ฐ€๋˜์ง€ ์•Š์•„๋„ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์„ค์ •์„ ์œ„ํ•ด ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์–ด์•ผ ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ๋•Œ ์ฃผ๋กœ ์“ฐ์ž…๋‹ˆ๋‹ค.

It is organized as a separate data space, in which single bytes can be read and written. The EEPROM has an endurance of at least 100,000 write/erase cycles

์“ฐ๊ธฐ์˜ ๊ฒฝ์šฐ 100,000 ๋ฒˆ์œผ๋กœ ํšŸ์ˆ˜๊ฐ€ ์ œํ•œ๋ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ๋•Œ, ์ง€์šฐ๊ณ  ์ €์žฅํ•˜๋Š” ๊ฒƒ(write) ๋ณด๋‹ค ์ €์žฅ๋œ ๊ฐ’์„ ํ™•์ธํ•˜๊ณ  ํ™•์ธ๋œ ๊ฐ’๊ณผ ๋น„๊ตํ•˜์—ฌ ๋‹ค๋ฅธ ๊ฒฝ์šฐ์—๋งŒ ์ง€์šฐ๊ณ  ์ €์žฅํ•˜๋Š” ๊ฒƒ(update)์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

<avr/eeprom.h>

read/update

eeprom_update_word((uint16_t *)0, (uint16_t)0x1234);
uint16_t var = eeprom_read_word((uint16_t *)0);
eeprom_update_word((uint16_t *)0, (uint16_t)-1234);
int16_t var = eeprom_read_word((uint16_t *)0);
info

AVR์€ Little Endian์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค. eeprom_update_word((uint16_t *)0, (uint16_t)0x1234)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 0 ๋ฒˆ ์ฃผ์†Œ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒฝ์šฐ, 0x34 ๊ฐ€ 0 ๋ฒˆ ์ฃผ์†Œ์—, 0x12 ๊ฐ€ 1 ๋ฒˆ ์ฃผ์†Œ์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

union {
uint64_t value;
uint8_t bytes[8];
} block;
block.value = 0x0102030405060708ULL;
eeprom_update_block((void *)block.bytes, (void *)0, 8);
uint64_t var;
eeprom_read_block((void *)&var, (void *)0, 8);

EEMEM

์ฃผ์†Œ๋ฅผ ์ง์ ‘ ์„ค์ •ํ•ด๊ฐ€๋ฉฐ EEPROM์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  ๊ฒƒ์„ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ์–ดํ•œ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๊ธฐ์–ตํ•˜๊ธฐ ์–ด๋ ต๊ณ , ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง‘๋‹ˆ๋‹ค. ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด EEMEM์„ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.

caution

ํ•ด๋‹น ๋ณ€์ˆ˜๋Š” ์ „์—ญ๋ณ€์ˆ˜๋‚˜ ์ง€์—ญ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ์ €์žฅ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ „์—ญ๋ณ€์ˆ˜๋‚˜ ์ง€์—ญ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

#include <avr/eeprom.h>
#include <avr/io.h>
EEMEM uint8_t set_state;
EEMEM int16_t set_a;
EEMEM uint16_t set_b;
int main(void) {
int16_t var_a = 0;
uint16_t var_b = 0;
if(eeprom_read_byte(&set_state) != 1) {
eeprom_update_word(&set_a, (uint16_t)-123);
eeprom_update_word(&set_b, (uint16_t)0x1234);
eeprom_update_byte(&set_state, (uint8_t)1);
} else {
var_a = eeprom_read_word(&set_a);
var_b = eeprom_read_word(&set_b);
}
while(1) {
}
}
Last updated on