Write to EEPROM page sets first byte to 0x00

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

Hello.

I'm working on storing data to the internal EEPROM of an Xmega 256A3, using memory mapped EEPROM.

Saving this data works fine, but for some reason, the first byte in the page is sometimes written in as zero (0x00).

This is my "write page" snippet.

WAIT_NVM_BUSY()
NVM.ADDR0 = (uint8_t)page_address;
NVM.ADDR1 = (uint8_t)(page_address>>8);
NVM.ADDR2 = 0;
NVM.CMD = NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc;
CCP = CCP_IOREG_gc;
NVM.CTRLA = NVM_CMDEX_bm;
WAIT_NVM_BUSY()

Like I said, it only seems to happens sometimes, always the first byte, and I can't nail down under what circumstances.

I also tried with the nonatomic erase-then-write and it behaves the same way (the erase works fine though, the write will bring in the 0x00).

I tried reading the EEPROM page to be written to a temporary buffer right before writing it, and the data there looks good (a pn pattern), i also tried reading it to a temp, then writing it back to mapped EEPROM, but it behaves the same way (except all data is updated in the page).

Furthermore, the zero-th byte isn't even modified in the page buffer (until i did the read-write of a temp buffer) yet it still is updated by write.

any ideas?

 

edit: also, for some reason my EELOAD bit is set at all times. not sure if this is a problem or not.

Last Edited: Thu. Jul 13, 2017 - 08:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have the A series, not the AU series, there is a bug.  Maybe you found it.  I'm not at home so I don't have access to any documents.  As I recall, the chip clobbers the eeprom address with the program counter address.  The fix for that was to go to sleep immediately after doing the EEPROM write.  Or maybe I have it confused.

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

I've no idea about Xmega but for tiny/mega it would often be the case that byte 0 in EEPROM might corrupt. That is because most of the time the EEAR (address register) holds 0x00 so if an "unscheduled write" occurs it will tend to hit location 0x0000 because that happens to be the selected address.

As to why such a corrupting write might even occur I think pretty much every tiny/mega datasheet has a paragraph like this:

 

 

Now I don't know about Xmega but I assume they have the equivalent of BOD? Is it enabled by default ?

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

I don't think EELOAD should be set all the time.

 

The A series is buggy.  Here is errata from my 7 year old 256A3 data sheet.