Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in programming inbuilt EEPROM of ATMEGA2560

Status
Not open for further replies.

mythrikalam

Newbie level 6
Joined
Oct 4, 2010
Messages
14
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
INDIA
Activity points
1,398
The Flash memory of ATMega2560-STK600 is fully utilized with the project we are working on, still we need to store some data. So, i need to make use of the inbuilt EEPROM and then go for the external EEPROM depending on the requirement. But, i dont know how to write data on to the inbuilt EEPROM, can anyone help me in this regard and if anyone have an example program working with the inbuilt EEPROM, kindly feel free to post me so that i can better understand.

I have written a program in avr-gcc to write/read data to the inbuilt eeprom, but when i tried to program the eeprom in the program tab of the STK600 IN JTAG MODE OF ATMEGA2560, i had an error that the hex file for the eeprom is empty. but i had compiled the program with zero errors and the program had been build/rebuild to create the hex file. so, in this regard can anyone help me how to program inbuilt eeprom of atmega2560

My problem is HOW MICROCONTROLLER CAN BE PROGRAMMED WITH THAT PROGRAM USING .eep FILE?

when i tried to program the microcontroller, as i already stated, i had an error that

THE INTEL HEX INPUT FILE IS EMPTY

how to overcome this problem and program the inbuilt eeprom?
 

Do you see an eep file created next to the hex file?
If it is there open it with a text editor, is it filled with data?
I assume that you have stored some variable values to the eeprom or messages for a display.
I use avrdude with AVR BURN-o-mat front end and there are two separate fields in the program, one for the hex and one for the eep.
I use the usbasp programmer and i have also used stk200, these aro both ISP,i don't know what is different in your jtag programmer.

If your problem it to actually write the eeprom values in the c program then you can use the following defines i have made to make read/write operations in the internal eeprom easier
Code:
// defines for eeprom access	#include <avr/eeprom.h>
#define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address)
#define write_eeprom_byte(address,value) eeprom_write_byte ((uint8_t*)address,(uint8_t)value)
#define read_eeprom_word(address) eeprom_read_word ((const uint16_t*)address)
#define write_eeprom_word(address,value) eeprom_write_word ((uint16_t*)address,(uint16_t)value)
#define read_eeprom_dword(address) eeprom_read_dword ((const uint32_t*)address)
#define write_eeprom_dword(address,value) eeprom_write_dword ((uint32_t*)address,(uint32_t)value)
#define read_eeprom_array(address,value_p,length) eeprom_read_block ((void *)address, (const void *)value_p, length)
#define write_eeprom_array(address,value_p,length) eeprom_write_block ((const void *)value_p, (void *)address, length)

it is very easy to use them,
Code:
some_variable=read_eeprom_byte(1); //read the value from position 1
write_eeprom_byte(2,0xff) // write value 0xff to position 2

//  read/write word and dword are the same as above but for 16 and 32 bit values

char text[10];
write_eeprom_array(10,text,8); // write in position 10 the 8 first characters of text array 

char text[10];
read_eeprom_array(10,text,5); // read to text array 5 char starting from position 10
Alex

The defines in my original post had some small mistakes,
i have updated the defines in this post with the fixed ones (7 Jan 2011)
 
Last edited:

You can also check the avr-libc manual.
I use avrstudio+avr-gcc and mk2 programmer, never had any problem using the onchip eeprom, if you defined eeprom type data, ypu should have the .eep file after the build, you can also open it as text, I actually used it for debugging a few times(store some data in eeprom, download it, open as text).
 

thank u alexan_e....................

as you said, i got two files in the default folder one named to be .hex file and the other being .eep file. We did all the stuff to check the content of .eep file by opening it with the text editor. we found some data, which is wrong with the content we have given. Now, actually the problem is when we try to program the inbuilt eeprom of atmega2560, we are getting an error stating THE INTEL HEX INPUT FILE IS EMPTY. I am using AVR4.18 SP2.
 

Attach the eep file, or copy-paste it here.
 

I was actually wrong, the process i have described above is to write or read values from eeprom at runtime, so for example:
Code:
#include <avr/eeprom.h>
// defines for eeprom access	
#define read_eeprom_byte(address) eeprom_read_byte ((const uint8_t*)address)
#define write_eeprom_byte(address,value) eeprom_write_byte ((uint8_t*)address,(uint8_t)value)
#define read_eeprom_word(address) eeprom_read_word ((const uint16_t*)address)
#define write_eeprom_word(address,value) eeprom_write_word ((uint16_t*)address,(uint16_t)value)
#define read_eeprom_dword(address) eeprom_read_dword ((const uint32_t*)address)
#define write_eeprom_dword(address,value) eeprom_write_dword ((uint32_t*)address,(uint32_t)value)
#define read_eeprom_array(address,value_p,length) eeprom_read_block ((void *)value_p,(const void *)address,  length)
#define write_eeprom_array(address,value_p,length) eeprom_write_block (( void *)value_p, (const void *)address, length)

