ATXmega64A3 EEPROM Erase issues

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I am looking for help regarding EEPROM commands. I can easily write and read byte from the EEPROM. However, whenevr I try to erase full EEPROM, the function completes, but the EEPROM data stays untouched.

My code is:

void EraseEEPROM(void)
{
	while ( NVM.STATUS & NVM_NVMBUSY_bm );// Wait until NVM is not busy

	_CLI();		                      // Disable interrupts

	NVM.CMD = NVM_CMD_ERASE_EEPROM_gc;    // Issue Erase EEPROM command
	CCP = CCP_IOREG_gc;		      // Reset Protection
	NVM.CTRLA = NVM_CMDEX_bm;	      // Execute command
	
	while ( NVM.STATUS & NVM_NVMBUSY_bm );// Wait until NVM is not busy
	
	_SEI();			              // Enable interrupts
}

Any help is appreciated.

Regards,
Leon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

Two thoughts:

What are the lock bits set to? If the EEPROM is locked then an Erase won't actually erase the EEPROM.

Additionally, the first series of Xmegas had a few errata, (chip bugs), which included, (IIRC), 4 NVM commands that did not work. If your routine is using one of those then once again, nothing is going to happen to the EEPROM.

Check the Errata section of the data sheet against your version of the chip to see which specific bugs apply to your version.

Others may have additional thoughts on the subject.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are you writing EEPROM primitives when the compiler already provides them?:

http://www.nongnu.org/avr-libc/u...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much for your suggestions.

All Lock bits on the micro are not programmed. I do have a EESAVE fuse set, but that should save EEPROM during Chip Erase process.

I checked the Errata and did not find anything on the commands for NVM.

Superfreak, you are absolutely right about provided functions from compiler. Unfortunately, EEPROM erase is not part of these.

Thanks again.

Regards,
Leon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Unfortunately, EEPROM erase is not part of these.


An erased EEPROM is just one that contains 0xFF so write 0xFF's to it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
An erased EEPROM is just one that contains 0xFF so write 0xFF's to it.

That is what I do right now. But it takes quite a bit of time. I need this time to be shortened significantly.

Regards,
Leon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As the issuing of the commands to write 0xFF is a very small part of the overhead of writing a location I'll be interested to hear if this really does speed the process. I imagine the EEPROM internally has a state machine that's probably going to be doing pretty much the same as you were doing programmatically.

BTW reading about this in various Xmega datasheet I see the ability to erase an "EEPROM page" (typically 32 bytes) at a time but not the ability to erase the entire device. Where is that documented?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that during full erase process, the NVM controller will apply an increased voltage to memory cells and will automatically set all the bits to '1'. This process is quite fast. I cannot be a 100% sure about it, but that is my understanding on how it is done.

I found all the commands from AVR app note AVR1315 and provided drivers.

Let me know if I missed anything in the app note.

Regards,
Leon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No I found that app note too and I see what you mean. What's more then Googling for NVM_CMD_ERASE_EEPROM_gc then leads you to here:

http://asf.atmel.com/docs/2.6.1/...

And within:

http://asf.atmel.com/docs/2.6.1/...

and then line 114 in:

http://asf.atmel.com/docs/2.6.1/...

Which all seems to confirm that what you are attempting is the correct approach.

(of course you could try that actual ASF code)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks clawson for your help.

I guess I will use a workaround for now. I will have to find the resolution for this one way or the other.

Regards,
Leon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks to clawson, I resolved this issue. After review of the Demo application, I found out that first you need to fill the buffer with 0xFF value. After that issuing EEPROM Erase command did the job perfectly and fast.

void EraseEEPROM(void)
{
	BYTE b;
	
	while ( NVM.STATUS & NVM_NVMBUSY_bm );					// Wait until NVM is not busy

	_CLI();													// Disable interrupts
	
	if ( NVM.STATUS & NVM_EELOAD_bm )						// Flush EEPROM page buffer if necessary
	{
		NVM.CMD = NVM_CMD_ERASE_EEPROM_BUFFER_gc;
		CCP = CCP_IOREG_gc;									// Reset Protection
		NVM.CTRLA = NVM_CMDEX_bm;							// Execute command
	}
	
	while ( NVM.STATUS & NVM_NVMBUSY_bm );					// Wait until NVM is not busy
	
	NVM.CMD = NVM_CMD_LOAD_EEPROM_BUFFER_gc;

	NVM.ADDR1 = 0x00;	NVM.ADDR2 = 0x00;					// Set address to write to
	
	for( b = 0; b < EEPROM_PAGE_SIZE; b++ )
	{	NVM.ADDR0 = b;	NVM.DATA0 = EMPTY_ENTRY;	}		// Load buffer with 0xFF

	NVM.CMD = NVM_CMD_ERASE_EEPROM_gc;						// Issue Erase EEPROM command
	CCP = CCP_IOREG_gc;										// Reset Protection
	NVM.CTRLA = NVM_CMDEX_bm;								// Execute command
	
	while ( NVM.STATUS & NVM_NVMBUSY_bm );					// Wait until NVM is not busy
	
	_SEI();													// Enable interrupts
}