Wednesday, 15 June 2011

Reading and Writing to internal EEPROM of Atmega32


EEPROM is Electrically erasable programmable ROM.Thus on storing any data or program on eeprom does not get lost even after the power is turned of as in case of static RAM.

Atmega32 has 1024 bytes of EEPROM and has a durability of 100,000 write cylces and infinte read cycles.
My program is based on an excellent tutorial i found on AVR freak which is here.

It is a very straightforward implementation of the tutotrial on avr freaks.

Writing to EEPROM is done either in bytes, words or blocks.

Writing in bytes

#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <stdio.h>
#include "LCD.h"
int main()
{
lcd_init();
uint8_t ByteOfData = 12;
eeprom_write_byte((uint8_t*)46,51);
ByteOfData = eeprom_read_byte((uint8_t*)46);
_delay_ms(10);
lcd_char((char)ByteOfData);
return 0;
}
view raw eepromRW.c hosted with ❤ by GitHub

Similarly writing a string to EEPROM

#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <stdio.h>
#include "LCD.h"
int main()
{
char stringOfData[6];
char stringOfReadData[6];
lcd_init();
sprintf(stringOfData,"hello");
eeprom_write_block((const void*)1,&stringOfData,6);
eeprom_read_block(&stringOfReadData,(const void*)1,4);
_delay_ms(10);
lcd_string_array((char *)stringOfData);
return 0;
}








3 comments:

Alfred Erian said...

I think you just printed the original variable on the LCD.
lcd_string_array((char *)stringOfData);
instead of
lcd_string_array((char *)stringOfReadData);
you meant to print the read variable from EEPROM right?

jayavelu said...

update function works fine in main loop but within while with a if condition, its not working....

jayavelu said...

Thanks for your nice tutorial....

Post a Comment

Popular Posts