uint8_t	my_byte;
uint16_t my_word;
uint32_t my_dword;
char my_text[10]={"123456789\0"};


//--------------- code inside main-----------------

write_eeprom_byte(1,0x0f);		// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]
write_eeprom_word(3,0x0fff);		// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]
write_eeprom_dword(10,0x0fffffff);	// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]
write_eeprom_array(10,my_text,8);    // write in eeprom position 10 the 8 first characters of my_text array

// and you can read them using
my_byte=read_eeprom_byte(1);			
my_word=read_eeprom_word(3);		
my_dword=read_eeprom_dword(10);
read_eeprom_array(10,my_text,5); // read to my_text array 5 char starting from eeprom position 10
or if you don't want to bother about specific eeprom address
Code:
uint8_t EEMEM	  my_eeprom_byte;
uint16_t EEMEM	  my_eeprom_word;
uint32_t EEMEM    my_eeprom_dword;
uint8_t 	  my_byte;
uint16_t	  my_word;
uint32_t 	  my_dword;

//--------------- code inside main-----------------

write_eeprom_byte(&my_eeprom_byte,0x0f);		// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]
write_eeprom_word(&my_eeprom_word,0x0fff);		// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]
write_eeprom_dword(&my_eeprom_dword,0x0fffffff);	// [COLOR="red"]this will be written at runtime (and stored in first run), it will not be includded in the eep file[/COLOR]

// and you can read them using
my_byte=read_eeprom_byte(&my_eeprom_byte);			
my_word=read_eeprom_word(&my_eeprom_word);		
my_dword=read_eeprom_dword(&my_eeprom_dword);

if you want to store some data in the eeprom when you compile the code (so they are added to the eep file and use them to fill the avr eeprom when you program the device),
you need to use the EEMEM and initialize it with a value like the following example:

Code:
//

uint8_t EEMEM eeprombyte=0x10;		[COLOR="red"]//store initial byte to eeprom, eep file will include this[/COLOR]

uint16_t EEMEM eepromword=0x5555;	[COLOR="red"]//store initial word to eeprom, eep file will include this[/COLOR]

uint8_t EEMEM eepromstring[5]={"Test\0"}; 	[COLOR="red"]//store string to eeprom, eep file will include this[/COLOR]

int main(void)

{
uint8_t RAMbyte;		//RAM byte variable
uint16_t RAMword;		//RAM word variable
uint8_t RAMstring[5];		//RAM array of bytes

RAMbyte = eeprom_read_byte(&eeprombyte);	//read byte from EEPROM and store to RAM
RAMword = eeprom_read_word(&eepromword);	//read word from EEPROM and store to RAM
read_eeprom_array(&eepromstring,&RAMstring,5);		//copy string from EEPROM to RAM
....
}

The above code/article source is

Use the above way to store the data you want in the eeprom at design time and they will be added to the eep file when you compile, then use the eep file to fill the avr device eeprom.

Alex
 
Last edited:

please find the attached file
 

Attachments

  • inbuilt_eeprom.rar
    151 bytes · Views: 87

Is this your data ?

hex: 01 03 F1 68 65 6C 6C 6F 73 68 61 6E 6B 61 72 6E 61 72 61 79 61 6E 61
ascii: helloshankarnarayana

the first 3 are not ascii characters

your file:
:10000000 0103F168656C6C6F7368616E6B61726E 91
:07001000 61726179616E61 0C
:00000001 FF ->end marker+checksum
^ hex stuf ^your data ^checksum

the first group is the hex format specific data, the next is your actual data, and the third group is the cheksum, the last line is the end marker (**broken link removed**)

So your error is coming from your setup, maybe you overlooked something, is the right eep file selected? etc...
 

is the right eep file selected? etc...

yes....the right file is selected.


can you clarify me one more doubt that whether the controller has to be programmed with .eep file only or both .eep and .hex files in order to program inbuilt eeprom of our controller.
 

You can program separately the eeprom region, I am not familiar with your setup(jtag probe, stk600), I only used the mk2 isp probe.

Your error message comes from the downloader application, can you post some screen shots?
 

The screen shots on avrfreaks are low resolution, copy-paste the command output and put a high res. image
From the error pop-up it seems that you are in ISP mode, not JTAG.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top