ATxmega128A1 eeprom problems

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

I am having problems writing records of about 40 bytes to my xmega128a1 eeprom, it seams hang my system. I can not use the avr/eeprom.h(not implemented yet for 128a1) so I have been basing my code on the example driver from the ATMEL website. I have tried the example driver straight and with mods that seam to make it conform to the avr1315 document. Has anyone had any luck? Below is my write function.

//from the example driver plus mods from the avr1315 pdf file
void EEPROM_WriteByte( uint8_t pageAddr, 
                       uint8_t byteAddr, uint8_t value )
{
	NVM.CTRLB &= ~NVM_EEMAPEN_bm ;//disable mapping
	NVM.INTCTRL = 0; //disable eeprom interrupts

    EEPROM_FlushBuffer();
EEPROM_WaitForNVM();             //I added this per AVR1315
	
    NVM.CMD = NVM_CMD_LOAD_EEPROM_BUFFER_gc;


    /* Calculate address */
    uint16_t address = (uint16_t)(pageAddr*EEPROM_PAGESIZE)
        |(byteAddr & (EEPROM_PAGESIZE-1));

    /* Set address to write to. */
    NVM.ADDR0 = address & 0xFF;
    NVM.ADDR1 = (address >> 8) & 0x1F;
    NVM.ADDR2 = 0x00;

    /* Load data to write, which triggers the loading of 
       EEPROM page buffer. */
    NVM.DATA0 = value;


EEPROM_WaitForNVM();            //I added this per AVR1315

NVM.ADDR0 = address & 0xFF;     //I added this per AVR1315
NVM.ADDR1 = (address >> 8) & 0x1F;//I added this per AVR1315
NVM.ADDR2 = 0x00;                //I added this per AVR1315


    /*  Issue EEPROM Atomic Write (Erase&Write) command. Load command, write
     *  the protection signature and execute command.
     */
    NVM.CMD = NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc;
	#ifdef MY_NVM_EXE
		myExec();
	#else
	        NVM_EXEC();
	#endif
}


//I wrote this version of the above code using the manual
void myExec()
{
	uint8_t ctrla = NVM.CTRLA | NVM_CMDEX_bm;
	CCP = 0xD8;
	NVM.CTRLA = ctrla;
}

[/code]

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

As I recall, any 128A1 earlier than Revision H (the latest version) has problems with the EEPROM. Make sure your 128A1 is Rev H (just became available in the last couple of weeks).

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

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

Thanks for the response. It looks like that is my problem I have Rev G. According to the errata:

9. EEPROM erase and write does not work with all System
Clock sources

When doing EEPROM erase or Write operations with
other clock sources than the 2 MHz RCOSC, Flash
will be read wrongly for one or two clock cycles
at the end of the EEPROM operation.

Problem fix/Workaround
Alt 1: Use the internal 2 MHz RCOSC when doing erase
or write operations on EEPROM.
Alt 2: Ensure to be in sleep mode while completing
erase or write on EEPROM. After starting
erase or write operations on EEPROM, other
interrupts should be disabled and the
device put to sleep.