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.
edit: also, for some reason my EELOAD bit is set at all times. not sure if this is a problem or not.